aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2024-02-17 21:24:05 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2024-02-17 21:24:05 +0100
commita8d1cd08bb4db528093a6bc4d64cb2ea34bf96c8 (patch)
tree49c96be1a459efd07414c6ba0515d1f653ed1817 /src
parent8b95c672e8d9aabab53f09d41eaeed9521ce4b57 (diff)
downloadmessenger-gtk-a8d1cd08bb4db528093a6bc4d64cb2ea34bf96c8.tar.gz
messenger-gtk-a8d1cd08bb4db528093a6bc4d64cb2ea34bf96c8.zip
Implement messages switching visibility depending on the senders block-state
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/chat/messenger.c29
-rw-r--r--src/contact.c42
-rw-r--r--src/contact.h23
-rw-r--r--src/event.c10
-rw-r--r--src/ui/message.c2
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,
79 // Locking the mutex for synchronization 79 // Locking the mutex for synchronization
80 pthread_mutex_lock(&(app->chat.mutex)); 80 pthread_mutex_lock(&(app->chat.mutex));
81 81
82 if (GNUNET_YES == GNUNET_CHAT_message_is_deleted(message))
83 {
84 application_call_message_event(
85 app,
86 event_delete_message,
87 context,
88 message
89 );
90
91 goto skip_message_handling;
92 }
93
82 // Handle each kind of message as proper event regarding context 94 // Handle each kind of message as proper event regarding context
83 switch (GNUNET_CHAT_message_get_kind(message)) 95 switch (GNUNET_CHAT_message_get_kind(message))
84 { 96 {
@@ -162,12 +174,16 @@ _chat_messenger_message(void *cls,
162 } 174 }
163 case GNUNET_CHAT_KIND_DELETION: 175 case GNUNET_CHAT_KIND_DELETION:
164 { 176 {
165 application_call_message_event( 177 const struct GNUNET_CHAT_Message *target;
166 app, 178 target = GNUNET_CHAT_message_get_target(message);
167 event_delete_message, 179
168 context, 180 if (target)
169 message 181 application_call_message_event(
170 ); 182 app,
183 event_delete_message,
184 context,
185 target
186 );
171 break; 187 break;
172 } 188 }
173 case GNUNET_CHAT_KIND_TAG: 189 case GNUNET_CHAT_KIND_TAG:
@@ -184,6 +200,7 @@ _chat_messenger_message(void *cls,
184 break; 200 break;
185 } 201 }
186 202
203skip_message_handling:
187 pthread_mutex_unlock(&(app->chat.mutex)); 204 pthread_mutex_unlock(&(app->chat.mutex));
188 return GNUNET_YES; 205 return GNUNET_YES;
189} 206}
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)
38 38
39 info->name_labels = NULL; 39 info->name_labels = NULL;
40 info->name_avatars = NULL; 40 info->name_avatars = NULL;
41 info->visible_widgets = NULL;
41 42
42 GNUNET_CHAT_contact_set_user_pointer(contact, info); 43 GNUNET_CHAT_contact_set_user_pointer(contact, info);
43} 44}
@@ -58,6 +59,9 @@ contact_destroy_info(struct GNUNET_CHAT_Contact *contact)
58 if (info->name_avatars) 59 if (info->name_avatars)
59 g_list_free(info->name_avatars); 60 g_list_free(info->name_avatars);
60 61
62 if (info->visible_widgets)
63 g_list_free(info->visible_widgets);
64
61 g_free(info); 65 g_free(info);
62 66
63 GNUNET_CHAT_contact_set_user_pointer(contact, NULL); 67 GNUNET_CHAT_contact_set_user_pointer(contact, NULL);
@@ -153,6 +157,39 @@ contact_remove_name_avatar_from_info(const struct GNUNET_CHAT_Contact *contact,
153} 157}
154 158
155void 159void
160contact_add_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact,
161 GtkWidget *widget)
162{
163 g_assert(widget);
164
165 MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
166
167 if (!info)
168 return;
169
170 gboolean visible = (GNUNET_YES != GNUNET_CHAT_contact_is_blocked(contact));
171
172 gtk_widget_set_visible(widget, visible);
173
174 info->visible_widgets = g_list_append(info->visible_widgets, widget);
175}
176
177void
178contact_remove_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact,
179 GtkWidget *widget)
180{
181 g_assert(widget);
182
183 MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
184
185 if (!info)
186 return;
187
188 if (info->visible_widgets)
189 info->visible_widgets = g_list_remove(info->visible_widgets, widget);
190}
191
192void
156contact_update_info(const struct GNUNET_CHAT_Contact *contact) 193contact_update_info(const struct GNUNET_CHAT_Contact *contact)
157{ 194{
158 MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact); 195 MESSENGER_ContactInfo* info = GNUNET_CHAT_contact_get_user_pointer(contact);
@@ -163,9 +200,14 @@ contact_update_info(const struct GNUNET_CHAT_Contact *contact)
163 GList* list; 200 GList* list;
164 const char *name = GNUNET_CHAT_contact_get_name(contact); 201 const char *name = GNUNET_CHAT_contact_get_name(contact);
165 202
203 gboolean visible = (GNUNET_YES != GNUNET_CHAT_contact_is_blocked(contact));
204
166 for (list = info->name_labels; list; list = list->next) 205 for (list = info->name_labels; list; list = list->next)
167 ui_label_set_text(GTK_LABEL(list->data), name); 206 ui_label_set_text(GTK_LABEL(list->data), name);
168 207
169 for (list = info->name_avatars; list; list = list->next) 208 for (list = info->name_avatars; list; list = list->next)
170 ui_avatar_set_text(HDY_AVATAR(list->data), name); 209 ui_avatar_set_text(HDY_AVATAR(list->data), name);
210
211 for (list = info->visible_widgets; list; list = list->next)
212 gtk_widget_set_visible(GTK_WIDGET(list->data), visible);
171} 213}
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
33 33
34 GList *name_labels; 34 GList *name_labels;
35 GList *name_avatars; 35 GList *name_avatars;
36 GList *visible_widgets;
36} MESSENGER_ContactInfo; 37} MESSENGER_ContactInfo;
37 38
38/** 39/**
@@ -119,6 +120,28 @@ contact_remove_name_avatar_from_info(const struct GNUNET_CHAT_Contact *contact,
119 HdyAvatar *avatar); 120 HdyAvatar *avatar);
120 121
121/** 122/**
123 * Adds a GtkWidget to the list of widgets
124 * which get visibility updated by state changes.
125 *
126 * @param contact Chat contact
127 * @param widget Widget
128 */
129void
130contact_add_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact,
131 GtkWidget *widget);
132
133/**
134 * Removes a GtkWidget from the list of widgets
135 * which get visibility updated by state changes.
136 *
137 * @param contact Chat contact
138 * @param widget Widget
139 */
140void
141contact_remove_visible_widget_to_info(const struct GNUNET_CHAT_Contact *contact,
142 GtkWidget *widget);
143
144/**
122 * Updates the connected UI elements for a given 145 * Updates the connected UI elements for a given
123 * contact depending on the current state. 146 * contact depending on the current state.
124 * 147 *
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:
765static void 765static void
766_event_update_tag_message_state(const struct GNUNET_CHAT_Message *msg) 766_event_update_tag_message_state(const struct GNUNET_CHAT_Message *msg)
767{ 767{
768 g_assert((msg) && (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(msg)));
769
768 const struct GNUNET_CHAT_Message *target; 770 const struct GNUNET_CHAT_Message *target;
769 target = GNUNET_CHAT_message_get_target(msg); 771 target = GNUNET_CHAT_message_get_target(msg);
770 772
@@ -800,11 +802,8 @@ event_delete_message(MESSENGER_Application *app,
800 G_OBJECT(row->data), app->quarks.ui 802 G_OBJECT(row->data), app->quarks.ui
801 ); 803 );
802 804
803 if ((message) && (message->msg == GNUNET_CHAT_message_get_target(msg))) 805 if ((message) && (message->msg == msg))
804 { 806 {
805 if (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(message->msg))
806 _event_update_tag_message_state(message->msg);
807
808 ui_chat_remove_message(handle->chat, app, message); 807 ui_chat_remove_message(handle->chat, app, message);
809 break; 808 break;
810 } 809 }
@@ -813,6 +812,9 @@ event_delete_message(MESSENGER_Application *app,
813 if (rows) 812 if (rows)
814 g_list_free(rows); 813 g_list_free(rows);
815 814
815 if ((msg) && (GNUNET_CHAT_KIND_TAG == GNUNET_CHAT_message_get_kind(msg)))
816 _event_update_tag_message_state(msg);
817
816 enqueue_chat_entry_update(handle); 818 enqueue_chat_entry_update(handle);
817} 819}
818 820
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,
766 { 766 {
767 contact_remove_name_avatar_from_info(handle->contact, handle->sender_avatar); 767 contact_remove_name_avatar_from_info(handle->contact, handle->sender_avatar);
768 contact_remove_name_label_from_info(handle->contact, handle->sender_label); 768 contact_remove_name_label_from_info(handle->contact, handle->sender_label);
769 contact_remove_visible_widget_to_info(handle->contact, handle->message_box);
769 } 770 }
770 771
771 if (contact) 772 if (contact)
772 { 773 {
773 contact_add_name_avatar_to_info(contact, handle->sender_avatar); 774 contact_add_name_avatar_to_info(contact, handle->sender_avatar);
774 contact_add_name_label_to_info(contact, handle->sender_label); 775 contact_add_name_label_to_info(contact, handle->sender_label);
776 contact_add_visible_widget_to_info(contact, handle->message_box);
775 } 777 }
776 778
777 handle->contact = contact; 779 handle->contact = contact;