From 493187d448d4d89a20f4ccc66924fefe55e7fe86 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 30 Oct 2011 13:27:32 +0100 Subject: [PATCH] implement XEP-0306 : status conditions for MUC --- src/common/connection_handlers_events.py | 41 ++++++++++++++++++++++-- src/common/xmpp/protocol.py | 12 +++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 34423e4e2..03b04e679 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -42,6 +42,28 @@ import gtkgui_helpers import logging log = logging.getLogger('gajim.c.connection_handlers_events') +CONDITION_TO_CODE = { + 'realjid-public': 100, + 'affiliation-changed': 101, + 'unavailable-shown': 102, + 'unavailable-not-shown': 103, + 'configuration-changed': 104, + 'self-presence': 110, + 'logging-enabled': 170, + 'logging-disabled': 171, + 'non-anonymous': 172, + 'semi-anonymous': 173, + 'fully-anonymous': 174, + 'room-created': 201, + 'nick-assigned': 210, + 'banned': 301, + 'new-nick': 303, + 'kicked': 307, + 'removed-affiliation': 321, + 'removed-membership': 322, + 'removed-shutdown': 332, +} + class HelperEvent: def get_jid_resource(self, check_fake_jid=False): if check_fake_jid and hasattr(self, 'id_') and \ @@ -898,7 +920,15 @@ class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): self.status_code = ['destroyed'] else: self.reason = self.stanza.getReason() - self.status_code = self.stanza.getStatusCode() + conditions = self.stanza.getStatusConditions() + if conditions: + self.status_code = [] + for condition in conditions: + if condition in CONDITION_TO_CODE: + self.status_code.append(CONDITION_TO_CODE[condition]) + else: + self.status_code = self.stanza.getStatusCode() + self.role = self.stanza.getRole() self.affiliation = self.stanza.getAffiliation() self.real_jid = self.stanza.getJid() @@ -1198,7 +1228,14 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent): conn=self.conn, msg_event=self)) return - self.status_code = self.stanza.getStatusCode() + conditions = self.stanza.getStatusConditions() + if conditions: + self.status_code = [] + for condition in conditions: + if condition in CONDITION_TO_CODE: + self.status_code.append(CONDITION_TO_CODE[condition]) + else: + self.status_code = self.stanza.getStatusCode() if not self.stanza.getTag('body'): # no # It could be a config change. See diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py index 7e46d07f4..8dc1cec2e 100644 --- a/src/common/xmpp/protocol.py +++ b/src/common/xmpp/protocol.py @@ -53,6 +53,7 @@ NS_CAPTCHA = 'urn:xmpp:captcha' # XEP-0158 NS_CHATSTATES = 'http://jabber.org/protocol/chatstates' # JEP-0085 NS_CHATTING = 'http://jabber.org/protocol/chatting' # XEP-0194 NS_CLIENT = 'jabber:client' +NS_CONDITIONS = 'urn:xmpp:muc:conditions:0' # XEP-0306 NS_COMMANDS = 'http://jabber.org/protocol/commands' NS_COMPONENT_ACCEPT = 'jabber:component:accept' NS_COMPONENT_1 = 'http://jabberd.jabberstudio.org/ns/component/1.0' @@ -625,6 +626,17 @@ class Protocol(Node): """ return self.getTagAttr('error', 'code') + def getStatusConditions(self): + """ + Return the status conditions list as defined in XEP-0306. + """ + conds = [] + condtag = self.getTag('conditions', namespace=NS_CONDITIONS) + if condtag: + for tag in condtag.getChildren(): + conds.append(tag.getName()) + return conds + def setError(self, error, code=None): """ Set the error code. Obsolete. Use error-conditions instead