From 11b29e2db89290f36b4079a95c65194e7194e0f8 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Sun, 5 Apr 2020 13:00:01 +0000
Subject: [PATCH] Use new connect function of SocketListener

---
 briar-gtk/briar_gtk/containers/main_window.py  | 9 +++++++--
 briar-gtk/briar_gtk/containers/private_chat.py | 4 +++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/briar-gtk/briar_gtk/containers/main_window.py b/briar-gtk/briar_gtk/containers/main_window.py
index 6e39d74..660bc88 100644
--- a/briar-gtk/briar_gtk/containers/main_window.py
+++ b/briar-gtk/briar_gtk/containers/main_window.py
@@ -150,7 +150,11 @@ class MainWindowContainer(Container):
     def _load_content(self):
         self._contacts = Contacts(APP().api)
         self._load_contacts()
-        self._contacts.watch_contacts(self._refresh_contacts_async)
+        # TODO: Disconnect if no more needed
+        APP().api.socket_listener.connect("ContactAddedEvent",
+                                          self._refresh_contacts_async)
+        APP().api.socket_listener.connect("ConversationMessageReceivedEvent",
+                                          self._refresh_contacts_async)
 
     def _load_contacts(self):
         self.contacts_list = self._contacts.get()
@@ -158,10 +162,11 @@ class MainWindowContainer(Container):
             contact_row = ContactRowWidget(contact)
             self.contacts_list_box.add(contact_row)
 
-    def _refresh_contacts_async(self):
+    def _refresh_contacts_async(self, message):
         GLib.idle_add(self._refresh_contacts)
 
     def _refresh_contacts(self):
+        # TODO: Keep selected contact with open chat
         self._clear_contact_list()
         self._load_contacts()
 
diff --git a/briar-gtk/briar_gtk/containers/private_chat.py b/briar-gtk/briar_gtk/containers/private_chat.py
index af9062b..9fe44a2 100644
--- a/briar-gtk/briar_gtk/containers/private_chat.py
+++ b/briar-gtk/briar_gtk/containers/private_chat.py
@@ -80,7 +80,9 @@ class PrivateChatContainer(Container):
             # Abusing idle_add function here because otherwise the message box
             # is too small and scrolling cuts out messages
             GLib.idle_add(self._add_message, message)
-        private_chat.watch_messages(self._add_message_async)
+        # TODO: Disconnect if no more needed
+        APP().api.socket_listener.connect("ConversationMessageReceivedEvent",
+                                          self._add_message_async)
 
     def _add_message(self, message):
         message_widget = PrivateMessageWidget(self._contact_name, message)
-- 
GitLab