From 9634f98250e7b0e630f238bb5778e162a4082457 Mon Sep 17 00:00:00 2001 From: js Date: Tue, 17 Jun 2008 16:03:21 +0000 Subject: [PATCH] * Implemented XEP-0184 section 5. * Added NS_RECEIPTS to protocol namespace list. * Show our support of XEP-0184 in caps. * Added a big, fat warning to get_contact as this does not work as expected. * There was some strangeness in our XEP-0022, it added an id tag to the x tag, which isn't mentioned anywhere in the XEP. And for some strange reason, that id even was the same all the time. * Fixed a typo. --- src/common/config.py | 2 +- src/common/connection.py | 23 +++++++++++++---------- src/common/connection_handlers.py | 6 +++--- src/common/contacts.py | 5 +++++ src/common/helpers.py | 2 ++ src/common/xmpp/protocol.py | 1 + 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 9b950705a..7816e616d 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -311,7 +311,7 @@ class Config: 'zeroconf_jabber_id': [ opt_str, '', '', True ], 'zeroconf_email': [ opt_str, '', '', True ], 'use_env_http_proxy' : [opt_bool, False], - 'answer_receipt' : [opt_bool, True, _('Answer to receipt requests')], + 'answer_receipts' : [opt_bool, True, _('Answer to receipt requests')], 'request_receipt' : [opt_bool, True, _('Sent receipt requests')], 'publish_mood': [opt_bool, True], 'publish_activity': [opt_bool, True], diff --git a/src/common/connection.py b/src/common/connection.py index c3cdcaab5..a7a9f03d7 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1096,11 +1096,6 @@ class Connection(ConnectionHandlers): # XEP-0022 chatstate_node = msg_iq.setTag('x', namespace = common.xmpp.NS_EVENT) - if not msgtxt: # when no , add - if not msg_id: # avoid putting 'None' in tag - msg_id = '' - chatstate_node.setTagData('id', msg_id) - # when msgtxt, requests XEP-0022 composing notification if chatstate is 'composing' or msgtxt: chatstate_node.addChild(name = 'composing') @@ -1110,12 +1105,20 @@ class Connection(ConnectionHandlers): addresses.addChild('address', attrs = {'type': 'ofrom', 'jid': forward_from}) - # TODO: We should also check if the other end supports it - # as XEP 0184 says checking is a SHOULD. Maybe we should - # implement section 6 of the XEP as well? + # XEP-0184 + if resource: + contact = gajim.contacts.get_contact(self.name, jid, + resource) + else: + contact = gajim.contacts. \ + get_contact_with_highest_priority(self.name, + jid) if msgtxt and gajim.config.get_per('accounts', self.name, - 'request_receipt'): - msg_iq.setTag('request', namespace='urn:xmpp:receipts') + 'request_receipt') and common.xmpp.NS_RECEIPTS in \ + gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: + msg_iq.setTag('request', + namespace=common.xmpp.NS_RECEIPTS) if session: # XEP-0201 diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 5677abe6b..352332994 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1693,11 +1693,11 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, # Receipt requested # TODO: We shouldn't answer if we're invisible! - cont = gajim.contacts.get_contact(self.name, + contact = gajim.contacts.get_contact(self.name, common.gajim.get_room_and_nick_from_fjid(frm)[0]) if msg.getTag('request', namespace='urn:xmpp:receipts') and \ - gajim.config.get_per('accounts', self.name, 'answer_receipt') \ - and cont and cont.sub not in (u'to', u'none'): + gajim.config.get_per('accounts', self.name, 'answer_receipts') \ + and contact and contact.sub not in (u'to', u'none'): receipt = common.xmpp.Message(to = jid, typ = 'chat') receipt.setID(msg.getID()) receipt.setTag('received', diff --git a/src/common/contacts.py b/src/common/contacts.py index ec4be9871..665e67d2f 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -248,6 +248,11 @@ class Contacts: return [] def get_contact(self, account, jid, resource = None): + ### WARNING ### + # This function returns a *RANDOM* resource if resource = None! + # Do *NOT* use if you need to get the contact to which you + # send a message for example, as a bare JID in Jabber means + # highest available resource, which this function ignores! '''Returns the contact instance for the given resource if it's given else the first contact is no resource is given or None if there is not''' if jid in self._contacts[account]: diff --git a/src/common/helpers.py b/src/common/helpers.py index 69ab35906..9cb497df1 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -1346,6 +1346,8 @@ def update_optional_features(account = None): gajim.gajim_optional_features[a].append(xmpp.NS_XHTML_IM) if gajim.HAVE_PYCRYPTO: gajim.gajim_optional_features[a].append(xmpp.NS_ESESSION_INIT) + if gajim.config.get_per('accounts', a, 'answer_receipts'): + gajim.gajim_optional_features[a].append(xmpp.NS_RECEIPTS) gajim.caps_hash[a] = compute_caps_hash([gajim.gajim_identity], gajim.gajim_common_features + gajim.gajim_optional_features[a]) # re-send presence with new hash diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py index a9140c8f9..188a83895 100644 --- a/src/common/xmpp/protocol.py +++ b/src/common/xmpp/protocol.py @@ -111,6 +111,7 @@ NS_XHTML = 'http://www.w3.org/1999/xhtml' # " NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # XEP-0141 NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate' # XEP-0122 NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams' +NS_RECEIPTS ='urn:xmpp:receipt' xmpp_stream_error_conditions=""" bad-format -- -- -- The entity has sent XML that cannot be processed.