From 04e1d0270724c729208694abdde9e1346926c9a5 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 10 Feb 2013 18:57:25 +0100 Subject: [PATCH] send RIE stanza as an IQ if user is online and supports RIE. Fixes #7289 --- src/common/connection.py | 26 +++++++++++++++----------- src/roster_window.py | 9 +++++++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index c2aefdaf8..554bfde8f 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1879,26 +1879,30 @@ class Connection(CommonConnection, ConnectionHandlers): form_node=obj.form_node, original_message=obj.original_message, delayed=obj.delayed, attention=obj.attention, callback=cb) - def send_contacts(self, contacts, jid): + def send_contacts(self, contacts, fjid, type_='message'): """ Send contacts with RosterX (Xep-0144) """ if not gajim.account_is_connected(self.name): return - if len(contacts) == 1: - msg = _('Sent contact: "%s" (%s)') % (contacts[0].get_full_jid(), + if type_ == 'message': + if len(contacts) == 1: + msg = _('Sent contact: "%s" (%s)') % (contacts[0].get_full_jid(), contacts[0].get_shown_name()) - else: - msg = _('Sent contacts:') - for contact in contacts: - msg += '\n "%s" (%s)' % (contact.get_full_jid(), + else: + msg = _('Sent contacts:') + for contact in contacts: + msg += '\n "%s" (%s)' % (contact.get_full_jid(), contact.get_shown_name()) - msg_iq = nbxmpp.Message(to=jid, body=msg) - x = msg_iq.addChild(name='x', namespace=nbxmpp.NS_ROSTERX) + stanza = nbxmpp.Message(to=gajim.get_jid_without_resource(fjid), + body=msg) + elif type_ == 'iq': + stanza = nbxmpp.Iq(to=fjid, typ='set') + x = stanza.addChild(name='x', namespace=nbxmpp.NS_ROSTERX) for contact in contacts: x.addChild(name='item', attrs={'action': 'add', 'jid': contact.jid, - 'name': contact.get_shown_name()}) - self.connection.send(msg_iq) + 'name': contact.get_shown_name()}) + self.connection.send(stanza) def send_stanza(self, stanza): """ diff --git a/src/roster_window.py b/src/roster_window.py index 06fb65a66..34de47ab2 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -70,7 +70,7 @@ from common import dbus_support if dbus_support.supported: import dbus -from nbxmpp.protocol import NS_FILE +from nbxmpp.protocol import NS_FILE, NS_ROSTERX from common.pep import MOODS, ACTIVITIES #(icon, name, type, jid, account, editable, second pixbuf) @@ -4503,7 +4503,12 @@ class RosterWindow: def on_drop_rosterx(self, widget, account_source, c_source, account_dest, c_dest, was_big_brother, context, etime): - gajim.connections[account_dest].send_contacts([c_source], c_dest.jid) + type_ = 'message' + if c_dest.show not in ('offline', 'error') and c_dest.supports( + NS_ROSTERX): + type_ = 'iq' + gajim.connections[account_dest].send_contacts([c_source], + c_dest.get_full_jid(), type_=type_) def on_drop_in_contact(self, widget, account_source, c_source, account_dest, c_dest, was_big_brother, context, etime):