fixes for very large conversation lists
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using GLib;
|
||||
using Gee;
|
||||
|
||||
public class Repository : DBusServiceBase {
|
||||
public class Repository : DBusServiceProxy {
|
||||
public signal void conversations_updated();
|
||||
public signal void messages_updated(string conversation_guid);
|
||||
|
||||
@@ -15,40 +15,37 @@ public class Repository : DBusServiceBase {
|
||||
|
||||
private static Repository instance = null;
|
||||
private DBusService.Repository? dbus_repository;
|
||||
private uint dbus_watch_id;
|
||||
|
||||
private Repository() {
|
||||
base();
|
||||
this.dbus_watch_id = Bus.watch_name(BusType.SESSION, DBUS_NAME, BusNameWatcherFlags.NONE, (name, name_owner) => {
|
||||
connect_to_repository();
|
||||
});
|
||||
}
|
||||
|
||||
protected override string get_service_name() {
|
||||
return "Repository";
|
||||
}
|
||||
|
||||
protected override async Object? get_proxy() throws Error {
|
||||
dbus_repository = yield Bus.get_proxy(BusType.SESSION, DBUS_NAME, DBUS_PATH);
|
||||
dbus_repository.get_version(); // Test the connection
|
||||
return dbus_repository;
|
||||
}
|
||||
|
||||
protected override void setup_signals() {
|
||||
dbus_repository.conversations_updated.connect(() => {
|
||||
|
||||
private void connect_to_repository() {
|
||||
try {
|
||||
this.dbus_repository = Bus.get_proxy_sync<DBusService.Repository>(BusType.SESSION, DBUS_NAME, DBUS_PATH);
|
||||
this.dbus_repository.conversations_updated.connect(() => {
|
||||
conversations_updated();
|
||||
});
|
||||
|
||||
this.dbus_repository.messages_updated.connect((conversation_guid) => {
|
||||
messages_updated(conversation_guid);
|
||||
});
|
||||
|
||||
conversations_updated();
|
||||
});
|
||||
|
||||
dbus_repository.messages_updated.connect((conversation_guid) => {
|
||||
messages_updated(conversation_guid);
|
||||
});
|
||||
|
||||
// Initial load
|
||||
conversations_updated();
|
||||
} catch (GLib.Error e) {
|
||||
warning("Failed to connect to repository: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public Conversation[] get_conversations() throws Error {
|
||||
if (!is_connected || dbus_repository == null) {
|
||||
throw create_not_connected_error();
|
||||
public Conversation[] get_conversations(int limit = 200) throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||
}
|
||||
|
||||
var conversations = dbus_repository.get_conversations();
|
||||
|
||||
var conversations = dbus_repository.get_conversations(limit, 0);
|
||||
Conversation[] returned_conversations = new Conversation[conversations.length];
|
||||
|
||||
for (int i = 0; i < conversations.length; i++) {
|
||||
@@ -58,9 +55,9 @@ public class Repository : DBusServiceBase {
|
||||
return returned_conversations;
|
||||
}
|
||||
|
||||
public Message[] get_messages(string conversation_guid, string last_message_id = "") throws Error {
|
||||
if (!is_connected || dbus_repository == null) {
|
||||
throw create_not_connected_error();
|
||||
public Message[] get_messages(string conversation_guid, string last_message_id = "") throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||
}
|
||||
|
||||
var messages = dbus_repository.get_messages(conversation_guid, last_message_id);
|
||||
@@ -73,11 +70,19 @@ public class Repository : DBusServiceBase {
|
||||
return returned_messages;
|
||||
}
|
||||
|
||||
public string send_message(string conversation_guid, string message) throws Error {
|
||||
if (!is_connected || dbus_repository == null) {
|
||||
throw create_not_connected_error();
|
||||
public string send_message(string conversation_guid, string message) throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||
}
|
||||
|
||||
return dbus_repository.send_message(conversation_guid, message);
|
||||
}
|
||||
|
||||
public void sync_conversation(string conversation_guid) throws DBusServiceProxyError, GLib.Error {
|
||||
if (dbus_repository == null) {
|
||||
throw new DBusServiceProxyError.NOT_CONNECTED("Repository not connected");
|
||||
}
|
||||
|
||||
dbus_repository.sync_conversation(conversation_guid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user