diff libervia/frontends/quick_frontend/quick_chat.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 26b7ed2817da
children
line wrap: on
line diff
--- a/libervia/frontends/quick_frontend/quick_chat.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/frontends/quick_frontend/quick_chat.py	Wed Jun 19 18:44:57 2024 +0200
@@ -43,8 +43,18 @@
     """Message metadata"""
 
     def __init__(
-            self, parent, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra,
-            profile):
+        self,
+        parent,
+        uid,
+        timestamp,
+        from_jid,
+        to_jid,
+        msg,
+        subject,
+        type_,
+        extra,
+        profile,
+    ):
         self.parent = parent
         self.profile = profile
         self.uid = uid
@@ -77,7 +87,8 @@
             mess_type=self.type,
             time=self.time_text,
             nick=self.nick,
-            message=self.main_message)
+            message=self.main_message,
+        )
 
     def __contains__(self, item):
         return hasattr(self, item) or item in self.extra
@@ -175,7 +186,8 @@
             except (exceptions.NotFound, KeyError):
                 # we check result as listener will be called
                 self.host.bridge.identity_get(
-                    entity.bare, ["nicknames"], True, self.profile)
+                    entity.bare, ["nicknames"], True, self.profile
+                )
                 return entity.node or entity
 
             if nicknames:
@@ -228,6 +240,7 @@
 
 class MessageWidget:
     """Base classe for widgets"""
+
     # This class does nothing and is only used to have a common ancestor
 
     pass
@@ -290,8 +303,17 @@
 class QuickChat(quick_widgets.QuickWidget):
     visible_states = ["chat_state"]  # FIXME: to be removed, used only in quick_games
 
-    def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None,
-                 subject=None, statuses=None, profiles=None):
+    def __init__(
+        self,
+        host,
+        target,
+        type_=C.CHAT_ONE2ONE,
+        nick=None,
+        occupants=None,
+        subject=None,
+        statuses=None,
+        profiles=None,
+    ):
         """
         @param type_: can be C.CHAT_ONE2ONE for single conversation or C.CHAT_GROUP for
                       chat à la IRC
@@ -366,7 +388,9 @@
             if uid not in self.messages:
                 self.message_new(*data)
             else:
-                log.debug("discarding message already in history: {data}, ".format(data=data))
+                log.debug(
+                    "discarding message already in history: {data}, ".format(data=data)
+                )
         del self._cache
         log.debug("{wid} is now unlocked".format(wid=self))
 
@@ -433,13 +457,17 @@
         if self.type == C.CHAT_GROUP:
             self.occupants_clear()
             self.host.bridge.muc_occupants_get(
-                str(self.target), self.profile, callback=self.update_occupants,
-                errback=log.error)
+                str(self.target),
+                self.profile,
+                callback=self.update_occupants,
+                errback=log.error,
+            )
         self.history_print(
             size=C.HISTORY_LIMIT_NONE,
-            filters={'timestamp_start': last_message.timestamp},
+            filters={"timestamp_start": last_message.timestamp},
             callback=self._resync_complete,
-            profile=self.profile)
+            profile=self.profile,
+        )
 
     ## Widget management ##
 
@@ -464,9 +492,7 @@
     def add_target(self, target):
         super(QuickChat, self).add_target(target)
         if target.resource:
-            self.current_target = (
-                target
-            )  # FIXME: tmp, must use resource priority throught contactList instead
+            self.current_target = target  # FIXME: tmp, must use resource priority throught contactList instead
 
     def recreate_args(self, args, kwargs):
         """copy important attribute for a new widget"""
@@ -526,12 +552,15 @@
         updated_occupants = set(occupants)
         left_occupants = local_occupants - updated_occupants
         joined_occupants = updated_occupants - local_occupants
-        log.debug("updating occupants for {room}:\n"
-                  "left: {left_occupants}\n"
-                  "joined: {joined_occupants}"
-                  .format(room=self.target,
-                          left_occupants=", ".join(left_occupants),
-                          joined_occupants=", ".join(joined_occupants)))
+        log.debug(
+            "updating occupants for {room}:\n"
+            "left: {left_occupants}\n"
+            "joined: {joined_occupants}".format(
+                room=self.target,
+                left_occupants=", ".join(left_occupants),
+                joined_occupants=", ".join(joined_occupants),
+            )
+        )
         for nick in left_occupants:
             self.removeUser(occupants[nick])
         for nick in joined_occupants:
@@ -559,10 +588,11 @@
 
     def change_user_nick(self, old_nick, new_nick):
         """Change nick of a user in group list"""
-        log.info("{old} is now known as {new} in room {room_jid}".format(
-            old = old_nick,
-            new = new_nick,
-            room_jid = self.target))
+        log.info(
+            "{old} is now known as {new} in room {room_jid}".format(
+                old=old_nick, new=new_nick, room_jid=self.target
+            )
+        )
 
     ## Messages ##
 
@@ -584,7 +614,9 @@
                 return True
         return False
 
-    def update_history(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile="@NONE@"):
+    def update_history(
+        self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, profile="@NONE@"
+    ):
         """Called when history need to be recreated
 
         Remove all message from history then call history_print
