use NEC to handle groupchat config changed events

This commit is contained in:
Yann Leboulanger 2010-11-27 21:02:41 +01:00
parent 11e8f9e779
commit ef741a0084
4 changed files with 52 additions and 56 deletions

View File

@ -1582,14 +1582,6 @@ ConnectionJingle, ConnectionIBBytestream):
statusCode = msg.getStatusCode()
if not msg.getTag('body'): # no <body>
# It could be a config change. See
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
if msg.getTag('x'):
if statusCode != []:
self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode))
return
displaymarking = None
seclabel = msg.getTag('securitylabel')
if seclabel and seclabel.getNamespace() == common.xmpp.NS_SECLABEL:

View File

@ -1081,8 +1081,8 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
if self.stanza.getTag('x'):
if self.status_code != []:
self.conn.dispatch('GC_CONFIG_CHANGE', (self.jid,
self.status_code))
gajim.nec.push_incoming_event(GcConfigChangedReceivedEvent(
None, conn=self.conn, msg_event=self))
return
self.displaymarking = None
@ -1133,6 +1133,17 @@ class GcSubjectReceivedEvent(nec.NetworkIncomingEvent):
self.has_timestamp = self.msg_event.has_timestamp
return True
class GcConfigChangedReceivedEvent(nec.NetworkIncomingEvent):
name = 'gc-config-changed-received'
base_network_events = []
def generate(self):
self.conn = self.msg_event.conn
self.stanza = self.msg_event.stanza
self.room_jid = self.msg_event.room_jid
self.status_code = self.msg_event.status_code
return True
class MessageSentEvent(nec.NetworkIncomingEvent):
name = 'message-sent'
base_network_events = []

View File

@ -462,6 +462,8 @@ class GroupchatControl(ChatControlBase):
self._nec_vcard_received)
gajim.ged.register_event_handler('gc-subject-received', ged.GUI1,
self._nec_gc_subject_received)
gajim.ged.register_event_handler('gc-config-changed-received', ged.GUI1,
self._nec_gc_config_changed_received)
gajim.gc_connected[self.account][self.room_jid] = False
# disable win, we are not connected yet
ChatControlBase.got_disconnected(self)
@ -1191,6 +1193,41 @@ class GroupchatControl(ChatControlBase):
else:
self.print_conversation(text)
def _nec_gc_config_changed_received(self, obj):
# statuscode is a list
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
# http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
# -init
changes = []
if '100' in obj.statusCode:
# Can be a presence (see chg_contact_status in groupchat_control.py)
changes.append(_('Any occupant is allowed to see your full JID'))
gc_control.is_anonymous = False
if '102' in statusCode:
changes.append(_('Room now shows unavailable member'))
if '103' in statusCode:
changes.append(_('room now does not show unavailable members'))
if '104' in statusCode:
changes.append(_('A non-privacy-related room configuration change '
'has occurred'))
if '170' in statusCode:
# Can be a presence (see chg_contact_status in groupchat_control.py)
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'))
gc_control.is_anonymous = False
if '173' in statusCode:
changes.append(_('Room is now semi-anonymous'))
gc_control.is_anonymous = True
if '174' in statusCode:
changes.append(_('Room is now fully-anonymous'))
gc_control.is_anonymous = True
for change in changes:
self.print_conversation(change)
def got_connected(self):
# Make autorejoin stop.
if self.autorejoin:
@ -1816,6 +1853,8 @@ class GroupchatControl(ChatControlBase):
self._nec_vcard_received)
gajim.ged.remove_event_handler('gc-subject-received', ged.GUI1,
self._nec_gc_subject_received)
gajim.ged.remove_event_handler('gc-config-changed-received', ged.GUI1,
self._nec_gc_config_changed_received)
if self.room_jid in gajim.gc_connected[self.account] and \
gajim.gc_connected[self.account][self.room_jid]:

View File

@ -626,51 +626,6 @@ class Interface:
self.instances[account]['gc_config'][obj.jid] = \
config.GroupchatConfigWindow(account, obj.jid, obj.dataform)
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
# http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
# -init
jid = array[0]
statusCode = array[1]
gc_control = self.msg_win_mgr.get_gc_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 '100' in statusCode:
# Can be a presence (see chg_contact_status in groupchat_control.py)
changes.append(_('Any occupant is allowed to see your full JID'))
gc_control.is_anonymous = False
if '102' in statusCode:
changes.append(_('Room now shows unavailable member'))
if '103' in statusCode:
changes.append(_('room now does not show unavailable members'))
if '104' in statusCode:
changes.append(_('A non-privacy-related room configuration change '
'has occurred'))
if '170' in statusCode:
# Can be a presence (see chg_contact_status in groupchat_control.py)
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'))
gc_control.is_anonymous = False
if '173' in statusCode:
changes.append(_('Room is now semi-anonymous'))
gc_control.is_anonymous = True
if '174' in statusCode:
changes.append(_('Room is now fully-anonymous'))
gc_control.is_anonymous = True
for change in changes:
gc_control.print_conversation(change)
def handle_event_gc_affiliation(self, obj):
#('GC_AFFILIATION', account, (room_jid, users_dict))
account = obj.conn.name
@ -1466,7 +1421,6 @@ class Interface:
'MSGERROR': [self.handle_event_msgerror],
'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change],
'FILE_REQUEST': [self.handle_event_file_request],
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
'FILE_SEND_ERROR': [self.handle_event_file_send_error],