Private
Public Access
1
0

Implement resync after update monitor reconnect

This commit is contained in:
2025-06-13 17:13:04 -07:00
parent 1420d96a20
commit 741932c67d
6 changed files with 53 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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);
}
});

View File

@@ -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;

View File

@@ -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">

View File

@@ -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) {

View File

@@ -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();
});
}
}