Move MUC config change handling into MUC module

- Remove status conditions code, since the XEP made a namespace bump to :1 and is now backwards compatible its useless
- XEP-0045 mentions status code 100 can be in messages but there is no case given where this would ever happen, so its removed from message handling
This commit is contained in:
Philipp Hörist 2018-12-19 02:22:16 +01:00
parent b935ce7096
commit 1fec6681cd
4 changed files with 53 additions and 62 deletions

View File

@ -40,27 +40,6 @@ from gajim.common.file_props import FilesProp
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):
@ -378,13 +357,6 @@ class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.status_code = ['destroyed']
else:
self.reason = self.stanza.getReason()
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()
@ -429,22 +401,7 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
# message from server
self.nick = ''
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
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
if self.stanza.getTag('x'):
if self.status_code != []:
app.nec.push_incoming_event(GcConfigChangedReceivedEvent(
None, conn=self.conn, msg_event=self))
if self.msg_obj.form_node:
# It could be a voice request. See
# http://www.xmpp.org/extensions/xep-0045.html#voiceapprove

View File

@ -26,6 +26,7 @@ from gajim.common.modules import dataforms
from gajim.common import app
from gajim.common import helpers
from gajim.common.caps_cache import muc_caps_cache
from gajim.common.nec import NetworkEvent
from gajim.common.nec import NetworkIncomingEvent
log = logging.getLogger('gajim.c.m.muc')
@ -37,6 +38,7 @@ class MUC:
self._account = con.name
self.handlers = [
('message', self._on_config_change, '', nbxmpp.NS_MUC_USER),
('message', self._mediated_invite, '', nbxmpp.NS_MUC_USER),
('message', self._direct_invite, '', nbxmpp.NS_CONFERENCE),
]
@ -154,6 +156,41 @@ class MUC:
self._con.connection.SendAndCallForResponse(
iq, self._default_response, {})
def _on_config_change(self, _con, stanza):
muc_user = stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER)
if muc_user is None:
return
if stanza.getBody():
return
room_list = app.contacts.get_gc_list(self._account)
room_jid = str(stanza.getFrom())
if room_jid not in room_list:
# Message not from a group chat
return
# https://xmpp.org/extensions/xep-0045.html#registrar-statuscodes
change_codes = ['100', '102', '103', '104',
'170', '171', '172', '173', '174']
codes = set()
for status in muc_user.getTags('status'):
code = status.getAttr('code')
if code in change_codes:
codes.add(code)
if not codes:
return
log.info('Received config change: %s', codes)
app.nec.push_incoming_event(
NetworkEvent('gc-config-changed-received',
account=self._account,
room_jid=room_jid,
status_codes=codes))
raise nbxmpp.NodeProcessed
def destroy(self, room_jid, reason='', jid=''):
if not app.account_is_connected(self._account):
return

View File

@ -1126,9 +1126,6 @@ class GroupchatControl(ChatControlBase):
self.parent_win.redraw_tab(self, 'attention')
else:
self.attention_flag = True
if '100' in obj.status_code:
# Room is not anonymous
self.is_anonymous = False
if not obj.nick:
# message from server
self.print_conversation(
@ -1416,40 +1413,40 @@ class GroupchatControl(ChatControlBase):
else:
self.subject_button.show()
def _nec_gc_config_changed_received(self, obj):
# statuscode is a list
def _nec_gc_config_changed_received(self, event):
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
# http://www.xmpp.org/extensions/xep-0045.html#registrar-statuscodes...
# -init
if obj.room_jid != self.room_jid or obj.conn.name != self.account:
if event.account != self.account:
return
if event.room_jid != self.room_jid:
return
changes = []
if '100' in obj.status_code:
if '100' in event.status_codes:
# Can be a presence (see chg_contact_status in groupchat_control.py)
changes.append(_('Any occupant is allowed to see your full JID'))
self.is_anonymous = False
if '102' in obj.status_code:
if '102' in event.status_codes:
changes.append(_('Room now shows unavailable members'))
if '103' in obj.status_code:
if '103' in event.status_codes:
changes.append(_('Room now does not show unavailable members'))
if '104' in obj.status_code:
if '104' in event.status_codes:
changes.append(_('A setting not related to privacy has been '
'changed'))
app.connections[self.account].get_module('Discovery').disco_muc(
self.room_jid, self.update_actions, update=True)
if '170' in obj.status_code:
if '170' in event.status_codes:
# Can be a presence (see chg_contact_status in groupchat_control.py)
changes.append(_('Room logging is now enabled'))
if '171' in obj.status_code:
if '171' in event.status_codes:
changes.append(_('Room logging is now disabled'))
if '172' in obj.status_code:
if '172' in event.status_codes:
changes.append(_('Room is now non-anonymous'))
self.is_anonymous = False
if '173' in obj.status_code:
if '173' in event.status_codes:
changes.append(_('Room is now semi-anonymous'))
self.is_anonymous = True
if '174' in obj.status_code:
if '174' in event.status_codes:
changes.append(_('Room is now fully anonymous'))
self.is_anonymous = True

View File

@ -385,7 +385,7 @@ class GajimRemote(Server):
# event has not been handled at GUI level
return
self.raise_signal('GCMessage', (obj.conn.name, [obj.fjid, obj.msgtxt,
obj.timestamp, obj.delayed, obj.xhtml_msgtxt, obj.status_code,
obj.timestamp, obj.delayed, obj.xhtml_msgtxt,
obj.displaymarking, obj.captcha_form, obj.needs_highlight]))
def on_our_status(self, obj):