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:
parent
90fcacd4bd
commit
5e43c6c98c
3 changed files with 39 additions and 29 deletions
|
|
@ -94,12 +94,11 @@ class Exp_Parrot(object):
|
|||
lang = e.getAttribute("lang") or ""
|
||||
|
||||
try:
|
||||
entity_type = self.host.memory.getEntityData(from_jid, ["type"], profile)[
|
||||
"type"
|
||||
]
|
||||
entity_type = self.host.memory.getEntityData(
|
||||
from_jid, [C.ENTITY_TYPE], profile)[C.ENTITY_TYPE]
|
||||
except (UnknownEntityError, KeyError):
|
||||
entity_type = "contact"
|
||||
if entity_type == "chatroom":
|
||||
if entity_type == C.ENTITY_TYPE_MUC:
|
||||
src_txt = from_jid.resource
|
||||
if src_txt == self.host.plugins["XEP-0045"].getRoomNick(
|
||||
client, from_jid.userhostJID()
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -257,8 +257,9 @@ class XEP_0085(object):
|
|||
@return: bool
|
||||
"""
|
||||
try:
|
||||
type_ = self.host.memory.getEntityDatum(to_jid.userhostJID(), "type", profile)
|
||||
if type_ == "chatroom": # FIXME: should not use disco instead ?
|
||||
type_ = self.host.memory.getEntityDatum(
|
||||
to_jid.userhostJID(), C.ENTITY_TYPE, profile)
|
||||
if type_ == C.ENTITY_TYPE_MUC:
|
||||
return True
|
||||
except (exceptions.UnknownEntityError, KeyError):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue