diff 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
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0045.py	Mon Jul 08 19:11:29 2019 +0200
+++ b/sat/plugins/plugin_xep_0045.py	Tue Jul 09 09:06:45 2019 +0200
@@ -58,7 +58,6 @@
 ROOM_USER_JOINED = 'ROOM_USER_JOINED'
 ROOM_USER_LEFT = 'ROOM_USER_LEFT'
 OCCUPANT_KEYS = ('nick', 'entity', 'affiliation', 'role')
-ENTITY_TYPE_MUC = "MUC"
 ROOM_STATE_OCCUPANTS = "occupants"
 ROOM_STATE_SELF_PRESENCE = "self-presence"
 ROOM_STATE_LIVE = "live"
@@ -1039,17 +1038,24 @@
 
     def userJoinedRoom(self, room, user):
         if user.nick == room.nick:
-            # we have received our own nick, this mean that the full room roster was received
+            # we have received our own nick,
+            # this mean that the full room roster was received
             self.changeRoomState(room, ROOM_STATE_SELF_PRESENCE)
-            log.debug(u"room {room} joined with nick {nick}".format(room=room.occupantJID.userhost(), nick=user.nick))
-            # We set type so we don't have to use a deferred with disco to check entity type
-            self.host.memory.updateEntityData(room.roomJID, C.ENTITY_TYPE, ENTITY_TYPE_MUC, profile_key=self.client.profile)
+            log.debug(u"room {room} joined with nick {nick}".format(
+                room=room.occupantJID.userhost(), nick=user.nick))
+            # we set type so we don't have to use a deferred
+            # with disco to check entity type
+            self.host.memory.updateEntityData(
+                room.roomJID, C.ENTITY_TYPE, C.ENTITY_TYPE_MUC,
+                profile_key=self.client.profile)
         elif room.state not in (ROOM_STATE_OCCUPANTS, ROOM_STATE_LIVE):
-            log.warning(u"Received user presence data in a room before its initialisation (current state: {state}),"
-                "this is not standard! Ignoring it: {room} ({nick})".format(
-                state=room.state,
-                room=room.roomJID.userhost(),
-                nick=user.nick))
+            log.warning(
+                u"Received user presence data in a room before its initialisation "
+                u"(current state: {state}),"
+                u"this is not standard! Ignoring it: {room} ({nick})".format(
+                    state=room.state,
+                    room=room.roomJID.userhost(),
+                    nick=user.nick))
             return
         else:
             if not room.fully_joined.called:
@@ -1058,8 +1064,10 @@
                 self._changing_nicks.remove(user.nick)
             except KeyError:
                 # this is a new user
-                log.debug(_(u"user {nick} has joined room {room_id}").format(nick=user.nick, room_id=room.occupantJID.userhost()))
-                if not self.host.trigger.point("MUC user joined", room, user, self.client.profile):
+                log.debug(_(u"user {nick} has joined room {room_id}").format(
+                    nick=user.nick, room_id=room.occupantJID.userhost()))
+                if not self.host.trigger.point(
+                        "MUC user joined", room, user, self.client.profile):
                     return
 
                 extra = {'info_type': ROOM_USER_JOINED,