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
6 changed files with 39 additions and 29 deletions
|
|
@ -94,7 +94,8 @@ class Const(object):
|
|||
ENTITY_ALL_RESOURCES = "@ALL_RESOURCES@"
|
||||
ENTITY_MAIN_RESOURCE = "@MAIN_RESOURCE@"
|
||||
ENTITY_CAP_HASH = "CAP_HASH"
|
||||
ENTITY_TYPE = "TYPE"
|
||||
ENTITY_TYPE = "type"
|
||||
ENTITY_TYPE_MUC = "MUC"
|
||||
|
||||
## Roster jids selection ##
|
||||
PUBLIC = "PUBLIC"
|
||||
|
|
|
|||
|
|
@ -566,14 +566,14 @@ class SatXMPPEntity(object):
|
|||
# the type is not 'groupchat'
|
||||
# we may have a groupchat message, we check if the we know this jid
|
||||
try:
|
||||
entity_type = self.host_app.memory.getEntityData(
|
||||
data["to"], ["type"], self.profile
|
||||
)["type"]
|
||||
entity_type = self.host_app.memory.getEntityDatum(
|
||||
data["to"], C.ENTITY_TYPE, self.profile
|
||||
)
|
||||
# FIXME: should entity_type manage resources ?
|
||||
except (exceptions.UnknownEntityError, KeyError):
|
||||
entity_type = "contact"
|
||||
|
||||
if entity_type == "chatroom":
|
||||
if entity_type == C.ENTITY_TYPE_MUC:
|
||||
data["type"] = C.MESS_TYPE_GROUPCHAT
|
||||
else:
|
||||
data["type"] = C.MESS_TYPE_CHAT
|
||||
|
|
|
|||
|
|
@ -849,11 +849,12 @@ class Memory(object):
|
|||
"""Set a misc data for an entity
|
||||
|
||||
If key was registered with setSignalOnUpdate, a signal will be sent to frontends
|
||||
@param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities,
|
||||
C.ENTITY_ALL for all entities (all resources + bare jids)
|
||||
@param key: key to set (eg: "type")
|
||||
@param value: value for this key (eg: "chatroom")
|
||||
@param silent(bool): if True, doesn't send signal to frontend, even if there is a signal flag (see setSignalOnUpdate)
|
||||
@param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of
|
||||
all entities, C.ENTITY_ALL for all entities (all resources + bare jids)
|
||||
@param key: key to set (eg: C.ENTITY_TYPE)
|
||||
@param value: value for this key (eg: C.ENTITY_TYPE_MUC)
|
||||
@param silent(bool): if True, doesn't send signal to frontend, even if there is a
|
||||
signal flag (see setSignalOnUpdate)
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
client = self.host.getClient(profile_key)
|
||||
|
|
@ -886,7 +887,7 @@ class Memory(object):
|
|||
|
||||
@param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities,
|
||||
C.ENTITY_ALL for all entities (all resources + bare jids)
|
||||
@param key: key to delete (eg: "type")
|
||||
@param key: key to delete (eg: C.ENTITY_TYPE)
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
|
||||
@raise exceptions.UnknownEntityError: if entity is not in cache
|
||||
|
|
|
|||
|
|
@ -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