diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2024-02-17 21:24:05 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2024-02-17 21:24:05 +0100 |
commit | a8d1cd08bb4db528093a6bc4d64cb2ea34bf96c8 (patch) | |
tree | 49c96be1a459efd07414c6ba0515d1f653ed1817 | |
parent | 8b95c672e8d9aabab53f09d41eaeed9521ce4b57 (diff) |
Implement messages switching visibility depending on the senders block-state
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/chat/messenger.c | 29 | ||||
-rw-r--r-- | src/contact.c | 42 | ||||
-rw-r--r-- | src/contact.h | 23 | ||||
-rw-r--r-- | src/event.c | 10 | ||||
-rw-r--r-- | src/ui/message.c | 2 |
5 files changed, 96 insertions, 10 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 4f242af..3107277 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c @@ -79,6 +79,18 @@ _chat_messenger_message(void *cls, // Locking the mutex for synchronization pthread_mutex_lock(&(app->chat.mutex)); + if (GNUNET_YES == GNUNET_CHAT_message_is_deleted(message)) + { + application_call_message_event( + app, + event_delete_message, + context, + message + ); + + goto skip_message_handling; + } + // Handle each kind of message as proper event regarding context switch (GNUNET_CHAT_message_get_kind(message)) { @@ -162,12 +174,16 @@ _chat_messenger_message(void *cls, } case GNUNET_CHAT_KIND_DELETION: { - application_call_message_event( - app, - event_delete_message, - context, - message - ); + const struct GNUNET_CHAT_Message *target; + target = GNUNET_CHAT_message_get_target(message); + + if (target) + application_call_message_event( + app, + event_delete_message, + context, + target + ); break; } case GNUNET_CHAT_KIND_TAG: @@ -184,6 +200,7 @@ _chat_messenger_message(void *cls, break; } +skip_message_handling: pthread_mutex_unlock(&(app->chat.mutex)); return GNUNET_YES; } diff --git a/src/contact.c b/src/contact.c index 2e9ff21..c00df4e 100644 --- a/src/contact.c +++ b/src/contact.c @@ -38,6 +38,7 @@ contact_create_info(struct GNUNET_CHAT_Contact *contact) info->name_labels = NULL; info->name_avatars = NULL; + info->visible_widgets = NULL; GNUNET_CHAT_contact_set_user_pointer(contact, info); } @@ -58,6 +59,9 @@ contact_destroy_info(struct GNUNET_CHAT_Contact *contact) if (info->name_avatars) g_list_free(info->name_avatars); + if (info->visible_widgets) + g_list_free(info->visible_widgets); + g_free(info); GNUNET_CHAT_contact_set_user_pointer(contact, NULL); @@ -153,6 +157,39 @@ contact_remove_name_avatar_from_info(const struct GNUNET_CHAT_Contact *contact, } void +contact_add_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkWidget *widget) +{ + g_assert(widget); + + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); + + if (!info) + return; + + gboolean visible = (GNUNET_YES != GNUNET_CHAT_contact_is_blocked(contact)); + + gtk_widget_set_visible(widget, visible); + + info->visible_widgets = g_list_append(info->visible_widgets, widget); +} + +void +contact_remove_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkWidget *widget) +{ + g_assert(widget); + + MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); + + if (!info) + return; + + if (info->visible_widgets) + info->visible_widgets = g_list_remove(info->visible_widgets, widget); +} + +void contact_update_info(const struct GNUNET_CHAT_Contact *contact) { MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); @@ -163,9 +200,14 @@ contact_update_info(const struct GNUNET_CHAT_Contact *contact) GList* list; const char *name = GNUNET_CHAT_contact_get_name(contact); + gboolean visible = (GNUNET_YES != GNUNET_CHAT_contact_is_blocked(contact)); + for (list = info->name_labels; list; list = list->next) ui_label_set_text(GTK_LABEL(list->data), name); for (list = info->name_avatars; list; list = list->next) ui_avatar_set_text(HDY_AVATAR(list->data), name); + + for (list = info->visible_widgets; list; list = list->next) + gtk_widget_set_visible(GTK_WIDGET(list->data), visible); } diff --git a/src/contact.h b/src/contact.h index ebd9b31..20f8fc6 100644 --- a/src/contact.h +++ b/src/contact.h @@ -33,6 +33,7 @@ typedef struct MESSENGER_ContactInfo GList *name_labels; GList *name_avatars; + GList *visible_widgets; } MESSENGER_ContactInfo; /** @@ -119,6 +120,28 @@ contact_remove_name_avatar_from_info(const struct GNUNET_CHAT_Contact *contact, HdyAvatar *avatar); /** + * Adds a GtkWidget to the list of widgets + * which get visibility updated by state changes. + * + * @param contact Chat contact + * @param widget Widget + */ +void +contact_add_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkWidget *widget); + +/** + * Removes a GtkWidget from the list of widgets + * which get visibility updated by state changes. + * + * @param contact Chat contact + * @param widget Widget + */ +void +contact_remove_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact, + GtkWidget *widget); + +/** * Updates the connected UI elements for a given * contact depending on the current state. * diff --git a/src/event.c b/src/event.c index 358c700..1ab296d 100644 --- a/src/event.c +++ b/src/event.c @@ -765,6 +765,8 @@ skip_message: static void _event_update_tag_message_state(const struct GNUNET_CHAT_Message *msg) { + g_assert((msg) && (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(msg))); + const struct GNUNET_CHAT_Message *target; target = GNUNET_CHAT_message_get_target(msg); @@ -800,11 +802,8 @@ event_delete_message(MESSENGER_Application *app, G_OBJECT(row->data), app->quarks.ui ); - if ((message) && (message->msg == GNUNET_CHAT_message_get_target(msg))) + if ((message) && (message->msg == msg)) { - if (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(message->msg)) - _event_update_tag_message_state(message->msg); - ui_chat_remove_message(handle->chat, app, message); break; } @@ -813,6 +812,9 @@ event_delete_message(MESSENGER_Application *app, if (rows) g_list_free(rows); + if ((msg) && (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(msg))) + _event_update_tag_message_state(msg); + enqueue_chat_entry_update(handle); } diff --git a/src/ui/message.c b/src/ui/message.c index 57668dc..9736ad1 100644 --- a/src/ui/message.c +++ b/src/ui/message.c @@ -766,12 +766,14 @@ ui_message_set_contact(UI_MESSAGE_Handle *handle, { contact_remove_name_avatar_from_info(handle->contact, handle->sender_avatar); contact_remove_name_label_from_info(handle->contact, handle->sender_label); + contact_remove_visible_widget_to_info(handle->contact, handle->message_box); } if (contact) { contact_add_name_avatar_to_info(contact, handle->sender_avatar); contact_add_name_label_to_info(contact, handle->sender_label); + contact_add_visible_widget_to_info(contact, handle->message_box); } handle->contact = contact; |