From 0abc789403c91de119f917944f7754043f445242 Mon Sep 17 00:00:00 2001 From: mathieui Date: Mon, 3 Jun 2013 23:12:19 +0200 Subject: Do not block on roster operations (and do not traceback on errors) #2315 --- src/connection.py | 3 ++- src/tabs.py | 46 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/connection.py b/src/connection.py index 9a952793..d931283e 100644 --- a/src/connection.py +++ b/src/connection.py @@ -49,13 +49,14 @@ class Connection(sleekxmpp.ClientXMPP): jid = safeJID(jid) # TODO: use the system language sleekxmpp.ClientXMPP.__init__(self, jid, password, lang=config.get('lang', 'en')) + self.core = None self.auto_reconnect = True if config.get('auto_reconnect', 'false').lower() in ('true', '1') else False self.reconnect_max_attempts = 0 self.auto_authorize = None self.ca_certs = config.get('ca_cert_path', '') or None interval = config.get('whitespace_interval', '300') - if interval.isnumeric(): + if interval.isdecimal() and int(interval) > 0: self.whitespace_keepalive_interval = int(interval) else: self.whitespace_keepalive_interval = 300 diff --git a/src/tabs.py b/src/tabs.py index d2ed1894..f99ba388 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -2407,6 +2407,10 @@ class RosterInfoTab(Tab): """ Set a name for the specified JID in your roster """ + def callback(iq): + if not iq: + self.core.information('The name could not be set.', 'Error') + log.debug('Error in /name:\n%s', iq) args = common.shell_split(arg) if not args: return self.core.command_help('name') @@ -2419,9 +2423,11 @@ class RosterInfoTab(Tab): return groups = set(contact.groups) + if 'none' in groups: + groups.remove('none') subscription = contact.subscription - if not self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription): - self.core.information('The name could not be set.', 'Error') + self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription, + callback=callback, block=False) def command_groupadd(self, args): """ @@ -2452,8 +2458,16 @@ class RosterInfoTab(Tab): name = contact.name subscription = contact.subscription - if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription): - roster.update_contact_groups(jid) + + def callback(iq): + if iq: + roster.update_contact_groups(jid) + else: + self.core.information('The group could not be set.', 'Error') + log.debug('Error in groupadd:\n%s', iq) + + self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription, + callback=callback, block=False) def command_groupmove(self, arg): """ @@ -2499,8 +2513,16 @@ class RosterInfoTab(Tab): new_groups.remove(group_from) name = contact.name subscription = contact.subscription - if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription): - roster.update_contact_groups(contact) + + def callback(iq): + if iq: + roster.update_contact_groups(contact) + else: + self.information('The group could not be set') + log.debug('Error in groupmove:\n%s', iq) + + self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription, + callback=callback, block=False) def command_groupremove(self, args): """ @@ -2531,8 +2553,16 @@ class RosterInfoTab(Tab): new_groups.remove(group) name = contact.name subscription = contact.subscription - if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription): - roster.update_contact_groups(jid) + + def callback(iq): + if iq: + roster.update_contact_groups(jid) + else: + self.information('The group could not be set') + log.debug('Error in groupremove:\n%s', iq) + + self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription, + callback=callback, block=False) def command_remove(self, args): """ -- cgit v1.2.3