Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0045.py @ 2994:94708a7d3ecf
core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
an old hardcoded value was used in several places to detect if an entity is a MUC, but this
value was not valid anymore. This has been fixed, and ENTITY_TYPE_MUC constant is now used
instead. This fixes message type autodetection for "groupchat" messages.
fixes 300
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 09 Jul 2019 09:06:45 +0200 |
parents | f4590ca2acff |
children | 6acaa8244220 |
comparison
equal
deleted
inserted
replaced
2993:d58dccd9e4b4 | 2994:94708a7d3ecf |
---|---|
56 NS_MUC = 'http://jabber.org/protocol/muc' | 56 NS_MUC = 'http://jabber.org/protocol/muc' |
57 AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast') | 57 AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast') |
58 ROOM_USER_JOINED = 'ROOM_USER_JOINED' | 58 ROOM_USER_JOINED = 'ROOM_USER_JOINED' |
59 ROOM_USER_LEFT = 'ROOM_USER_LEFT' | 59 ROOM_USER_LEFT = 'ROOM_USER_LEFT' |
60 OCCUPANT_KEYS = ('nick', 'entity', 'affiliation', 'role') | 60 OCCUPANT_KEYS = ('nick', 'entity', 'affiliation', 'role') |
61 ENTITY_TYPE_MUC = "MUC" | |
62 ROOM_STATE_OCCUPANTS = "occupants" | 61 ROOM_STATE_OCCUPANTS = "occupants" |
63 ROOM_STATE_SELF_PRESENCE = "self-presence" | 62 ROOM_STATE_SELF_PRESENCE = "self-presence" |
64 ROOM_STATE_LIVE = "live" | 63 ROOM_STATE_LIVE = "live" |
65 ROOM_STATES = (ROOM_STATE_OCCUPANTS, ROOM_STATE_SELF_PRESENCE, ROOM_STATE_LIVE) | 64 ROOM_STATES = (ROOM_STATE_OCCUPANTS, ROOM_STATE_SELF_PRESENCE, ROOM_STATE_LIVE) |
66 HISTORY_LEGACY = u"legacy" | 65 HISTORY_LEGACY = u"legacy" |
1037 self._changing_nicks.discard(presence.nick) | 1036 self._changing_nicks.discard(presence.nick) |
1038 self.userLeftRoom(room, user) | 1037 self.userLeftRoom(room, user) |
1039 | 1038 |
1040 def userJoinedRoom(self, room, user): | 1039 def userJoinedRoom(self, room, user): |
1041 if user.nick == room.nick: | 1040 if user.nick == room.nick: |
1042 # we have received our own nick, this mean that the full room roster was received | 1041 # we have received our own nick, |
1042 # this mean that the full room roster was received | |
1043 self.changeRoomState(room, ROOM_STATE_SELF_PRESENCE) | 1043 self.changeRoomState(room, ROOM_STATE_SELF_PRESENCE) |
1044 log.debug(u"room {room} joined with nick {nick}".format(room=room.occupantJID.userhost(), nick=user.nick)) | 1044 log.debug(u"room {room} joined with nick {nick}".format( |
1045 # We set type so we don't have to use a deferred with disco to check entity type | 1045 room=room.occupantJID.userhost(), nick=user.nick)) |
1046 self.host.memory.updateEntityData(room.roomJID, C.ENTITY_TYPE, ENTITY_TYPE_MUC, profile_key=self.client.profile) | 1046 # we set type so we don't have to use a deferred |
1047 # with disco to check entity type | |
1048 self.host.memory.updateEntityData( | |
1049 room.roomJID, C.ENTITY_TYPE, C.ENTITY_TYPE_MUC, | |
1050 profile_key=self.client.profile) | |
1047 elif room.state not in (ROOM_STATE_OCCUPANTS, ROOM_STATE_LIVE): | 1051 elif room.state not in (ROOM_STATE_OCCUPANTS, ROOM_STATE_LIVE): |
1048 log.warning(u"Received user presence data in a room before its initialisation (current state: {state})," | 1052 log.warning( |
1049 "this is not standard! Ignoring it: {room} ({nick})".format( | 1053 u"Received user presence data in a room before its initialisation " |
1050 state=room.state, | 1054 u"(current state: {state})," |
1051 room=room.roomJID.userhost(), | 1055 u"this is not standard! Ignoring it: {room} ({nick})".format( |
1052 nick=user.nick)) | 1056 state=room.state, |
1057 room=room.roomJID.userhost(), | |
1058 nick=user.nick)) | |
1053 return | 1059 return |
1054 else: | 1060 else: |
1055 if not room.fully_joined.called: | 1061 if not room.fully_joined.called: |
1056 return | 1062 return |
1057 try: | 1063 try: |
1058 self._changing_nicks.remove(user.nick) | 1064 self._changing_nicks.remove(user.nick) |
1059 except KeyError: | 1065 except KeyError: |
1060 # this is a new user | 1066 # this is a new user |
1061 log.debug(_(u"user {nick} has joined room {room_id}").format(nick=user.nick, room_id=room.occupantJID.userhost())) | 1067 log.debug(_(u"user {nick} has joined room {room_id}").format( |
1062 if not self.host.trigger.point("MUC user joined", room, user, self.client.profile): | 1068 nick=user.nick, room_id=room.occupantJID.userhost())) |
1069 if not self.host.trigger.point( | |
1070 "MUC user joined", room, user, self.client.profile): | |
1063 return | 1071 return |
1064 | 1072 |
1065 extra = {'info_type': ROOM_USER_JOINED, | 1073 extra = {'info_type': ROOM_USER_JOINED, |
1066 'user_affiliation': user.affiliation, | 1074 'user_affiliation': user.affiliation, |
1067 'user_role': user.role, | 1075 'user_role': user.role, |