Implement resync after update monitor reconnect
This commit is contained in:
@@ -15,8 +15,23 @@ public class ConversationListModel : Object, ListModel
|
||||
return (int)(b.date - a.date);
|
||||
});
|
||||
|
||||
Repository.get_instance().conversations_updated.connect(load_conversations);
|
||||
Repository.get_instance().messages_updated.connect(load_conversations);
|
||||
weak ConversationListModel self = this;
|
||||
Repository.get_instance().conversations_updated.connect(() => {
|
||||
self.load_conversations();
|
||||
});
|
||||
|
||||
Repository.get_instance().messages_updated.connect((conversation_guid) => {
|
||||
self.load_conversations();
|
||||
});
|
||||
|
||||
Repository.get_instance().reconnected.connect(() => {
|
||||
// Trigger a sync-list to get the latest conversations
|
||||
try {
|
||||
Repository.get_instance().sync_conversation_list();
|
||||
} catch (GLib.Error e) {
|
||||
warning("Failed to sync conversation list: %s", e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Conversation? get_conversation(string guid) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ConversationListView : Adw.Bin
|
||||
var app_menu = new Menu ();
|
||||
|
||||
var section = new Menu ();
|
||||
section.append ("Refresh", "list.refresh");
|
||||
section.append ("Manual Sync", "list.refresh");
|
||||
section.append ("Settings...", "win.settings");
|
||||
app_menu.append_section (null, section);
|
||||
|
||||
@@ -54,8 +54,10 @@ public class ConversationListView : Adw.Bin
|
||||
|
||||
var refresh_action = new SimpleAction("refresh", null);
|
||||
refresh_action.activate.connect (() => {
|
||||
if (conversation_model != null) {
|
||||
conversation_model.load_conversations ();
|
||||
try {
|
||||
Repository.get_instance().sync_conversation_list();
|
||||
} catch (GLib.Error e) {
|
||||
warning("Failed to sync conversation list: %s", e.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace DBusService {
|
||||
[DBus (name = "MessagesUpdated")]
|
||||
public signal void messages_updated(string conversation_id);
|
||||
|
||||
[DBus (name = "UpdateStreamReconnected")]
|
||||
public signal void update_stream_reconnected();
|
||||
|
||||
[DBus (name = "GetAttachmentInfo")]
|
||||
public abstract RepositoryAttachmentInfoStruct get_attachment_info(string attachment_id) throws DBusError, IOError;
|
||||
|
||||
|
||||
@@ -103,6 +103,11 @@
|
||||
value="Emitted when the list of messages is updated."/>
|
||||
</signal>
|
||||
|
||||
<signal name="UpdateStreamReconnected">
|
||||
<annotation name="org.freedesktop.DBus.DocString"
|
||||
value="Emitted when the update stream is reconnected after a timeout or configuration change."/>
|
||||
</signal>
|
||||
|
||||
<!-- Attachments -->
|
||||
|
||||
<method name="GetAttachmentInfo">
|
||||
|
||||
@@ -6,6 +6,7 @@ public class Repository : DBusServiceProxy {
|
||||
public signal void messages_updated(string conversation_guid);
|
||||
public signal void attachment_downloaded(string attachment_guid);
|
||||
public signal void attachment_uploaded(string upload_guid, string attachment_guid);
|
||||
public signal void reconnected();
|
||||
|
||||
public static Repository get_instance() {
|
||||
if (instance == null) {
|
||||
@@ -46,11 +47,24 @@ public class Repository : DBusServiceProxy {
|
||||
attachment_uploaded(upload_guid, attachment_guid);
|
||||
});
|
||||
|
||||
this.dbus_repository.update_stream_reconnected.connect(() => {
|
||||
reconnected();
|
||||
});
|
||||
|
||||
conversations_updated();
|
||||
reconnected();
|
||||
} catch (GLib.Error e) {
|
||||
warning("Failed to connect to repository: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public void sync_conversation_list() throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||
}
|
||||
|
||||
dbus_repository.sync_conversation_list();
|
||||
}
|
||||
|
||||
public Conversation[] get_conversations(int limit = 200) throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
|
||||
@@ -34,7 +34,15 @@ public class MessageListModel : Object, ListModel
|
||||
|
||||
public void watch_updates() {
|
||||
if (this.handler_id == 0) {
|
||||
this.handler_id = Repository.get_instance().messages_updated.connect(got_messages_updated);
|
||||
weak MessageListModel self = this;
|
||||
this.handler_id = Repository.get_instance().messages_updated.connect((conversation_guid) => {
|
||||
self.got_messages_updated(conversation_guid);
|
||||
});
|
||||
|
||||
this.handler_id = Repository.get_instance().reconnected.connect(() => {
|
||||
// On reconnect, reload the messages that we're looking at now.
|
||||
self.load_messages();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user