home · contact · privacy
Fuse handling of transform-prefixed update messages.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 19 Sep 2025 14:57:46 +0000 (16:57 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 19 Sep 2025 14:57:46 +0000 (16:57 +0200)
ircplom/client_tui.py

index 9bddf1eaaaf012d9842495cfc6de42b92f28c0d6..5e10d97746a153f9e179c406c3dd1b9fce5dbeb8 100644 (file)
@@ -218,13 +218,18 @@ class _UpdatingChannel(_UpdatingNode, Channel):
     def recursive_set_and_report_change(self, update: _Update) -> None:
         super().recursive_set_and_report_change(update)
         if update.key == 'user_ids':
-            if update.old_value:
-                d = {'NUHS:joining': tuple(sorted(
-                        id_ for id_ in update.value
-                        if id_ not in update.old_value))}
+            update.results.clear()
+            scope = self._scope(update.key)
+            if not update.old_value:
+                nicks = []
+                for id_ in sorted(update.value):
+                    nicks += [f'NICK:{id_}', ':, ']
+                nicks.pop()
+                update.results += [(scope, [':residents: '] + nicks)]
             else:
-                d = {'NICKS:residents': tuple(sorted(update.value))}
-            update.results = [(self._scope(update.key), d)]
+                for id_ in (id_ for id_ in update.value
+                            if id_ not in update.old_value):
+                    update.results += [(scope, [':joining: ', f'NUH:{id_}'])]
 
 
 class _UpdatingUser(_UpdatingNode, User):
@@ -234,21 +239,20 @@ class _UpdatingUser(_UpdatingNode, User):
     def recursive_set_and_report_change(self, update: _Update) -> None:
         super().recursive_set_and_report_change(update)
         if update.key in {'nick', 'exit_msg'}:
-            msg = 'RAW:'
             if update.key == 'nick':
                 self.prev_nick = update.old_value
                 if update.old_value != '?':
                     update.results += [
                         (LogScope.USER,
-                         msg + f'{self.prev} renames {update.value}')]
+                         [f':{self.prev} renames {update.value}'])]
             elif update.key == 'exit_msg':
                 update.results.clear()
                 if update.value:
-                    msg += f'{self} '
+                    msg = f':{self} '
                     msg += 'quits' if update.value[0] == 'Q' else 'parts'
                     if len(update.value) > 1:
                         msg += ': ' + update.value[1:]
-                    update.results += [(self._scope(update.key), msg)]
+                    update.results += [(self._scope(update.key), [msg])]
 
     @property
     def prev(self) -> str:
@@ -348,19 +352,15 @@ class _ClientWindowsManager:
                 self.log(f'{log_path} cleared', **log_kwargs)
             elif isinstance(value, Topic):
                 self.log(f'{value.who} set topic: {value.what}', **log_kwargs)
-            elif isinstance(value, dict):
-                for verb, item in [(k, v) for k, v in value.items() if v]:
-                    toks = verb.split(':', maxsplit=1)
-                    verb = toks[-1]
-                    transform = toks[0] if len(toks) > 1 else ''
-                    if transform in {'NICKS', 'NUHS'}:
-                        nuhs = (self.db.users[id_] for id_ in item)
-                        item = ', '.join([
-                            (str(nuh) if transform == 'NUHS' else nuh.nick)
-                            for nuh in nuhs])
-                    self.log(f'{verb}: {item}', **log_kwargs)
-            elif isinstance(value, str) and value.startswith('RAW:'):
-                self.log(value.split(':', maxsplit=1)[1], **log_kwargs)
+            elif isinstance(value, list):
+                msg = ''
+                for item in value:
+                    transform, content = item.split(':', maxsplit=1)
+                    if transform in {'NICK', 'NUH'}:
+                        nuh = self.db.users[content]
+                        content = str(nuh) if transform == 'NUH' else nuh.nick
+                    msg += content
+                self.log(msg, **log_kwargs)
             else:
                 announcement = f'{log_path} set to:'
                 if isinstance(value, tuple):