diff --git a/src/transcript/message-list-model.vala b/src/transcript/message-list-model.vala index 7bf111e..bd43b6f 100644 --- a/src/transcript/message-list-model.vala +++ b/src/transcript/message-list-model.vala @@ -19,7 +19,8 @@ public class MessageListModel : Object, ListModel private ArrayList _messages; private HashSet participants = new HashSet(); - private ulong handler_id = 0; + private ulong update_handler_id = 0; + private ulong reconnected_handler_id = 0; public MessageListModel(string conversation_guid) { _messages = new ArrayList(); @@ -33,13 +34,16 @@ public class MessageListModel : Object, ListModel } public void watch_updates() { - if (this.handler_id == 0) { + if (this.update_handler_id == 0) { weak MessageListModel self = this; - this.handler_id = Repository.get_instance().messages_updated.connect((conversation_guid) => { + this.update_handler_id = Repository.get_instance().messages_updated.connect((conversation_guid) => { self.got_messages_updated(conversation_guid); }); + } - this.handler_id = Repository.get_instance().reconnected.connect(() => { + if (this.reconnected_handler_id == 0) { + weak MessageListModel self = this; + this.reconnected_handler_id = Repository.get_instance().reconnected.connect(() => { // On reconnect, reload the messages that we're looking at now. self.load_messages(); }); @@ -47,9 +51,14 @@ public class MessageListModel : Object, ListModel } public void unwatch_updates() { - if (this.handler_id != 0) { - Repository.get_instance().disconnect(this.handler_id); - this.handler_id = 0; + if (this.update_handler_id != 0) { + Repository.get_instance().disconnect(this.update_handler_id); + this.update_handler_id = 0; + } + + if (this.reconnected_handler_id != 0) { + Repository.get_instance().disconnect(this.reconnected_handler_id); + this.reconnected_handler_id = 0; } }