diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-05 23:29:53 +0100 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-10-05 23:29:53 +0100 |
commit | 6199578ed18101c2245b3f2b28e0e579b6e59833 (patch) | |
tree | 1728688d933784a9407b4e0565cfdce59a2ddd37 | |
parent | ddf331a607e6286bccba8eaa55916544c1029a58 (diff) |
chat: Improve system message handling
Not 100% happy with how system messages are displayed. Need to find a
better system for how to handle them.
-rw-r--r-- | src/chat.py | 17 | ||||
-rw-r--r-- | src/main.py | 3 | ||||
-rw-r--r-- | src/message.py | 8 |
3 files changed, 21 insertions, 7 deletions
diff --git a/src/chat.py b/src/chat.py index 9ac793b..5e52347 100644 --- a/src/chat.py +++ b/src/chat.py @@ -88,8 +88,10 @@ class WeegtkChat(Adw.Bin): def scroll_bottom(self, *args): n_items = self.model.get_n_items() self.auto_scroll = True - self.messages.scroll_to(n_items - 1, Gtk.ListScrollFlags.FOCUS) - self.window.emit("scroll_child", Gtk.ScrollType.END, False) + + if n_items > 0: + self.messages.scroll_to(n_items - 1, Gtk.ListScrollFlags.FOCUS) + self.window.emit("scroll_child", Gtk.ScrollType.END, False) def setup_list_item(self, factory, list_item, *user_data): message = WeegtkMessage() @@ -121,11 +123,18 @@ class WeegtkChat(Adw.Bin): user = self.parse_out_colors(prefix) msg = self.parse_out_colors(text) count = self.model.get_n_items() + msg_type = "message" + + # TODO figure out if there is a way to check if a message is from the + # the system instead of from a user + if len(user) == 0 or user[0] == "=" or user[0] == "-" or user[0] == "[": + user = f"{self.data['short_name']} {user}" + msg_type = "system" if count != 0: last = self.model.get_string(count - 1) last_data = json.loads(last) - if last_data["type"] == "message" and last_data["username"] == user: + if last_data["username"] == user: last_data["text"].append(msg) self.model.splice(count - 1, 1, [json.dumps(last_data)]) return @@ -133,7 +142,7 @@ class WeegtkChat(Adw.Bin): data = { "username": user, "text": [msg], - "type": "message" + "type": msg_type } self.model.append(json.dumps(data)) diff --git a/src/main.py b/src/main.py index 1b45586..5a1427a 100644 --- a/src/main.py +++ b/src/main.py @@ -161,7 +161,6 @@ class WeegtkApplication(Adw.Application): def _parse_line(self, message): """Parse a WeeChat message with a buffer line.""" - # TODO implement text for chats for obj in message.objects: lines = [] if obj.objtype != 'hda' or obj.value['path'][-1] != 'line_data': @@ -182,7 +181,6 @@ class WeegtkApplication(Adw.Application): if message.msgid == 'listlines': lines.reverse() for line in lines: - #print(line) self.buffers[line[0]].display(*line[1]) def _parse_nicklist(self, message): @@ -325,6 +323,7 @@ class WeegtkApplication(Adw.Application): # Only make chats visible on main screen if True or buf.is_chat(): + test_label = Gtk.Label(label="Hello") self.props.active_window.stack.add_titled(buf, name=buf_name, title=buf_name) def buffer_input(self, source_object, full_name, text): diff --git a/src/message.py b/src/message.py index 368ab7d..4e37609 100644 --- a/src/message.py +++ b/src/message.py @@ -57,7 +57,13 @@ class WeegtkMessage(Gtk.Box): else: self.set_visible(True) self.username.set_label(data["username"]) - self.avatar.set_text(data["username"]) + + # Hide avatar for system messages + if data["type"] == "system": + self.avatar.set_visible(False) + else: + self.avatar.set_text(data["username"]) + self.avatar.set_visible(True) first = True for message in data["text"]: |