diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-18 01:08:49 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-02-18 01:08:49 +0100 |
commit | 394afaba0b6410c163b459404d36a805c3166d51 (patch) | |
tree | 80d423abc762ec9fad11e4048e21c8031d610322 | |
parent | ef325fba989867bb5d17b0cf4e3ae8cd653ffd1e (diff) | |
download | messenger-gtk-394afaba0b6410c163b459404d36a805c3166d51.tar.gz messenger-gtk-394afaba0b6410c163b459404d36a805c3166d51.zip |
Implemented message deletion
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/chat/messenger.c | 10 | ||||
-rw-r--r-- | src/event.c | 28 | ||||
-rw-r--r-- | src/event.h | 5 | ||||
-rw-r--r-- | src/ui/chat.c | 40 | ||||
-rw-r--r-- | src/ui/chat.h | 2 | ||||
-rw-r--r-- | src/ui/message.c | 3 | ||||
-rw-r--r-- | src/ui/message.h | 1 |
7 files changed, 89 insertions, 0 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index f1ea471..452e476 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -170,6 +170,16 @@ _chat_messenger_message(void *cls, | |||
170 | ); | 170 | ); |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | case GNUNET_CHAT_KIND_DELETION: | ||
174 | { | ||
175 | application_call_message_event( | ||
176 | app, | ||
177 | event_delete_message, | ||
178 | context, | ||
179 | message | ||
180 | ); | ||
181 | break; | ||
182 | } | ||
173 | default: | 183 | default: |
174 | break; | 184 | break; |
175 | } | 185 | } |
diff --git a/src/event.c b/src/event.c index 8133b54..459f910 100644 --- a/src/event.c +++ b/src/event.c | |||
@@ -472,3 +472,31 @@ event_receive_message(MESSENGER_Application *app, | |||
472 | ui_chat_add_message(handle->chat, app, message); | 472 | ui_chat_add_message(handle->chat, app, message); |
473 | ui_chat_entry_update(handle, app, context); | 473 | ui_chat_entry_update(handle, app, context); |
474 | } | 474 | } |
475 | |||
476 | void | ||
477 | event_delete_message(MESSENGER_Application *app, | ||
478 | struct GNUNET_CHAT_Context *context, | ||
479 | const struct GNUNET_CHAT_Message *msg) | ||
480 | { | ||
481 | UI_CHAT_ENTRY_Handle *handle = GNUNET_CHAT_context_get_user_pointer(context); | ||
482 | |||
483 | if ((!handle) || (!(handle->chat))) | ||
484 | return; | ||
485 | |||
486 | GList *messages = handle->chat->messages; | ||
487 | |||
488 | while (messages) | ||
489 | { | ||
490 | UI_MESSAGE_Handle *message = (UI_MESSAGE_Handle*) (messages->data); | ||
491 | |||
492 | if ((message) && (message->msg == GNUNET_CHAT_message_get_target(msg))) | ||
493 | { | ||
494 | ui_chat_remove_message(handle->chat, app, message); | ||
495 | break; | ||
496 | } | ||
497 | |||
498 | messages = messages->next; | ||
499 | } | ||
500 | |||
501 | ui_chat_entry_update(handle, app, context); | ||
502 | } | ||
diff --git a/src/event.h b/src/event.h index 746e9f3..59dd348 100644 --- a/src/event.h +++ b/src/event.h | |||
@@ -58,4 +58,9 @@ event_receive_message(MESSENGER_Application *app, | |||
58 | struct GNUNET_CHAT_Context *context, | 58 | struct GNUNET_CHAT_Context *context, |
59 | const struct GNUNET_CHAT_Message *msg); | 59 | const struct GNUNET_CHAT_Message *msg); |
60 | 60 | ||
61 | void | ||
62 | event_delete_message(MESSENGER_Application *app, | ||
63 | struct GNUNET_CHAT_Context *context, | ||
64 | const struct GNUNET_CHAT_Message *msg); | ||
65 | |||
61 | #endif /* EVENT_H_ */ | 66 | #endif /* EVENT_H_ */ |
diff --git a/src/ui/chat.c b/src/ui/chat.c index 45d361e..72d75b0 100644 --- a/src/ui/chat.c +++ b/src/ui/chat.c | |||
@@ -215,6 +215,37 @@ handle_chat_selection_close_button_click(UNUSED GtkButton *button, | |||
215 | } | 215 | } |
216 | 216 | ||
217 | static void | 217 | static void |
218 | handle_chat_selection_delete_button_click(UNUSED GtkButton *button, | ||
219 | gpointer user_data) | ||
220 | { | ||
221 | UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data; | ||
222 | |||
223 | GList *selected = gtk_list_box_get_selected_rows(handle->messages_listbox); | ||
224 | UI_MESSAGE_Handle *message; | ||
225 | |||
226 | while (selected) | ||
227 | { | ||
228 | GtkListBoxRow *row = GTK_LIST_BOX_ROW(selected->data); | ||
229 | |||
230 | if (!row) | ||
231 | goto skip_row; | ||
232 | |||
233 | message = g_hash_table_lookup(handle->bindings, row); | ||
234 | |||
235 | if ((!message) || (!(message->msg))) | ||
236 | goto skip_row; | ||
237 | |||
238 | GNUNET_CHAT_message_delete( | ||
239 | message->msg, | ||
240 | GNUNET_TIME_relative_get_zero_() | ||
241 | ); | ||
242 | |||
243 | skip_row: | ||
244 | selected = selected->next; | ||
245 | } | ||
246 | } | ||
247 | |||
248 | static void | ||
218 | handle_attach_file_button_click(GtkButton *button, | 249 | handle_attach_file_button_click(GtkButton *button, |
219 | gpointer user_data) | 250 | gpointer user_data) |
220 | { | 251 | { |
@@ -362,6 +393,8 @@ ui_chat_new(MESSENGER_Application *app) | |||
362 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); | 393 | UI_CHAT_Handle *handle = g_malloc(sizeof(UI_CHAT_Handle)); |
363 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); | 394 | UI_MESSENGER_Handle *messenger = &(app->ui.messenger); |
364 | 395 | ||
396 | handle->bindings = app->ui.bindings; | ||
397 | |||
365 | handle->messages = NULL; | 398 | handle->messages = NULL; |
366 | handle->edge_value = 0; | 399 | handle->edge_value = 0; |
367 | 400 | ||
@@ -524,6 +557,13 @@ ui_chat_new(MESSENGER_Application *app) | |||
524 | ); | 557 | ); |
525 | 558 | ||
526 | g_signal_connect( | 559 | g_signal_connect( |
560 | handle->selection_delete_button, | ||
561 | "clicked", | ||
562 | G_CALLBACK(handle_chat_selection_delete_button_click), | ||
563 | handle | ||
564 | ); | ||
565 | |||
566 | g_signal_connect( | ||
527 | handle->messages_listbox, | 567 | handle->messages_listbox, |
528 | "size-allocate", | 568 | "size-allocate", |
529 | G_CALLBACK(handle_chat_messages_listbox_size_allocate), | 569 | G_CALLBACK(handle_chat_messages_listbox_size_allocate), |
diff --git a/src/ui/chat.h b/src/ui/chat.h index 300a9be..b27f829 100644 --- 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; | |||
38 | 38 | ||
39 | typedef struct UI_CHAT_Handle | 39 | typedef struct UI_CHAT_Handle |
40 | { | 40 | { |
41 | GHashTable *bindings; | ||
42 | |||
41 | GList *messages; | 43 | GList *messages; |
42 | gdouble edge_value; | 44 | gdouble edge_value; |
43 | 45 | ||
diff --git a/src/ui/message.c b/src/ui/message.c index 5cbafcc..4dbddf1 100644 --- a/src/ui/message.c +++ b/src/ui/message.c | |||
@@ -249,6 +249,7 @@ ui_message_new(MESSENGER_Application *app, | |||
249 | handle->type = type; | 249 | handle->type = type; |
250 | 250 | ||
251 | handle->timestamp = GNUNET_TIME_absolute_get_zero_(); | 251 | handle->timestamp = GNUNET_TIME_absolute_get_zero_(); |
252 | handle->msg = NULL; | ||
252 | 253 | ||
253 | const char *ui_builder_file; | 254 | const char *ui_builder_file; |
254 | 255 | ||
@@ -403,6 +404,8 @@ ui_message_update(UI_MESSAGE_Handle *handle, | |||
403 | { | 404 | { |
404 | struct GNUNET_CHAT_File *file = NULL; | 405 | struct GNUNET_CHAT_File *file = NULL; |
405 | 406 | ||
407 | handle->msg = msg; | ||
408 | |||
406 | if (msg) | 409 | if (msg) |
407 | { | 410 | { |
408 | file = GNUNET_CHAT_message_get_file(msg); | 411 | file = GNUNET_CHAT_message_get_file(msg); |
diff --git a/src/ui/message.h b/src/ui/message.h index 71387ef..87c7003 100644 --- a/src/ui/message.h +++ b/src/ui/message.h | |||
@@ -46,6 +46,7 @@ typedef struct UI_MESSAGE_Handle | |||
46 | UI_MESSAGE_Type type; | 46 | UI_MESSAGE_Type type; |
47 | 47 | ||
48 | struct GNUNET_TIME_Absolute timestamp; | 48 | struct GNUNET_TIME_Absolute timestamp; |
49 | const struct GNUNET_CHAT_Message *msg; | ||
49 | 50 | ||
50 | GtkBuilder *builder; | 51 | GtkBuilder *builder; |
51 | GtkWidget *message_box; | 52 | GtkWidget *message_box; |