changeset 2892:82b781c46841

core: added a rosterResync method to bridge: rosterResync do a full resynchronisation of roster with server. This should not be needed, but may be useful if user suspect a sync issue for whatever reason.
author Goffi <goffi@goffi.org>
date Sun, 07 Apr 2019 18:49:41 +0200
parents 6a0f42e9410a
children 7c8773723200
files sat/bridge/bridge_constructor/bridge_template.ini sat/bridge/dbus_bridge.py sat/bridge/pb.py sat/core/sat_main.py sat/core/xmpp.py sat_frontends/bridge/dbus_bridge.py sat_frontends/bridge/pb.py
diffstat 7 files changed, 52 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/bridge_template.ini	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat/bridge/bridge_constructor/bridge_template.ini	Sun Apr 07 18:49:41 2019 +0200
@@ -692,6 +692,16 @@
 doc_param_0=entity_jid: JID to remove from roster
 doc_param_1=%(doc_profile_key)s
 
+[rosterResync]
+async=
+type=method
+category=core
+sig_in=s
+sig_out=
+param_0_default="@DEFAULT@"
+doc=Do a full resynchronisation of roster with server
+doc_param_0=%(doc_profile_key)s
+
 [launchAction]
 async=
 type=method
--- a/sat/bridge/dbus_bridge.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat/bridge/dbus_bridge.py	Sun Apr 07 18:49:41 2019 +0200
@@ -511,6 +511,12 @@
         return self._callback("progressGetAllMetadata", unicode(profile))
 
     @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
+                         in_signature='s', out_signature='',
+                         async_callbacks=('callback', 'errback'))
+    def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None):
+        return self._callback("rosterResync", unicode(profile_key), callback=callback, errback=errback)
+
+    @dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
                          in_signature='s', out_signature='b',
                          async_callbacks=None)
     def saveParamsTemplate(self, filename):
--- a/sat/bridge/pb.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat/bridge/pb.py	Sun Apr 07 18:49:41 2019 +0200
@@ -20,9 +20,9 @@
 
 from sat.core.log import getLogger
 
-log = getLogger(__name__)
 from twisted.spread import jelly, pb
 from twisted.internet import reactor
+log = getLogger(__name__)
 
 
 ## jelly hack
--- a/sat/core/sat_main.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat/core/sat_main.py	Sun Apr 07 18:49:41 2019 +0200
@@ -145,6 +145,7 @@
         self.bridge.register_method("addContact", self._addContact)
         self.bridge.register_method("updateContact", self._updateContact)
         self.bridge.register_method("delContact", self._delContact)
+        self.bridge.register_method("rosterResync", self._rosterResync)
         self.bridge.register_method("isConnected", self.isConnected)
         self.bridge.register_method("launchAction", self.launchCallback)
         self.bridge.register_method("actionsGet", self.actionsGet)
@@ -809,6 +810,10 @@
         self.profiles[profile].presence.unsubscribe(to_jid)  # is not asynchronous
         return self.profiles[profile].roster.removeItem(to_jid)
 
+    def _rosterResync(self, profile_key):
+        client = self.getClient(profile_key)
+        return client.roster.resync()
+
     ## Discovery ##
     # discovery methods are shortcuts to self.memory.disco
     # the main difference with client.disco is that self.memory.disco manage cache
--- a/sat/core/xmpp.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat/core/xmpp.py	Sun Apr 07 18:49:41 2019 +0200
@@ -1171,6 +1171,19 @@
             roster_cache[roster_jid_s] = roster_item_elt
 
     @defer.inlineCallbacks
+    def resync(self):
+        """Ask full roster to resync database
+
+        this should not be necessary, but may be used if user suspsect roster
+        to be somehow corrupted
+        """
+        roster_cache = self.roster_cache
+        yield roster_cache.clear()
+        self._jids.clear()
+        self._groups.clear()
+        yield self.requestRoster()
+
+    @defer.inlineCallbacks
     def requestRoster(self):
         """Ask the server for Roster list """
         if self.versioning:
--- a/sat_frontends/bridge/dbus_bridge.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat_frontends/bridge/dbus_bridge.py	Sun Apr 07 18:49:41 2019 +0200
@@ -726,6 +726,15 @@
             kwargs['error_handler'] = error_handler
         return self.db_core_iface.progressGetAllMetadata(profile, **kwargs)
 
+    def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None):
+        if callback is None:
+            error_handler = None
+        else:
+            if errback is None:
+                errback = log.error
+            error_handler = lambda err:errback(dbus_to_bridge_exception(err))
+        return self.db_core_iface.rosterResync(profile_key, timeout=const_TIMEOUT, reply_handler=callback, error_handler=error_handler)
+
     def saveParamsTemplate(self, filename, callback=None, errback=None):
         if callback is None:
             error_handler = None
--- a/sat_frontends/bridge/pb.py	Sun Apr 07 18:47:17 2019 +0200
+++ b/sat_frontends/bridge/pb.py	Sun Apr 07 18:49:41 2019 +0200
@@ -526,6 +526,14 @@
             errback = self._generic_errback
         d.addErrback(errback)
 
+    def rosterResync(self, profile_key="@DEFAULT@", callback=None, errback=None):
+        d = self.root.callRemote("rosterResync", profile_key)
+        if callback is not None:
+            d.addCallback(lambda __: callback())
+        if errback is None:
+            errback = self._generic_errback
+        d.addErrback(errback)
+
     def saveParamsTemplate(self, filename, callback=None, errback=None):
         d = self.root.callRemote("saveParamsTemplate", filename)
         if callback is not None: