implement XEP-0306 : status conditions for MUC
This commit is contained in:
parent
19306fbf6f
commit
493187d448
2 changed files with 51 additions and 2 deletions
|
@ -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 <body>
|
||||
# It could be a config change. See
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue