changeset 2850:272dc905ff20

quick frontend (chat): new updateOccupants methods which add/remove occupants to be in sync with new list
author Goffi <goffi@goffi.org>
date Sun, 10 Mar 2019 18:03:02 +0100
parents c2858e63cd82
children 7764383a968c
files sat_frontends/quick_frontend/quick_chat.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_chat.py	Sun Mar 10 18:02:58 2019 +0100
+++ b/sat_frontends/quick_frontend/quick_chat.py	Sun Mar 10 18:03:02 2019 +0100
@@ -433,6 +433,28 @@
         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)