re-fix the issue of accumulating message list models
This commit is contained in:
@@ -19,7 +19,8 @@ public class MessageListModel : Object, ListModel
|
||||
|
||||
private ArrayList<Message> _messages;
|
||||
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) {
|
||||
_messages = new ArrayList<Message>();
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user