From 9457c28a6377fc367a79aeaf228a2cee3a9b1257 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 25 Jun 2008 09:25:43 +0000 Subject: [PATCH] don't try the old (XEP-018) way to go invisible. It's not XMPP complient. That prevent to show the we are invisible but we are not. Fixes #4012 --- src/common/connection.py | 34 +++++++++++++++++-------------- src/common/connection_handlers.py | 8 ++++++++ src/roster_window.py | 7 ++++++- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 641b02a52..b7e7dc128 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -811,6 +811,11 @@ class Connection(ConnectionHandlers): def send_invisible_presence(self, msg, signed, initial = False): if not self.connection: return + if not self.privacy_rules_supported: + self.dispatch('STATUS', gajim.SHOW_LIST[self.connected]) + self.dispatch('ERROR', (_('Invisibility not supported'), + _('Account %s doesn\'t support invisibility.') % self.name)) + return # If we are already connected, and privacy rules are supported, send # offline presence first as it's required by XEP-0126 if self.connected > 1 and self.privacy_rules_supported: @@ -828,19 +833,16 @@ class Connection(ConnectionHandlers): {'msg': msg, 'signed': signed, 'initial': initial}) def _continue_invisible(self, con, iq_obj, msg, signed, initial): - ptype = '' - show = '' if iq_obj.getType() == 'error': # server doesn't support privacy lists - # We use the old way which is not xmpp complient - ptype = 'invisible' - show = 'invisible' - else: - # active the privacy rule - self.privacy_rules_supported = True - self.activate_privacy_rule('invisible') - priority = unicode(gajim.get_priority(self.name, show)) - p = common.xmpp.Presence(typ = ptype, priority = priority, show = show) - p = self.add_sha(p, ptype != 'unavailable') + return + # active the privacy rule + self.privacy_rules_supported = True + self.activate_privacy_rule('invisible') + self.connected = STATUS_LIST.index('invisible') + self.status = msg + priority = unicode(gajim.get_priority(self.name, 'invisible')) + p = common.xmpp.Presence(priority = priority) + p = self.add_sha(p, True) if msg: p.setStatus(msg) if signed: @@ -953,7 +955,9 @@ class Connection(ConnectionHandlers): sign_msg = False if not auto and not show == 'offline': sign_msg = True - self.status = msg + if show != 'invisible': + # We save it only when privacy list is accepted + self.status = msg if show != 'offline' and self.connected < 1: # set old_show to requested 'show' in case we need to # recconect before we auth to server @@ -993,12 +997,12 @@ class Connection(ConnectionHandlers): # dont'try to connect, when we are in state 'connecting' if self.connected == 1: return - was_invisible = self.connected == STATUS_LIST.index('invisible') - self.connected = STATUS_LIST.index(show) if show == 'invisible': signed = self.get_signed_presence(msg) self.send_invisible_presence(msg, signed) return + was_invisible = self.connected == STATUS_LIST.index('invisible') + self.connected = STATUS_LIST.index(show) if was_invisible and self.privacy_rules_supported: iq = self.build_privacy_rule('visible', 'allow') self.connection.send(iq) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index e00b2d2cd..bf7b10769 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1101,6 +1101,14 @@ class ConnectionVcard: if iq_obj.getType() != 'error': self.privacy_rules_supported = True self.get_privacy_list('block') + elif self.continue_connect_info: + if self.continue_connect_info[0] == 'invisible': + # Trying to login as invisible but privacy list not supported + self.disconnect(on_purpose=True) + self.dispatch('STATUS', 'offline') + self.dispatch('ERROR', (_('Invisibility not supported'), + _('Account %s doesn\'t support invisibility.') % self.name)) + return # Ask metacontacts before roster self.get_metacontacts() elif self.awaiting_answers[id][0] == PEP_CONFIG: diff --git a/src/roster_window.py b/src/roster_window.py index d9e83776b..7082e1d7b 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -4450,7 +4450,12 @@ class RosterWindow: icon = state_images[show] item.set_image(icon) sub_menu.append(item) - item.connect('activate', self.change_status, account, show) + con = gajim.connections[account] + if show == 'invisible' and con.connected > 1 and \ + not con.privacy_rules_supported: + item.set_sensitive(False) + else: + item.connect('activate', self.change_status, account, show) item = gtk.SeparatorMenuItem() sub_menu.append(item)