quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list

This commit is contained in:
Goffi 2019-03-10 18:03:02 +01:00
commit 060c985aba

View file

@ -433,6 +433,28 @@ class QuickChat(quick_widgets.QuickWidget):
for nick, data in occupants.iteritems():
self.occupants[nick] = Occupant(self, data, self.profile)
def updateOccupants(self, occupants):
"""Update occupants list
In opposition to setOccupants, this only add missing occupants and remove
occupants who have left
"""
# FIXME: occupants with modified status are not handled
local_occupants = set(self.occupants)
updated_occupants = set(occupants)
left_occupants = local_occupants - updated_occupants
joined_occupants = updated_occupants - local_occupants
log.debug(u"updating occupants for {room}:\n"
u"left: {left_occupants}\n"
u"joined: {joined_occupants}"
.format(room=self.target,
left_occupants=u", ".join(left_occupants),
joined_occupants=u", ".join(joined_occupants)))
for nick in left_occupants:
self.removeUser(occupants[nick])
for nick in joined_occupants:
self.addUser(occupants[nick])
def addUser(self, occupant_data):
"""Add user if it is not in the group list"""
occupant = Occupant(self, occupant_data, self.profile)