messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

commit 03badafe00a8bf4a019dca2ccac8e8937ff59899
parent e4f21c04bc978487afcabb595703e50759a92a10
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun, 16 Jan 2022 15:30:10 +0100

Implemeneted sorting of messages to handle old messages reloading

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/chat/messenger.c | 6+++---
Msrc/event.c | 19+++++++++++++++++--
Msrc/ui/chat.c | 50++++++++++++++++++++++++++++++++++++++++++++++++--
Msrc/ui/message.c | 6++++++
Msrc/ui/message.h | 2++
5 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/src/chat/messenger.c b/src/chat/messenger.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -28,7 +28,7 @@ #include "../event.h" int -_chat_messenger_iterate_contacts(UNUSED void *cls, +_chat_messenger_destroy_contacts(UNUSED void *cls, UNUSED struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_Contact *contact) { @@ -56,7 +56,7 @@ _chat_messenger_idle(void *cls) GNUNET_CHAT_iterate_contacts( app->chat.messenger.handle, - _chat_messenger_iterate_contacts, + _chat_messenger_destroy_contacts, NULL ); diff --git a/src/event.c b/src/event.c @@ -84,7 +84,6 @@ _add_new_chat_entry(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context) { UI_MESSENGER_Handle *ui = &(app->ui.messenger); - UI_CHAT_ENTRY_Handle *entry = ui_chat_entry_new(app); ui_chat_entry_update(entry, app, context); @@ -125,7 +124,15 @@ _iterate_profile_contacts(void *cls, struct GNUNET_CHAT_Contact *contact) { MESSENGER_Application *app = (MESSENGER_Application*) cls; - _add_new_chat_entry(app, GNUNET_CHAT_contact_get_context(contact)); + + struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context( + contact + ); + + if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context)) + return GNUNET_YES; + + _add_new_chat_entry(app, context); return GNUNET_YES; } @@ -135,6 +142,14 @@ _iterate_profile_groups(void *cls, UNUSED struct GNUNET_CHAT_Group *group) { MESSENGER_Application *app = (MESSENGER_Application*) cls; + + struct GNUNET_CHAT_Context *context = GNUNET_CHAT_group_get_context( + group + ); + + if (GNUNET_SYSERR == GNUNET_CHAT_context_get_status(context)) + return GNUNET_YES; + _add_new_chat_entry(app, GNUNET_CHAT_group_get_context(group)); return GNUNET_YES; } diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -142,6 +142,35 @@ handle_back_button_click(UNUSED GtkButton *button, } } +static gint +handle_chat_messages_sort(GtkListBoxRow* row0, + GtkListBoxRow* row1, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + UI_MESSAGE_Handle *message0 = (UI_MESSAGE_Handle*) ( + g_hash_table_lookup(app->ui.bindings, row0) + ); + + UI_MESSAGE_Handle *message1 = (UI_MESSAGE_Handle*) ( + g_hash_table_lookup(app->ui.bindings, row1) + ); + + if ((!message0) || (!message1)) + return 0; + + struct GNUNET_TIME_Absolute timestamp0 = message0->timestamp; + struct GNUNET_TIME_Absolute timestamp1 = message1->timestamp; + + if (GNUNET_TIME_absolute_cmp(timestamp0, <, timestamp1)) + return -1; + else if (GNUNET_TIME_absolute_cmp(timestamp0, >, timestamp1)) + return +1; + else + return 0; +} + static void handle_chat_messages_selected_rows_changed(GtkListBox *listbox, gpointer user_data) @@ -461,6 +490,13 @@ ui_chat_new(MESSENGER_Application *app) gtk_builder_get_object(handle->builder, "messages_listbox") ); + gtk_list_box_set_sort_func( + handle->messages_listbox, + handle_chat_messages_sort, + app, + NULL + ); + g_signal_connect( handle->messages_listbox, "selected-rows-changed", @@ -747,7 +783,7 @@ ui_chat_delete(UI_CHAT_Handle *handle) void ui_chat_add_message(UI_CHAT_Handle *handle, - GNUNET_UNUSED MESSENGER_Application *app, + MESSENGER_Application *app, UI_MESSAGE_Handle *message) { GNUNET_assert((handle) && (message)); @@ -757,18 +793,28 @@ ui_chat_add_message(UI_CHAT_Handle *handle, message->message_box ); + GtkWidget *row = gtk_widget_get_parent(message->message_box); + + g_hash_table_insert(app->ui.bindings, row, message); + handle->messages = g_list_prepend(handle->messages, message); + + gtk_list_box_invalidate_sort(handle->messages_listbox); } void ui_chat_remove_message(UI_CHAT_Handle *handle, - GNUNET_UNUSED MESSENGER_Application *app, + MESSENGER_Application *app, UI_MESSAGE_Handle *message) { GNUNET_assert((handle) && (message)); handle->messages = g_list_remove(handle->messages, message); + GtkWidget *row = gtk_widget_get_parent(message->message_box); + + g_hash_table_remove(app->ui.bindings, row); + gtk_container_remove( GTK_CONTAINER(handle->messages_listbox), gtk_widget_get_parent(GTK_WIDGET(message->message_box)) diff --git a/src/ui/message.c b/src/ui/message.c @@ -248,6 +248,8 @@ ui_message_new(MESSENGER_Application *app, handle->type = type; + handle->timestamp = GNUNET_TIME_absolute_get_zero_(); + const char *ui_builder_file; switch (handle->type) @@ -402,7 +404,11 @@ ui_message_update(UI_MESSAGE_Handle *handle, struct GNUNET_CHAT_File *file = NULL; if (msg) + { file = GNUNET_CHAT_message_get_file(msg); + + handle->timestamp = GNUNET_CHAT_message_get_timestamp(msg); + } else file = g_hash_table_lookup(app->ui.bindings, handle->message_box); diff --git a/src/ui/message.h b/src/ui/message.h @@ -45,6 +45,8 @@ typedef struct UI_MESSAGE_Handle { UI_MESSAGE_Type type; + struct GNUNET_TIME_Absolute timestamp; + GtkBuilder *builder; GtkWidget *message_box;