Hide the badges on Pidgin.Message when the user doesn't have any

Thu, 02 Jan 2025 22:46:22 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 02 Jan 2025 22:46:22 -0600
changeset 43125
06367e26ef2f
parent 43124
711b58ead6df
child 43126
5b5a883528e0

Hide the badges on Pidgin.Message when the user doesn't have any

Testing Done:
Sent a message with echo on the demo protocol plugin and verified the badges were hidden. Then sent messages in an irc channel where another client had ops and verified they were hidden for me but shown for the other side.

Bugs closed: PIDGIN-18020

Reviewed at https://reviews.imfreedom.org/r/3721/

pidgin/pidginmessage.c file | annotate | diff | comparison | revisions
pidgin/resources/Conversations/message.ui file | annotate | diff | comparison | revisions
--- a/pidgin/pidginmessage.c	Thu Jan 02 22:42:47 2025 -0600
+++ b/pidgin/pidginmessage.c	Thu Jan 02 22:46:22 2025 -0600
@@ -273,6 +273,31 @@
 	return pidgin_message_set_tooltip_for_timestamp(tooltip, timestamp);
 }
 
+static gboolean
+pidgin_message_show_badges_cb(G_GNUC_UNUSED GObject *self,
+                              PurpleMessage *message,
+                              G_GNUC_UNUSED gpointer data)
+{
+	if(PURPLE_IS_MESSAGE(message)) {
+		PurpleConversationMember *member = NULL;
+
+		member = purple_message_get_author(message);
+		if(PURPLE_IS_CONVERSATION_MEMBER(member)) {
+			PurpleBadges *badges = NULL;
+			guint n_badges = 0;
+
+			badges = purple_conversation_member_get_badges(member);
+			n_badges = g_list_model_get_n_items(G_LIST_MODEL(badges));
+
+			if(n_badges > 0) {
+				return TRUE;
+			}
+		}
+	}
+
+	return FALSE;
+}
+
 /******************************************************************************
  * GObject Implementation
  *****************************************************************************/
@@ -368,6 +393,8 @@
 	                                        pidgin_message_query_tooltip_edited_cb);
 	gtk_widget_class_bind_template_callback(widget_class,
 	                                        pidgin_message_query_tooltip_timestamp_cb);
+	gtk_widget_class_bind_template_callback(widget_class,
+	                                        pidgin_message_show_badges_cb);
 }
 
 /******************************************************************************
--- a/pidgin/resources/Conversations/message.ui	Thu Jan 02 22:42:47 2025 -0600
+++ b/pidgin/resources/Conversations/message.ui	Thu Jan 02 22:46:22 2025 -0600
@@ -45,6 +45,11 @@
                     </lookup>
                   </lookup>
                 </binding>
+                <binding name="visible">
+                  <closure type="gboolean" function="pidgin_message_show_badges_cb">
+                    <lookup name="message">PidginMessage</lookup>
+                  </closure>
+                </binding>
               </object>
             </child>
             <child>

mercurial