aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-01-16 15:30:10 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-01-16 15:30:10 +0100
commit03badafe00a8bf4a019dca2ccac8e8937ff59899 (patch)
treeeaa5a8ed7ac884da5a24801112a9c2d14e6262ff
parente4f21c04bc978487afcabb595703e50759a92a10 (diff)
downloadmessenger-gtk-03badafe00a8bf4a019dca2ccac8e8937ff59899.tar.gz
messenger-gtk-03badafe00a8bf4a019dca2ccac8e8937ff59899.zip
Implemeneted sorting of messages to handle old messages reloading
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/chat/messenger.c6
-rw-r--r--src/event.c19
-rw-r--r--src/ui/chat.c50
-rw-r--r--src/ui/message.c6
-rw-r--r--src/ui/message.h2
5 files changed, 76 insertions, 7 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index ea8b450..bea3299 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -28,7 +28,7 @@
28#include "../event.h" 28#include "../event.h"
29 29
30int 30int
31_chat_messenger_iterate_contacts(UNUSED void *cls, 31_chat_messenger_destroy_contacts(UNUSED void *cls,
32 UNUSED struct GNUNET_CHAT_Handle *handle, 32 UNUSED struct GNUNET_CHAT_Handle *handle,
33 struct GNUNET_CHAT_Contact *contact) 33 struct GNUNET_CHAT_Contact *contact)
34{ 34{
@@ -56,7 +56,7 @@ _chat_messenger_idle(void *cls)
56 56
57 GNUNET_CHAT_iterate_contacts( 57 GNUNET_CHAT_iterate_contacts(
58 app->chat.messenger.handle, 58 app->chat.messenger.handle,
59 _chat_messenger_iterate_contacts, 59 _chat_messenger_destroy_contacts,
60 NULL 60 NULL
61 ); 61 );
62 62
diff --git a/src/event.c b/src/event.c
index a12bfef..4b3e580 100644
--- a/src/event.c
+++ b/src/event.c
@@ -84,7 +84,6 @@ _add_new_chat_entry(MESSENGER_Application *app,
84 struct GNUNET_CHAT_Context *context) 84 struct GNUNET_CHAT_Context *context)
85{ 85{
86 UI_MESSENGER_Handle *ui = &(app->ui.messenger); 86 UI_MESSENGER_Handle *ui = &(app->ui.messenger);
87
88 UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); 87 UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app);
89 88
90 ui_chat_entry_update(entry, app, context); 89 ui_chat_entry_update(entry, app, context);
@@ -125,7 +124,15 @@ _iterate_profile_contacts(void *cls,
125 struct GNUNET_CHAT_Contact *contact) 124 struct GNUNET_CHAT_Contact *contact)
126{ 125{
127 MESSENGER_Application *app = (MESSENGER_Application*) cls; 126 MESSENGER_Application *app = (MESSENGER_Application*) cls;
128 _add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact)); 127
128 struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context(
129 contact
130 );
131
132 if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context))
133 return GNUNET_YES;
134
135 _add_new_chat_entry(app, context);
129 return GNUNET_YES; 136 return GNUNET_YES;
130} 137}
131 138
@@ -135,6 +142,14 @@ _iterate_profile_groups(void *cls,
135 UNUSED struct GNUNET_CHAT_Group *group) 142 UNUSED struct GNUNET_CHAT_Group *group)
136{ 143{
137 MESSENGER_Application *app = (MESSENGER_Application*) cls; 144 MESSENGER_Application *app = (MESSENGER_Application*) cls;
145
146 struct GNUNET_CHAT_Context *context = GNUNET_CHAT_group_get_context(
147 group
148 );
149
150 if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context))
151 return GNUNET_YES;
152
138 _add_new_chat_entry(app, GNUNET_CHAT_group_get_context(group)); 153 _add_new_chat_entry(app, GNUNET_CHAT_group_get_context(group));
139 return GNUNET_YES; 154 return GNUNET_YES;
140} 155}
diff --git a/src/ui/chat.c b/src/ui/chat.c
index eefb7cf..e0b284d 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -142,6 +142,35 @@ handle_back_button_click(UNUSED GtkButton *button,
142 } 142 }
143} 143}
144 144
145static gint
146handle_chat_messages_sort(GtkListBoxRow* row0,
147 GtkListBoxRow* row1,
148 gpointer user_data)
149{
150 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
151
152 UI_MESSAGE_Handle *message0 = (UI_MESSAGE_Handle*) (
153 g_hash_table_lookup(app->ui.bindings, row0)
154 );
155
156 UI_MESSAGE_Handle *message1 = (UI_MESSAGE_Handle*) (
157 g_hash_table_lookup(app->ui.bindings, row1)
158 );
159
160 if ((!message0) || (!message1))
161 return 0;
162
163 struct GNUNET_TIME_Absolute timestamp0 = message0->timestamp;
164 struct GNUNET_TIME_Absolute timestamp1 = message1->timestamp;
165
166 if (GNUNET_TIME_absolute_cmp(timestamp0, <, timestamp1))
167 return -1;
168 else if (GNUNET_TIME_absolute_cmp(timestamp0, >, timestamp1))
169 return +1;
170 else
171 return 0;
172}
173
145static void 174static void
146handle_chat_messages_selected_rows_changed(GtkListBox *listbox, 175handle_chat_messages_selected_rows_changed(GtkListBox *listbox,
147 gpointer user_data) 176 gpointer user_data)
@@ -461,6 +490,13 @@ ui_chat_new(MESSENGER_Application *app)
461 gtk_builder_get_object(handle->builder, "messages_listbox") 490 gtk_builder_get_object(handle->builder, "messages_listbox")
462 ); 491 );
463 492
493 gtk_list_box_set_sort_func(
494 handle->messages_listbox,
495 handle_chat_messages_sort,
496 app,
497 NULL
498 );
499
464 g_signal_connect( 500 g_signal_connect(
465 handle->messages_listbox, 501 handle->messages_listbox,
466 "selected-rows-changed", 502 "selected-rows-changed",
@@ -747,7 +783,7 @@ ui_chat_delete(UI_CHAT_Handle *handle)
747 783
748void 784void
749ui_chat_add_message(UI_CHAT_Handle *handle, 785ui_chat_add_message(UI_CHAT_Handle *handle,
750 GNUNET_UNUSED MESSENGER_Application *app, 786 MESSENGER_Application *app,
751 UI_MESSAGE_Handle *message) 787 UI_MESSAGE_Handle *message)
752{ 788{
753 GNUNET_assert((handle) && (message)); 789 GNUNET_assert((handle) && (message));
@@ -757,18 +793,28 @@ ui_chat_add_message(UI_CHAT_Handle *handle,
757 message->message_box 793 message->message_box
758 ); 794 );
759 795
796 GtkWidget *row = gtk_widget_get_parent(message->message_box);
797
798 g_hash_table_insert(app->ui.bindings, row, message);
799
760 handle->messages = g_list_prepend(handle->messages, message); 800 handle->messages = g_list_prepend(handle->messages, message);
801
802 gtk_list_box_invalidate_sort(handle->messages_listbox);
761} 803}
762 804
763void 805void
764ui_chat_remove_message(UI_CHAT_Handle *handle, 806ui_chat_remove_message(UI_CHAT_Handle *handle,
765 GNUNET_UNUSED MESSENGER_Application *app, 807 MESSENGER_Application *app,
766 UI_MESSAGE_Handle *message) 808 UI_MESSAGE_Handle *message)
767{ 809{
768 GNUNET_assert((handle) && (message)); 810 GNUNET_assert((handle) && (message));
769 811
770 handle->messages = g_list_remove(handle->messages, message); 812 handle->messages = g_list_remove(handle->messages, message);
771 813
814 GtkWidget *row = gtk_widget_get_parent(message->message_box);
815
816 g_hash_table_remove(app->ui.bindings, row);
817
772 gtk_container_remove( 818 gtk_container_remove(
773 GTK_CONTAINER(handle->messages_listbox), 819 GTK_CONTAINER(handle->messages_listbox),
774 gtk_widget_get_parent(GTK_WIDGET(message->message_box)) 820 gtk_widget_get_parent(GTK_WIDGET(message->message_box))
diff --git a/src/ui/message.c b/src/ui/message.c
index 9c93502..5cbafcc 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -248,6 +248,8 @@ ui_message_new(MESSENGER_Application *app,
248 248
249 handle->type = type; 249 handle->type = type;
250 250
251 handle->timestamp = GNUNET_TIME_absolute_get_zero_();
252
251 const char *ui_builder_file; 253 const char *ui_builder_file;
252 254
253 switch (handle->type) 255 switch (handle->type)
@@ -402,7 +404,11 @@ ui_message_update(UI_MESSAGE_Handle *handle,
402 struct GNUNET_CHAT_File *file = NULL; 404 struct GNUNET_CHAT_File *file = NULL;
403 405
404 if (msg) 406 if (msg)
407 {
405 file = GNUNET_CHAT_message_get_file(msg); 408 file = GNUNET_CHAT_message_get_file(msg);
409
410 handle->timestamp = GNUNET_CHAT_message_get_timestamp(msg);
411 }
406 else 412 else
407 file = g_hash_table_lookup(app->ui.bindings, handle->message_box); 413 file = g_hash_table_lookup(app->ui.bindings, handle->message_box);
408 414
diff --git a/src/ui/message.h b/src/ui/message.h
index b3b7353..71387ef 100644
--- a/src/ui/message.h
+++ b/src/ui/message.h
@@ -45,6 +45,8 @@ typedef struct UI_MESSAGE_Handle
45{ 45{
46 UI_MESSAGE_Type type; 46 UI_MESSAGE_Type type;
47 47
48 struct GNUNET_TIME_Absolute timestamp;
49
48 GtkBuilder *builder; 50 GtkBuilder *builder;
49 GtkWidget *message_box; 51 GtkWidget *message_box;
50 52