From dd6c860aed79c5adf0db08142bbbf7b8ec3fbe67 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Wed, 29 May 2019 16:53:34 +0200 Subject: Don't change type of a conversation --- libdino/src/entity/conversation.vala | 2 +- libdino/src/service/avatar_manager.vala | 7 +++- libdino/src/service/conversation_manager.vala | 57 ++++++++++++++++++--------- 3 files changed, 46 insertions(+), 20 deletions(-) (limited to 'libdino/src') diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala index 9e8a3406..0537ee61 100644 --- a/libdino/src/entity/conversation.vala +++ b/libdino/src/entity/conversation.vala @@ -136,7 +136,7 @@ public class Conversation : Object { } public static bool equals_func(Conversation conversation1, Conversation conversation2) { - return conversation1.counterpart.equals(conversation2.counterpart) && conversation1.account.equals(conversation2.account); + return conversation1.counterpart.equals(conversation2.counterpart) && conversation1.account.equals(conversation2.account) && conversation1.type_ == conversation2.type_; } public static uint hash_func(Conversation conversation) { diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index 3e6d4d80..c9c078ab 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -71,7 +71,12 @@ public class AvatarManager : StreamInteractionModule, Object { } public async Pixbuf? get_avatar(Account account, Jid jid) { - string? hash = get_avatar_hash(account, jid); + Jid jid_ = jid; + if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { + jid_ = jid.bare_jid; + } + + string? hash = get_avatar_hash(account, jid_); if (hash != null) { return yield get_avatar_by_hash(hash); } diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala index 77205c57..b1e8d8a8 100644 --- a/libdino/src/service/conversation_manager.vala +++ b/libdino/src/service/conversation_manager.vala @@ -14,7 +14,7 @@ public class ConversationManager : StreamInteractionModule, Object { private StreamInteractor stream_interactor; private Database db; - private HashMap> conversations = new HashMap>(Account.hash_func, Account.equals_func); + private HashMap>> conversations = new HashMap>>(Account.hash_func, Account.equals_func); public static void start(StreamInteractor stream_interactor, Database db) { ConversationManager m = new ConversationManager(stream_interactor, db); @@ -33,15 +33,19 @@ public class ConversationManager : StreamInteractionModule, Object { public Conversation create_conversation(Jid jid, Account account, Conversation.Type? type = null) { assert(conversations.has_key(account)); Jid store_jid = type == Conversation.Type.GROUPCHAT ? jid.bare_jid : jid; - if (conversations[account].has_key(store_jid)) { - conversations[account][store_jid].type_ = type; - return conversations[account][store_jid]; - } else { - Conversation conversation = new Conversation(jid, account, type); - add_conversation(conversation); - conversation.persist(db); - return conversation; + + // Do we already have a conversation for this jid? + foreach (var conversation in conversations[account][store_jid]) { + if (conversation.type_ == type) { + return conversation; + } } + + // Create a new converation + Conversation conversation = new Conversation(jid, account, type); + add_conversation(conversation); + conversation.persist(db); + return conversation; } public Conversation? get_conversation_for_message(Entities.Message message) { @@ -68,17 +72,27 @@ public class ConversationManager : StreamInteractionModule, Object { return ret; } - public Conversation? get_conversation(Jid jid, Account account) { + public Conversation? get_conversation(Jid jid, Account account, Conversation.Type? type = null) { if (conversations.has_key(account)) { - return conversations[account][jid]; + if (conversations[account].has_key(jid)) { + foreach (var conversation in conversations[account][jid]) { + if (type == null || conversation.type_ == type) { + return conversation; + } + } + } } return null; } public Conversation? get_conversation_by_id(int id) { - foreach (HashMap hm in conversations.values) { - foreach (Conversation conversation in hm.values) { - if (conversation.id == id) return conversation; + foreach (HashMap> hm in conversations.values) { + foreach (Gee.List hm2 in hm.values) { + foreach (Conversation conversation in hm2) { + if (conversation.id == id) { + return conversation; + } + } } } return null; @@ -88,8 +102,10 @@ public class ConversationManager : StreamInteractionModule, Object { Gee.List ret = new ArrayList(Conversation.equals_func); foreach (Account account_ in conversations.keys) { if (account != null && !account_.equals(account)) continue; - foreach (Conversation conversation in conversations[account_].values) { - if(conversation.active) ret.add(conversation); + foreach (Gee.List list in conversations[account_].values) { + foreach (var conversation in list) { + if(conversation.active) ret.add(conversation); + } } } return ret; @@ -112,7 +128,7 @@ public class ConversationManager : StreamInteractionModule, Object { } private void on_account_added(Account account) { - conversations[account] = new HashMap(Jid.hash_func, Jid.equals_func); + conversations[account] = new HashMap>(Jid.hash_func, Jid.equals_func); foreach (Conversation conversation in db.get_conversations(account)) { add_conversation(conversation); } @@ -153,7 +169,12 @@ public class ConversationManager : StreamInteractionModule, Object { } private void add_conversation(Conversation conversation) { - conversations[conversation.account][conversation.counterpart] = conversation; + if (!conversations[conversation.account].has_key(conversation.counterpart)) { + conversations[conversation.account][conversation.counterpart] = new ArrayList(Conversation.equals_func); + } + + conversations[conversation.account][conversation.counterpart].add(conversation); + if (conversation.active) { conversation_activated(conversation); } -- cgit v1.2.3-70-g09d2