Private
Public Access
1
0

re-fix the issue of accumulating message list models

This commit is contained in:
2025-06-13 17:48:50 -07:00
parent 9c013c3702
commit 4d466f0d26

View File

@@ -19,7 +19,8 @@ public class MessageListModel : Object, ListModel
private ArrayList<Message> _messages; private ArrayList<Message> _messages;
private HashSet<string> participants = new HashSet<string>(); private HashSet<string> participants = new HashSet<string>();
private ulong handler_id = 0; private ulong update_handler_id = 0;
private ulong reconnected_handler_id = 0;
public MessageListModel(string conversation_guid) { public MessageListModel(string conversation_guid) {
_messages = new ArrayList<Message>(); _messages = new ArrayList<Message>();
@@ -33,13 +34,16 @@ public class MessageListModel : Object, ListModel
} }
public void watch_updates() { public void watch_updates() {
if (this.handler_id == 0) { if (this.update_handler_id == 0) {
weak MessageListModel self = this; 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); 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. // On reconnect, reload the messages that we're looking at now.
self.load_messages(); self.load_messages();
}); });
@@ -47,9 +51,14 @@ public class MessageListModel : Object, ListModel
} }
public void unwatch_updates() { public void unwatch_updates() {
if (this.handler_id != 0) { if (this.update_handler_id != 0) {
Repository.get_instance().disconnect(this.handler_id); Repository.get_instance().disconnect(this.update_handler_id);
this.handler_id = 0; this.update_handler_id = 0;
}
if (this.reconnected_handler_id != 0) {
Repository.get_instance().disconnect(this.reconnected_handler_id);
this.reconnected_handler_id = 0;
} }
} }