Now About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2025-01-15 21:14:35 +0000
committerLucas Fryzek <lucas.fryzek@fryzekconcepts.com>2025-01-15 21:14:35 +0000
commita34196f2fa184755e0dc336341b8ed92e5d0a398 (patch)
tree026566161dee7ff20c0d10c6c74f8d33f64e7fa3
parent1310a03148eac23db565ca0c6bbd5ae490024637 (diff)
chat: Improve rendering of messages
Reduces the slowdown from receiving lots of messages at once. TODO look to see if adding messages can be done without freezing the UI.
-rw-r--r--src/chat.py8
-rw-r--r--src/gtk/message.ui1
-rw-r--r--src/main.py2
-rw-r--r--src/message.py10
4 files changed, 16 insertions, 5 deletions
diff --git a/src/chat.py b/src/chat.py
index b659395..3ee0438 100644
--- a/src/chat.py
+++ b/src/chat.py
@@ -166,9 +166,7 @@ class WeegtkChat(Adw.Bin):
last = self.model.get_string(count - 1)
last_data = json.loads(last)
if last_data["username"] == user:
- last_data["text"].append(msg)
- self.model.splice(count - 1, 1, [json.dumps(last_data)])
- return
+ msg_type = "message_append"
data = {
"username": user,
@@ -177,6 +175,10 @@ class WeegtkChat(Adw.Bin):
}
self.model.append(json.dumps(data))
+ def clear(self):
+ # TODO clear chat buffer
+ pass
+
@Gtk.Template.Callback()
def entry_activate(self, *args):
entry_buffer = self.text_entry.get_buffer()
diff --git a/src/gtk/message.ui b/src/gtk/message.ui
index 9619342..66d1769 100644
--- a/src/gtk/message.ui
+++ b/src/gtk/message.ui
@@ -21,6 +21,7 @@
<object class="GtkBox" id="MessageText">
<property name="orientation">vertical</property>
<property name="halign">start</property>
+ <property name="valign">center</property>
<child>
<object class="GtkLabel" id="username">
<property name="label" translatable="true">Username</property>
diff --git a/src/main.py b/src/main.py
index a120031..ea387eb 100644
--- a/src/main.py
+++ b/src/main.py
@@ -320,7 +320,7 @@ class WeegtkApplication(Adw.Application):
self.buffers[index].data['title'] = item['title']
##self.pages[index].set_title(item['title'])
elif message.msgid == '_buffer_cleared':
- self.buffers[index].widget.chat.clear()
+ self.buffers[index].clear()
elif message.msgid.startswith('_buffer_localvar_'):
self.buffers[index].data['local_variables'] = \
item['local_variables']
diff --git a/src/message.py b/src/message.py
index 7a14483..db50829 100644
--- a/src/message.py
+++ b/src/message.py
@@ -65,14 +65,22 @@ class WeegtkMessage(Gtk.Box):
else:
self.avatar.set_text(data["username"])
+ if data["type"] == "message_append":
+ self.avatar.set_visible(False)
+ self.username.set_visible(False)
+
first = True
+ padding_size = self.avatar.get_size() + self.avatar.get_margin_start() + self.avatar.get_margin_end()
+ # TODO messages no longer should be a list, and there should only be one message per entry
+ # Remove this for loop and make sure chat only sets message contents as a single string
for message in data["text"]:
margin = 5 if not first else 0
first = False
markuped = self.parse_message(message)
msg = Gtk.Label(label=markuped, selectable=True,
wrap=True, wrap_mode=Pango.WrapMode.WORD_CHAR, xalign=0,
- margin_top=margin, use_markup=True)
+ margin_top=margin, use_markup=True,
+ margin_start= padding_size if data["type"] == "message_append" else 0)
self.message_list.append(msg)