Now About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/chat.py
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-05 23:29:53 +0100
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2024-10-05 23:29:53 +0100
commit6199578ed18101c2245b3f2b28e0e579b6e59833 (patch)
tree1728688d933784a9407b4e0565cfdce59a2ddd37 /src/chat.py
parentddf331a607e6286bccba8eaa55916544c1029a58 (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.
Diffstat (limited to 'src/chat.py')
-rw-r--r--src/chat.py17
1 files changed, 13 insertions, 4 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))