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);
|
return (int)(b.date - a.date);
|
||||||
});
|
});
|
||||||
|
|
||||||
Repository.get_instance().conversations_updated.connect(load_conversations);
|
weak ConversationListModel self = this;
|
||||||
Repository.get_instance().messages_updated.connect(load_conversations);
|
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) {
|
public Conversation? get_conversation(string guid) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class ConversationListView : Adw.Bin
|
|||||||
var app_menu = new Menu ();
|
var app_menu = new Menu ();
|
||||||
|
|
||||||
var section = new Menu ();
|
var section = new Menu ();
|
||||||
section.append ("Refresh", "list.refresh");
|
section.append ("Manual Sync", "list.refresh");
|
||||||
section.append ("Settings...", "win.settings");
|
section.append ("Settings...", "win.settings");
|
||||||
app_menu.append_section (null, section);
|
app_menu.append_section (null, section);
|
||||||
|
|
||||||
@@ -54,8 +54,10 @@ public class ConversationListView : Adw.Bin
|
|||||||
|
|
||||||
var refresh_action = new SimpleAction("refresh", null);
|
var refresh_action = new SimpleAction("refresh", null);
|
||||||
refresh_action.activate.connect (() => {
|
refresh_action.activate.connect (() => {
|
||||||
if (conversation_model != null) {
|
try {
|
||||||
conversation_model.load_conversations ();
|
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")]
|
[DBus (name = "MessagesUpdated")]
|
||||||
public signal void messages_updated(string conversation_id);
|
public signal void messages_updated(string conversation_id);
|
||||||
|
|
||||||
|
[DBus (name = "UpdateStreamReconnected")]
|
||||||
|
public signal void update_stream_reconnected();
|
||||||
|
|
||||||
[DBus (name = "GetAttachmentInfo")]
|
[DBus (name = "GetAttachmentInfo")]
|
||||||
public abstract RepositoryAttachmentInfoStruct get_attachment_info(string attachment_id) throws DBusError, IOError;
|
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."/>
|
value="Emitted when the list of messages is updated."/>
|
||||||
</signal>
|
</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 -->
|
<!-- Attachments -->
|
||||||
|
|
||||||
<method name="GetAttachmentInfo">
|
<method name="GetAttachmentInfo">
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public class Repository : DBusServiceProxy {
|
|||||||
public signal void messages_updated(string conversation_guid);
|
public signal void messages_updated(string conversation_guid);
|
||||||
public signal void attachment_downloaded(string attachment_guid);
|
public signal void attachment_downloaded(string attachment_guid);
|
||||||
public signal void attachment_uploaded(string upload_guid, string attachment_guid);
|
public signal void attachment_uploaded(string upload_guid, string attachment_guid);
|
||||||
|
public signal void reconnected();
|
||||||
|
|
||||||
public static Repository get_instance() {
|
public static Repository get_instance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -46,12 +47,25 @@ public class Repository : DBusServiceProxy {
|
|||||||
attachment_uploaded(upload_guid, attachment_guid);
|
attachment_uploaded(upload_guid, attachment_guid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.dbus_repository.update_stream_reconnected.connect(() => {
|
||||||
|
reconnected();
|
||||||
|
});
|
||||||
|
|
||||||
conversations_updated();
|
conversations_updated();
|
||||||
|
reconnected();
|
||||||
} catch (GLib.Error e) {
|
} catch (GLib.Error e) {
|
||||||
warning("Failed to connect to repository: %s", e.message);
|
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 {
|
public Conversation[] get_conversations(int limit = 200) throws DBusServiceProxyError, GLib.Error {
|
||||||
if (dbus_repository == null) {
|
if (dbus_repository == null) {
|
||||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||||
|
|||||||
@@ -34,7 +34,15 @@ public class MessageListModel : Object, ListModel
|
|||||||
|
|
||||||
public void watch_updates() {
|
public void watch_updates() {
|
||||||
if (this.handler_id == 0) {
|
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