messenger-gtk

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

commit 394afaba0b6410c163b459404d36a805c3166d51
parent ef325fba989867bb5d17b0cf4e3ae8cd653ffd1e
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Fri, 18 Feb 2022 01:08:49 +0100

Implemented message deletion

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

Diffstat:
Msrc/chat/messenger.c | 10++++++++++
Msrc/event.c | 28++++++++++++++++++++++++++++
Msrc/event.h | 5+++++
Msrc/ui/chat.c | 40++++++++++++++++++++++++++++++++++++++++
Msrc/ui/chat.h | 2++
Msrc/ui/message.c | 3+++
Msrc/ui/message.h | 1+
7 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/chat/messenger.c b/src/chat/messenger.c @@ -170,6 +170,16 @@ _chat_messenger_message(void *cls, ); break; } + case GNUNET_CHAT_KIND_DELETION: + { + application_call_message_event( + app, + event_delete_message, + context, + message + ); + break; + } default: break; } diff --git a/src/event.c b/src/event.c @@ -472,3 +472,31 @@ event_receive_message(MESSENGER_Application *app, ui_chat_add_message(handle->chat, app, message); ui_chat_entry_update(handle, app, context); } + +void +event_delete_message(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg) +{ + UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); + + if ((!handle) || (!(handle->chat))) + return; + + GList *messages = handle->chat->messages; + + while (messages) + { + UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) (messages->data); + + if ((message) && (message->msg == GNUNET_CHAT_message_get_target(msg))) + { + ui_chat_remove_message(handle->chat, app, message); + break; + } + + messages = messages->next; + } + + ui_chat_entry_update(handle, app, context); +} diff --git a/src/event.h b/src/event.h @@ -58,4 +58,9 @@ event_receive_message(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg); +void +event_delete_message(MESSENGER_Application *app, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *msg); + #endif /* EVENT_H_ */ diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -215,6 +215,37 @@ handle_chat_selection_close_button_click(UNUSED GtkButton *button, } static void +handle_chat_selection_delete_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; + + GList *selected = gtk_list_box_get_selected_rows(handle->messages_listbox); + UI_MESSAGE_Handle *message; + + while (selected) + { + GtkListBoxRow *row = GTK_LIST_BOX_ROW(selected->data); + + if (!row) + goto skip_row; + + message = g_hash_table_lookup(handle->bindings, row); + + if ((!message) || (!(message->msg))) + goto skip_row; + + GNUNET_CHAT_message_delete( + message->msg, + GNUNET_TIME_relative_get_zero_() + ); + + skip_row: + selected = selected->next; + } +} + +static void handle_attach_file_button_click(GtkButton *button, gpointer user_data) { @@ -362,6 +393,8 @@ ui_chat_new(MESSENGER_Application *app) UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); UI_MESSENGER_Handle *messenger = &(app->ui.messenger); + handle->bindings = app->ui.bindings; + handle->messages = NULL; handle->edge_value = 0; @@ -524,6 +557,13 @@ ui_chat_new(MESSENGER_Application *app) ); g_signal_connect( + handle->selection_delete_button, + "clicked", + G_CALLBACK(handle_chat_selection_delete_button_click), + handle + ); + + g_signal_connect( handle->messages_listbox, "size-allocate", G_CALLBACK(handle_chat_messages_listbox_size_allocate), diff --git a/src/ui/chat.h b/src/ui/chat.h @@ -38,6 +38,8 @@ typedef struct UI_FILE_LOAD_ENTRY_Handle UI_FILE_LOAD_ENTRY_Handle; typedef struct UI_CHAT_Handle { + GHashTable *bindings; + GList *messages; gdouble edge_value; diff --git a/src/ui/message.c b/src/ui/message.c @@ -249,6 +249,7 @@ ui_message_new(MESSENGER_Application *app, handle->type = type; handle->timestamp = GNUNET_TIME_absolute_get_zero_(); + handle->msg = NULL; const char *ui_builder_file; @@ -403,6 +404,8 @@ ui_message_update(UI_MESSAGE_Handle *handle, { struct GNUNET_CHAT_File *file = NULL; + handle->msg = msg; + if (msg) { file = GNUNET_CHAT_message_get_file(msg); diff --git a/src/ui/message.h b/src/ui/message.h @@ -46,6 +46,7 @@ typedef struct UI_MESSAGE_Handle UI_MESSAGE_Type type; struct GNUNET_TIME_Absolute timestamp; + const struct GNUNET_CHAT_Message *msg; GtkBuilder *builder; GtkWidget *message_box;