@@ -605,8 +637,9 @@
         """
         self.set_unlocked()
 
-    def history_print(self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, callback=None,
-                     profile="@NONE@"):
+    def history_print(
+        self, size=C.HISTORY_LIMIT_DEFAULT, filters=None, callback=None, profile="@NONE@"
+    ):
         """Print the current history
 
         Note: self.set_unlocked will be called once history is printed
@@ -690,7 +723,7 @@
             str(target),
             size,
             True,
-            {k: str(v) for k,v in filters.items()},
+            {k: str(v) for k, v in filters.items()},
             profile,
             callback=_history_get_cb,
             errback=_history_get_eb,
@@ -712,13 +745,16 @@
         """
         if self.type == C.CHAT_GROUP:
             return
-        self.host.bridge.message_encryption_get(str(self.target.bare), self.profile,
-                                              callback=self.message_encryption_get_cb,
-                                              errback=self.message_encryption_get_eb)
+        self.host.bridge.message_encryption_get(
+            str(self.target.bare),
+            self.profile,
+            callback=self.message_encryption_get_cb,
+            errback=self.message_encryption_get_eb,
+        )
 
-
-    def message_new(self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra,
-                   profile):
+    def message_new(
+        self, uid, timestamp, from_jid, to_jid, msg, subject, type_, extra, profile
+    ):
         if self._locked:
             self._cache[uid] = (
                 uid,
@@ -733,8 +769,12 @@
             )
             return
 
-        if ((not msg and not subject and not extra[C.KEY_ATTACHMENTS]
-             and type_ != C.MESS_TYPE_INFO)):
+        if (
+            not msg
+            and not subject
+            and not extra[C.KEY_ATTACHMENTS]
+            and type_ != C.MESS_TYPE_INFO
+        ):
             log.warning("Received an empty message for uid {}".format(uid))
             return
 
@@ -772,13 +812,19 @@
 
     def message_encryption_started(self, session_data):
         self.encrypted = True
-        log.debug(_("message encryption started with {target} using {encryption}").format(
-            target=self.target, encryption=session_data['name']))
+        log.debug(
+            _("message encryption started with {target} using {encryption}").format(
+                target=self.target, encryption=session_data["name"]
+            )
+        )
 
     def message_encryption_stopped(self, session_data):
         self.encrypted = False
-        log.debug(_("message encryption stopped with {target} (was using {encryption})")
-                 .format(target=self.target, encryption=session_data['name']))
+        log.debug(
+            _("message encryption stopped with {target} (was using {encryption})").format(
+                target=self.target, encryption=session_data["name"]
+            )
+        )
 
     def create_message(self, message, append=False):
         """Must be implemented by frontend to create and show a new message widget