From b60e7da28aad7532b71e92c766ed3cc2698c47c5 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 6 Sep 2020 15:42:54 +0200 Subject: Fix message duplication in MUC PMs --- libdino/src/entity/message.vala | 2 +- libdino/src/service/message_processor.vala | 2 +- main/src/ui/util/helper.vala | 21 +++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index 272905a9..7192f6aa 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -81,7 +81,7 @@ public class Message : Object { if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); string our_resource = row[db.message.our_resource]; - if (type_.is_muc_semantic() && our_resource != null) { + if (type_ == Type.GROUPCHAT && our_resource != null) { ourpart = counterpart.with_resource(our_resource); } else if (our_resource != null) { ourpart = account.bare_jid.with_resource(our_resource); diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index 3e92e61f..5ddf86a6 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -598,7 +598,7 @@ public class MessageProcessor : StreamInteractionModule, Object { message.local_time = now; message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; - if (conversation.type_.is_muc_semantic()) { + if (conversation.type_ == Conversation.Type.GROUPCHAT) { message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.bare_jid; message.real_jid = conversation.account.bare_jid; } else { diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 8d9fee53..ca2c37d9 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -124,7 +124,7 @@ public static string get_conversation_display_name(StreamInteractor stream_inter return get_groupchat_display_name(stream_interactor, conversation.account, conversation.counterpart); } if (conversation.type_ == Conversation.Type.GROUPCHAT_PM) { - return _("%s from %s").printf(get_occupant_display_name(stream_interactor, conversation.account, conversation.counterpart), get_groupchat_display_name(stream_interactor, conversation.account, conversation.counterpart.bare_jid)); + return _("%s from %s").printf(get_occupant_display_name(stream_interactor, conversation, conversation.counterpart), get_groupchat_display_name(stream_interactor, conversation.account, conversation.counterpart.bare_jid)); } return conversation.counterpart.to_string(); } @@ -141,7 +141,7 @@ public static string get_participant_display_name(StreamInteractor stream_intera return get_real_display_name(stream_interactor, conversation.account, participant, me_is_me) ?? participant.bare_jid.to_string(); } if ((conversation.type_ == Conversation.Type.GROUPCHAT || conversation.type_ == Conversation.Type.GROUPCHAT_PM) && conversation.counterpart.equals_bare(participant)) { - return get_occupant_display_name(stream_interactor, conversation.account, participant); + return get_occupant_display_name(stream_interactor, conversation, participant); } return participant.bare_jid.to_string(); } @@ -182,17 +182,26 @@ private static string get_groupchat_display_name(StreamInteractor stream_interac return jid.to_string(); } -private static string get_occupant_display_name(StreamInteractor stream_interactor, Account account, Jid jid, bool me_is_me = false, bool muc_real_name = false) { +private static string get_occupant_display_name(StreamInteractor stream_interactor, Conversation conversation, Jid jid, bool me_is_me = false, bool muc_real_name = false) { if (muc_real_name) { MucManager muc_manager = stream_interactor.get_module(MucManager.IDENTITY); - if (muc_manager.is_private_room(account, jid.bare_jid)) { - Jid? real_jid = muc_manager.get_real_jid(jid, account); + if (muc_manager.is_private_room(conversation.account, jid.bare_jid)) { + Jid? real_jid = muc_manager.get_real_jid(jid, conversation.account); if (real_jid != null) { - string? display_name = get_real_display_name(stream_interactor, account, real_jid, me_is_me); + string? display_name = get_real_display_name(stream_interactor, conversation.account, real_jid, me_is_me); if (display_name != null) return display_name; } } } + + // If it's us (jid=our real full JID), display our nick + if (conversation.type_ == Conversation.Type.GROUPCHAT_PM && conversation.account.bare_jid.equals_bare(jid)) { + var muc_conv = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(conversation.counterpart.bare_jid, conversation.account, Conversation.Type.GROUPCHAT); + if (muc_conv != null && muc_conv.nickname != null) { + return muc_conv.nickname; + } + } + return jid.resourcepart ?? jid.to_string(); } -- cgit v1.2.3-70-g09d2