plugin XEP-0045: avoid sending useless presence signals:

- presence signals were sent twice (from XEP-0045 itself + core), this is now avoided by
  cancelling presence workflow in core when presence if from a joined room.
- filter out cached presences if no status or show information is set (occupants are
  already specified in mucRoomJoined signal)
This commit is contained in:
Goffi 2019-07-07 15:39:53 +02:00
commit eb08ab4927

View file

@ -792,26 +792,8 @@ class XEP_0045(object):
entity_bare = entity.userhostJID()
muc_client = client._muc_client
if entity_bare in muc_client.joined_rooms:
room = muc_client.joined_rooms[entity_bare]
if hasattr(room, "_cache_presence"):
# room has a cache for presence, meaning it has not been fully
# joined yet. So we put presence in cache, and stop workflow.
# Or delete current presence and continue workflow if it's an
# "unavailable" presence
cache = room._cache_presence
if show == C.PRESENCE_UNAVAILABLE:
try:
del cache[entity]
except KeyError:
pass
return True
else:
cache[entity] = {
"entity": entity,
"show": show,
"statuses": statuses,
"priority": priority}
return False
# presence is already handled in (un)availableReceived
return False
return True
@ -1150,7 +1132,23 @@ class SatMUCClient(muc.MUCClient):
self.host.bridge.mucRoomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.client.profile)
def userUpdatedStatus(self, room, user, show, status):
self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {C.PRESENCE_STATUSES_DEFAULT: status or ''}, self.client.profile)
entity = jid.JID(tuple=(room.roomJID.user, room.roomJID.host, user.nick))
if hasattr(room, "_cache_presence"):
# room has a cache for presence, meaning it has not been fully
# joined yet. So we put presence in cache, and stop workflow.
# Or delete current presence and continue workflow if it's an
# "unavailable" presence
cache = room._cache_presence
cache[entity] = {
"room": room,
"user": user,
"show": show,
"status": status,
}
return
statuses = {C.PRESENCE_STATUSES_DEFAULT: status or ''}
self.host.bridge.presenceUpdate(
entity.full(), show or '', 0, statuses, self.client.profile)
## messages ##
@ -1256,8 +1254,13 @@ class SatMUCClient(muc.MUCClient):
del room._cache_presence
for elem in cache:
self.client.xmlstream.dispatch(elem)
for __, presence_data in cache_presence.iteritems():
self.client.presence.availableReceived(**presence_data)
for presence_data in cache_presence.itervalues():
if not presence_data[u'show'] and not presence_data[u'status']:
# occupants are already sent in mucRoomJoined, so if we don't have
# extra information like show or statuses, we can discard the signal
continue
else:
self.userUpdatedStatus(**presence_data)
def _historyEb(self, failure_, room):
log.error(u"Error while managing history: {}".format(failure_))