From 42c01e8b9f52fc988ce00b13b4c83d13c3d0a62e Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 19 Sep 2025 13:06:14 +0200 Subject: [PATCH] Simplify Channel/Topic update processing. --- ircplom/client_tui.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ircplom/client_tui.py b/ircplom/client_tui.py index 46c4106..74d9058 100644 --- a/ircplom/client_tui.py +++ b/ircplom/client_tui.py @@ -8,7 +8,7 @@ from ircplom.tui_base import (BaseTui, PromptWidget, TuiEvent, Window, from ircplom.client import ( AutoAttrMixin, Channel, Client, ClientQueueMixin, Dict, DictItem, IrcConnSetup, LogScope, NewClientEvent, NickUserHost, ServerCapability, - SharedClientDbFields, User) + SharedClientDbFields, Topic, User) CMD_SHORTCUTS['disconnect'] = 'window.disconnect' CMD_SHORTCUTS['join'] = 'window.join' @@ -216,21 +216,16 @@ class _UpdatingChannel(_UpdatingNode, Channel): def _focused_set_and_report_change( self, old_value: '_UpdatingNode', update: _Update ) -> tuple[tuple[LogScope, Any], ...]: - scope = self._scope(update.key) - if update.key == 'topic': + if update.key == 'user_ids': + assert isinstance(update.value, set) + d = ({'NUHS:joining': tuple(sorted(id_ for id_ in update.value + if id_ not in self.user_ids))} + if self.user_ids + else {'NICKS:residents': tuple(sorted(update.value))}) if super()._focused_set_and_report_change(old_value, update): - return ((scope, - f'RAW:{self.topic.who} set topic: {self.topic.what}'),) + return ((self._scope(update.key), d),) return tuple() - assert update.key == 'user_ids' - assert isinstance(update.value, set) - d = ({'NUHS:joining': tuple(sorted(id_ for id_ in update.value - if id_ not in self.user_ids))} - if self.user_ids - else {'NICKS:residents': tuple(sorted(update.value))}) - if super()._focused_set_and_report_change(old_value, update): - return ((scope, d),) - return tuple() + return super()._focused_set_and_report_change(old_value, update) class _UpdatingUser(_UpdatingNode, User): @@ -361,6 +356,8 @@ class _ClientWindowsManager: log_kwargs |= {'target': update.path[1]} if value is None: 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) -- 2.30.2