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
This commit is contained in:
Goffi 2019-07-09 09:06:45 +02:00
commit 5e43c6c98c

View file

@ -58,7 +58,6 @@ AFFILIATIONS = ('owner', 'admin', 'member', 'none', 'outcast')
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 @@ class SatMUCClient(muc.MUCClient):
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 @@ class SatMUCClient(muc.MUCClient):
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,