diff options
author | Marvin W <git@larma.de> | 2019-12-23 23:13:27 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2019-12-23 23:13:27 +0100 |
commit | cf1c7d3af2ce6324b93f95d68fcffaebcc4a2603 (patch) | |
tree | 33b16678e0f64c980b49daf8a98d489bb0970df4 /libdino/src | |
parent | 4185da3b99cfdfba331a2cc0b6bdbd1bed63845e (diff) | |
download | dino-cf1c7d3af2ce6324b93f95d68fcffaebcc4a2603.tar.gz dino-cf1c7d3af2ce6324b93f95d68fcffaebcc4a2603.zip |
Display correct name on outgoing file transfers in groups
Fixes #248, #643
Diffstat (limited to 'libdino/src')
-rw-r--r-- | libdino/src/service/chat_interaction.vala | 1 | ||||
-rw-r--r-- | libdino/src/service/content_item_store.vala | 35 | ||||
-rw-r--r-- | libdino/src/service/file_manager.vala | 6 |
3 files changed, 34 insertions, 8 deletions
diff --git a/libdino/src/service/chat_interaction.vala b/libdino/src/service/chat_interaction.vala index 566eac7e..4ec8e243 100644 --- a/libdino/src/service/chat_interaction.vala +++ b/libdino/src/service/chat_interaction.vala @@ -56,6 +56,7 @@ public class ChatInteraction : StreamInteractionModule, Object { if (file_transfer.provider == 0) { // HTTP file transfer: Check if the associated message is the last one + if (file_transfer.info == null) return false; Message? message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(int.parse(file_transfer.info), conversation); if (message == null) return false; if (message.equals(conversation.read_up_to)) return false; diff --git a/libdino/src/service/content_item_store.vala b/libdino/src/service/content_item_store.vala index 03278b4b..673053c5 100644 --- a/libdino/src/service/content_item_store.vala +++ b/libdino/src/service/content_item_store.vala @@ -68,7 +68,19 @@ public class ContentItemStore : StreamInteractionModule, Object { try { string storage_dir = FileManager.get_storage_dir(); FileTransfer file_transfer = new FileTransfer.from_row(db, row_option.inner, storage_dir); - items.add(new FileItem(file_transfer, row[db.content_item.id])); + if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { + try { + // resourcepart wasn't set before, so we pick nickname instead (which isn't accurate if nickname is changed) + file_transfer.ourpart = conversation.counterpart.with_resource(file_transfer.ourpart.resourcepart ?? conversation.nickname); + } catch (InvalidJidError e) { + warning("Failed setting file transfer Jid: %s", e.message); + } + } + Message? message = null; + if (file_transfer.provider == 0 && file_transfer.info != null) { + message = stream_interactor.get_module(MessageStorage.IDENTITY).get_message_by_id(int.parse(file_transfer.info), conversation); + } + items.add(new FileItem(file_transfer, conversation, row[db.content_item.id], message)); } catch (InvalidJidError e) { warning("Ignoring file transfer with invalid Jid: %s", e.message); } @@ -168,7 +180,7 @@ public class ContentItemStore : StreamInteractionModule, Object { } private void insert_file_transfer(FileTransfer file_transfer, Conversation conversation) { - FileItem item = new FileItem(file_transfer, -1); + FileItem item = new FileItem(file_transfer, conversation, -1); item.id = db.add_content_item(conversation, file_transfer.time, file_transfer.local_time, 2, file_transfer.id, false); if (!discard(item)) { if (collection_conversations.has_key(conversation)) { @@ -265,17 +277,26 @@ public class FileItem : ContentItem { public FileTransfer file_transfer; public Conversation conversation; - public FileItem(FileTransfer file_transfer, int id) { - Jid jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? file_transfer.account.full_jid : file_transfer.counterpart; + public FileItem(FileTransfer file_transfer, Conversation conversation, int id, Message? message = null) { Entities.Message.Marked mark = Entities.Message.Marked.NONE; - if (file_transfer.direction == FileTransfer.DIRECTION_SENT) { + if (message != null) { + mark = message.marked; + } else if (file_transfer.direction == FileTransfer.DIRECTION_SENT) { mark = file_to_message_state(file_transfer.state); } - base(id, TYPE, jid, file_transfer.local_time, file_transfer.time, file_transfer.encryption, mark); + base(id, TYPE, file_transfer.from, file_transfer.local_time, file_transfer.time, file_transfer.encryption, mark); this.file_transfer = file_transfer; + this.conversation = conversation; - if (file_transfer.direction == FileTransfer.DIRECTION_SENT) { + if (message != null) { + WeakRef weak_message = WeakRef(message); + message.notify["marked"].connect(() => { + Message? m = weak_message.get() as Message; + if (m == null) return; + this.mark = m.marked; + }); + } else if (file_transfer.direction == FileTransfer.DIRECTION_SENT) { file_transfer.notify["state"].connect_after(() => { this.mark = file_to_message_state(file_transfer.state); }); diff --git a/libdino/src/service/file_manager.vala b/libdino/src/service/file_manager.vala index 5f3db040..7cd9aeaf 100644 --- a/libdino/src/service/file_manager.vala +++ b/libdino/src/service/file_manager.vala @@ -42,7 +42,11 @@ public class FileManager : StreamInteractionModule, Object { FileTransfer file_transfer = new FileTransfer(); file_transfer.account = conversation.account; file_transfer.counterpart = conversation.counterpart; - file_transfer.ourpart = conversation.account.bare_jid; + if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { + file_transfer.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; + } else { + file_transfer.ourpart = conversation.account.full_jid; + } file_transfer.direction = FileTransfer.DIRECTION_SENT; file_transfer.time = new DateTime.now_utc(); file_transfer.local_time = new DateTime.now_utc(); |