aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-22 19:54:14 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-22 19:54:14 +0100
commit963ca5e24a56e17be1ba1bbff2a498c7837edb55 (patch)
treeab1040cf33fa5fedb30db4e6c47f1c25cf8a5125
parent62090cdc581f6b7c52997f124c791912b91977f5 (diff)
downloadmessenger-gtk-963ca5e24a56e17be1ba1bbff2a498c7837edb55.tar.gz
messenger-gtk-963ca5e24a56e17be1ba1bbff2a498c7837edb55.zip
Adjusted chat update to be applied by each new message
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/event.c32
-rw-r--r--src/ui/chat.c14
-rw-r--r--src/ui/chat_entry.c55
-rw-r--r--src/ui/message.c2
-rw-r--r--src/ui/message.h2
5 files changed, 83 insertions, 22 deletions
diff --git a/src/event.c b/src/event.c
index 9bbc064..5d6d72d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -235,13 +235,13 @@ event_joining_contact(MESSENGER_Application *app,
235 if (!handle) 235 if (!handle)
236 return; 236 return;
237 237
238 ui_chat_entry_update(handle, app, context);
239
240 UI_MESSAGE_Handle *message = ui_message_new( 238 UI_MESSAGE_Handle *message = ui_message_new(
241 UI_MESSAGE_STATUS, 239 UI_MESSAGE_STATUS,
242 UI_MESSAGE_CONTENT_TEXT 240 UI_MESSAGE_CONTENT_TEXT
243 ); 241 );
244 242
243 ui_message_update(message, msg);
244
245 struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( 245 struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
246 msg 246 msg
247 ); 247 );
@@ -270,7 +270,8 @@ event_joining_contact(MESSENGER_Application *app,
270 message->message_box 270 message->message_box
271 ); 271 );
272 272
273 handle->chat->messages = g_list_append(handle->chat->messages, message); 273 handle->chat->messages = g_list_prepend(handle->chat->messages, message);
274 ui_chat_entry_update(handle, app, context);
274} 275}
275 276
276void 277void
@@ -325,6 +326,8 @@ event_invitation(UNUSED MESSENGER_Application *app,
325 UI_MESSAGE_CONTENT_TEXT 326 UI_MESSAGE_CONTENT_TEXT
326 ); 327 );
327 328
329 ui_message_update(message, msg);
330
328 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( 331 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
329 msg 332 msg
330 ); 333 );
@@ -360,7 +363,8 @@ event_invitation(UNUSED MESSENGER_Application *app,
360 message->message_box 363 message->message_box
361 ); 364 );
362 365
363 handle->chat->messages = g_list_append(handle->chat->messages, message); 366 handle->chat->messages = g_list_prepend(handle->chat->messages, message);
367 ui_chat_entry_update(handle, app, context);
364} 368}
365 369
366void 370void
@@ -382,6 +386,8 @@ event_receive_message(UNUSED MESSENGER_Application *app,
382 file? UI_MESSAGE_CONTENT_FILE : UI_MESSAGE_CONTENT_TEXT 386 file? UI_MESSAGE_CONTENT_FILE : UI_MESSAGE_CONTENT_TEXT
383 ); 387 );
384 388
389 ui_message_update(message, msg);
390
385 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( 391 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
386 msg 392 msg
387 ); 393 );
@@ -393,8 +399,8 @@ event_receive_message(UNUSED MESSENGER_Application *app,
393 msg 399 msg
394 ); 400 );
395 401
396 const char *text = GNUNET_CHAT_message_get_text(msg); 402 const gchar *text = GNUNET_CHAT_message_get_text(msg);
397 const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); 403 const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp);
398 404
399 if ((!ui_messenger_is_context_active(&(app->ui.messenger), context)) && 405 if ((!ui_messenger_is_context_active(&(app->ui.messenger), context)) &&
400 (GNUNET_YES != sent)) 406 (GNUNET_YES != sent))
@@ -409,21 +415,11 @@ event_receive_message(UNUSED MESSENGER_Application *app,
409 gtk_label_set_text(message->text_label, text? text : ""); 415 gtk_label_set_text(message->text_label, text? text : "");
410 gtk_label_set_text(message->timestamp_label, time? time : ""); 416 gtk_label_set_text(message->timestamp_label, time? time : "");
411 417
412 if (message->read_receipt_image)
413 // TODO: check read receipt
414
415 gtk_container_add( 418 gtk_container_add(
416 GTK_CONTAINER(handle->chat->messages_listbox), 419 GTK_CONTAINER(handle->chat->messages_listbox),
417 message->message_box 420 message->message_box
418 ); 421 );
419 422
420 handle->chat->messages = g_list_append(handle->chat->messages, message); 423 handle->chat->messages = g_list_prepend(handle->chat->messages, message);
421 424 ui_chat_entry_update(handle, app, context);
422 gtk_label_set_text(handle->text_label, text? text : "");
423 gtk_label_set_text(handle->timestamp_label, time? time : "");
424
425 gtk_widget_set_visible(
426 GTK_WIDGET(handle->read_receipt_image),
427 GNUNET_YES == sent
428 );
429} 425}
diff --git a/src/ui/chat.c b/src/ui/chat.c
index 5dd11f6..3831f66 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -514,7 +514,9 @@ ui_chat_update(UI_CHAT_Handle *handle,
514 GString *subtitle = g_string_new(""); 514 GString *subtitle = g_string_new("");
515 515
516 if (contact) 516 if (contact)
517 {
517 title = GNUNET_CHAT_contact_get_name(contact); 518 title = GNUNET_CHAT_contact_get_name(contact);
519 }
518 else if (group) 520 else if (group)
519 { 521 {
520 title = GNUNET_CHAT_group_get_name(group); 522 title = GNUNET_CHAT_group_get_name(group);
@@ -581,6 +583,18 @@ ui_chat_update(UI_CHAT_Handle *handle,
581 gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), activated); 583 gtk_widget_set_sensitive(GTK_WIDGET(handle->attach_file_button), activated);
582 gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated); 584 gtk_widget_set_sensitive(GTK_WIDGET(handle->emoji_button), activated);
583 gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated); 585 gtk_widget_set_sensitive(GTK_WIDGET(handle->send_record_button), activated);
586
587 if (!handle->messages)
588 return;
589
590 UI_MESSAGE_Handle *message = (
591 (UI_MESSAGE_Handle*) handle->messages->data
592 );
593
594 const gchar *time = gtk_label_get_text(message->timestamp_label);
595
596 if (!group)
597 gtk_label_set_text(handle->chat_subtitle, time);
584} 598}
585 599
586void 600void
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c
index a3c7892..7de4064 100644
--- a/src/ui/chat_entry.c
+++ b/src/ui/chat_entry.c
@@ -27,6 +27,8 @@
27#include "../application.h" 27#include "../application.h"
28#include "../contact.h" 28#include "../contact.h"
29 29
30#include "message.h"
31
30UI_CHAT_ENTRY_Handle* 32UI_CHAT_ENTRY_Handle*
31ui_chat_entry_new(MESSENGER_Application *app) 33ui_chat_entry_new(MESSENGER_Application *app)
32{ 34{
@@ -62,6 +64,16 @@ ui_chat_entry_new(MESSENGER_Application *app)
62 return handle; 64 return handle;
63} 65}
64 66
67/*static int
68_iterate_message_read_receipt(UNUSED void *cls,
69 UNUSED const struct GNUNET_CHAT_Message *message,
70 const struct GNUNET_CHAT_Contact *contact,
71 int read_receipt)
72{
73 printf("read_receipt: %s %d\n", GNUNET_CHAT_contact_get_name(contact), read_receipt);
74 return GNUNET_YES;
75}*/
76
65void 77void
66ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, 78ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
67 MESSENGER_Application *app, 79 MESSENGER_Application *app,
@@ -86,8 +98,47 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
86 hdy_avatar_set_text(handle->entry_avatar, title); 98 hdy_avatar_set_text(handle->entry_avatar, title);
87 } 99 }
88 100
89 if (handle->chat) 101 if (!handle->chat)
90 ui_chat_update(handle->chat, app, context); 102 return;
103
104 ui_chat_update(handle->chat, app, context);
105
106 if (!handle->chat->messages)
107 return;
108
109 UI_MESSAGE_Handle *message = (
110 (UI_MESSAGE_Handle*) handle->chat->messages->data
111 );
112
113 const gchar *text = gtk_label_get_text(message->text_label);
114 const gchar *time = gtk_label_get_text(message->timestamp_label);
115
116 if (group)
117 {
118 GString *message_text = g_string_new(
119 gtk_label_get_text(message->sender_label)
120 );
121
122 g_string_append_printf(
123 message_text,
124 _(": %s"),
125 text
126 );
127
128 gtk_label_set_text(handle->text_label, message_text->str);
129 g_string_free(message_text, TRUE);
130 }
131 else
132 gtk_label_set_text(handle->text_label, text);
133
134 gtk_label_set_text(handle->timestamp_label, time);
135
136 gtk_widget_set_visible(
137 GTK_WIDGET(handle->read_receipt_image),
138 message->read_receipt_image? gtk_widget_is_visible(
139 GTK_WIDGET(message->read_receipt_image)
140 ) : FALSE
141 );
91} 142}
92 143
93void 144void
diff --git a/src/ui/message.c b/src/ui/message.c
index cd8be30..47ec2aa 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -167,7 +167,7 @@ ui_message_new(UI_MESSAGE_Type type,
167 167
168void 168void
169ui_message_update(UI_MESSAGE_Handle *handle, 169ui_message_update(UI_MESSAGE_Handle *handle,
170 struct GNUNET_CHAT_Message *msg) 170 const struct GNUNET_CHAT_Message *msg)
171{ 171{
172 struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg); 172 struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg);
173 173
diff --git a/src/ui/message.h b/src/ui/message.h
index 704c33f..27577a9 100644
--- a/src/ui/message.h
+++ b/src/ui/message.h
@@ -80,7 +80,7 @@ ui_message_new(UI_MESSAGE_Type type,
80 80
81void 81void
82ui_message_update(UI_MESSAGE_Handle *handle, 82ui_message_update(UI_MESSAGE_Handle *handle,
83 struct GNUNET_CHAT_Message *message); 83 const struct GNUNET_CHAT_Message *message);
84 84
85void 85void
86ui_message_delete(UI_MESSAGE_Handle *handle); 86ui_message_delete(UI_MESSAGE_Handle *handle);