From 55a4e6c9779ae74236fcd8510117e20a670b08ad Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 22 Apr 2007 19:45:19 +0000 Subject: [PATCH] fix send_custom_status function. see #342 --- src/common/connection.py | 34 ++++++++++++++++++---- src/common/zeroconf/connection_zeroconf.py | 2 +- src/roster_window.py | 5 +++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 088a6648b..86d4bb23d 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -731,7 +731,33 @@ class Connection(ConnectionHandlers): self.awaiting_answers[id] = (PRIVACY_ARRIVED, ) self.connection.send(iq) - def change_status(self, show, msg, auto = False, to = None): + def send_custom_status(self, show, msg, jid): + if not show in STATUS_LIST: + return -1 + if not self.connection: + return + sshow = helpers.get_xmpp_show(show) + if not msg: + msg = '' + keyID = gajim.config.get_per('accounts', self.name, 'keyid') + if show == 'offline': + p = common.xmpp.Presence(typ = 'unavailable') + p = self.add_sha(p, False) + if msg: + p.setStatus(msg) + else: + signed = self.get_signed_msg(msg) + priority = unicode(gajim.get_priority(self.name, sshow)) + p = common.xmpp.Presence(typ = None, priority = priority, show = sshow, + to = jid) + p = self.add_sha(p) + if msg: + p.setStatus(msg) + if signed: + p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed) + self.connection.send(p) + + def change_status(self, show, msg, auto = False): if not show in STATUS_LIST: return -1 sshow = helpers.get_xmpp_show(show) @@ -780,8 +806,7 @@ class Connection(ConnectionHandlers): self.connection.send(iq) self.activate_privacy_rule('visible') priority = unicode(gajim.get_priority(self.name, sshow)) - p = common.xmpp.Presence(typ = None, priority = priority, show = sshow, - to = to) + p = common.xmpp.Presence(typ = None, priority = priority, show = sshow) p = self.add_sha(p) if msg: p.setStatus(msg) @@ -790,8 +815,7 @@ class Connection(ConnectionHandlers): if self.connection: self.connection.send(p) self.priority = priority - if not to: - self.dispatch('STATUS', show) + self.dispatch('STATUS', show) def _on_disconnected(self): ''' called when a disconnect request has completed successfully''' diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 4418b2519..95efd170e 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -283,7 +283,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): else: self.reannounce() - def change_status(self, show, msg, sync = False, auto = False, to = None): + def change_status(self, show, msg, sync = False, auto = False): if not show in STATUS_LIST: return -1 self.status = show diff --git a/src/roster_window.py b/src/roster_window.py index 7e9dd3746..32884ac81 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -2848,7 +2848,10 @@ class RosterWindow: gajim.sleeper_state[account] = 'online' elif gajim.sleeper_state[account] not in ('autoaway', 'autoxa'): gajim.sleeper_state[account] = 'off' - gajim.connections[account].change_status(status, txt, auto, to = to) + if to: + gajim.connections[account].send_custom_status(status, txt, to) + else: + gajim.connections[account].change_status(status, txt, auto) for gc_control in gajim.interface.msg_win_mgr.get_controls( message_control.TYPE_GC):