From 0314f23aa4d16a247c7e3d7ace0fe138389877c0 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 19 Jul 2007 10:06:59 +0000 Subject: [PATCH] Add notification of Configuration Changes in MUC. See #3270. http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify --- src/common/connection_handlers.py | 6 ++++++ src/common/xmpp/protocol.py | 8 ++++++++ src/gajim.py | 31 +++++++++++++++++++++++++++++++ src/groupchat_control.py | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 9fa71bb1b..695076416 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1529,6 +1529,12 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) else: if not msg.getTag('body'): #no + # It could be a config change. See + # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify + if msg.getTag('x'): + statusCode = msg.getStatusCode() + if statusCode != []: + self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) return # Ignore message from room in which we are not if not self.last_history_line.has_key(jid): diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py index 8409483d8..79883c461 100644 --- a/src/common/xmpp/protocol.py +++ b/src/common/xmpp/protocol.py @@ -449,6 +449,14 @@ class Message(Protocol): th=self.getThread() if th: m.setThread(th) return m + def getStatusCode(self): + """Returns the status code of the message (for groupchat config + change)""" + attrs = [] + for xtag in self.getTags('x'): + for child in xtag.getTags('status'): + attrs.append(child.getAttr('code')) + return attrs class Presence(Protocol): """ XMPP Presence object.""" diff --git a/src/gajim.py b/src/gajim.py index 3a32f617b..d74039ec3 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -1210,6 +1210,36 @@ class Interface: self.instances[account]['gc_config'][room_jid] = \ config.GroupchatConfigWindow(account, room_jid, array[1]) + def handle_event_gc_config_change(self, account, array): + #('GC_CONFIG_CHANGE', account, (jid, statusCode)) statuscode is a list + # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify + jid = array[0] + statusCode = array[1] + + gc_control = self.msg_win_mgr.get_control(jid, account) + if not gc_control and \ + jid in self.minimized_controls[account]: + gc_control = self.minimized_controls[account][jid] + if not gc_control: + return + + changes = [] + if '170' in statusCode: + changes.append(_('Room logging is now enabled')) + if '171' in statusCode: + changes.append(_('Room logging is now disabled')) + if '172' in statusCode: + changes.append(_('Room is now non-anonymous')) + if '173' in statusCode: + changes.append(_('Room is now semi-anonymous')) + if '174' in statusCode: + changes.append(_('Room is now fully-anonymous')) + if '104' in statusCode: + changes.append(_('Room configuration has changed')) + + for change in changes: + gc_control.print_conversation(change) + def handle_event_gc_affiliation(self, account, array): #('GC_AFFILIATION', account, (room_jid, affiliation, list)) list is list room_jid = array[0] @@ -2113,6 +2143,7 @@ class Interface: 'GC_MSG': self.handle_event_gc_msg, 'GC_SUBJECT': self.handle_event_gc_subject, 'GC_CONFIG': self.handle_event_gc_config, + 'GC_CONFIG_CHANGE': self.handle_event_gc_config_change, 'GC_INVITATION': self.handle_event_gc_invitation, 'GC_AFFILIATION': self.handle_event_gc_affiliation, 'GC_PASSWORD_REQUIRED': self.handle_event_gc_password_required, diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 1c560f555..bfd4364e7 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -887,7 +887,7 @@ class GroupchatControl(ChatControlBase): fake_jid = self.room_jid + '/' + nick newly_created = False if '170' in statusCode: - self.print_conversation(_('Room logging is enabled'), 'info') + self.print_conversation(_('Room logging is enabled')) if show in ('offline', 'error'): if '307' in statusCode: if actor is None: # do not print 'kicked by None'