IRCv3: Create notifications for incoming WALLOPS messages

Thu, 31 Oct 2024 23:53:14 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 31 Oct 2024 23:53:14 -0500
changeset 43028
dda093fe275e
parent 43027
581af7cd0603
child 43029
b95b2d2b8200

IRCv3: Create notifications for incoming WALLOPS messages

Testing Done:
Setup an inspricd instance and sent `WALLOPS` from there to test.

Bugs closed: PIDGIN-17899

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

protocols/ircv3/purpleircv3connection.c file | annotate | diff | comparison | revisions
protocols/ircv3/purpleircv3core.h file | annotate | diff | comparison | revisions
protocols/ircv3/purpleircv3messagehandlers.c file | annotate | diff | comparison | revisions
protocols/ircv3/purpleircv3messagehandlers.h file | annotate | diff | comparison | revisions
protocols/ircv3/purpleircv3protocol.c file | annotate | diff | comparison | revisions
--- a/protocols/ircv3/purpleircv3connection.c	Thu Oct 31 23:48:31 2024 -0500
+++ b/protocols/ircv3/purpleircv3connection.c	Thu Oct 31 23:53:14 2024 -0500
@@ -494,6 +494,9 @@
 	g_signal_connect_object(client, "message::" IBIS_RPL_ENDOFNAMES,
 	                        G_CALLBACK(purple_ircv3_message_handler_ignore),
 	                        connection, G_CONNECT_DEFAULT);
+	g_signal_connect_object(client, "message::" IBIS_MSG_WALLOPS,
+	                        G_CALLBACK(purple_ircv3_message_handler_wallops),
+	                        connection, G_CONNECT_DEFAULT);
 
 
 	g_signal_connect_object(client, "message",
--- a/protocols/ircv3/purpleircv3core.h	Thu Oct 31 23:48:31 2024 -0500
+++ b/protocols/ircv3/purpleircv3core.h	Thu Oct 31 23:53:14 2024 -0500
@@ -34,6 +34,8 @@
 #define PURPLE_IRCV3_DEFAULT_PLAIN_PORT 6667
 #define PURPLE_IRCV3_DEFAULT_TLS_PORT 6697
 
+#define PURPLE_IRCV3_ICON_NAME "im-ircv3"
+
 #define PURPLE_IRCV3_DOMAIN (g_quark_from_static_string("ircv3-plugin"))
 
 #endif /* PURPLE_IRCV3_CORE_H */
--- a/protocols/ircv3/purpleircv3messagehandlers.c	Thu Oct 31 23:48:31 2024 -0500
+++ b/protocols/ircv3/purpleircv3messagehandlers.c	Thu Oct 31 23:53:14 2024 -0500
@@ -665,3 +665,49 @@
 
 	return TRUE;
 }
+
+gboolean
+purple_ircv3_message_handler_wallops(G_GNUC_UNUSED IbisClient *client,
+                                     G_GNUC_UNUSED const char *command,
+                                     IbisMessage *ibis_message,
+                                     gpointer data)
+{
+	PurpleIRCv3Connection *v3_connection = data;
+	PurpleAccount *account = NULL;
+	PurpleConnection *connection = data;
+	PurpleContact *contact = NULL;
+	PurpleContactInfo *info = NULL;
+	PurpleNotification *notification = NULL;
+	PurpleNotificationManager *manager = NULL;
+	GStrv params = NULL;
+	char *wallops_title = NULL;
+	guint n_params = 0;
+
+	params = ibis_message_get_params(ibis_message);
+	n_params = g_strv_length(params);
+
+	if(n_params != 1) {
+		g_message("received WALLOPS with %u params, expected 1", n_params);
+		return FALSE;
+	}
+
+	contact = purple_ircv3_connection_find_or_create_contact(v3_connection,
+	                                                         ibis_message);
+	info = PURPLE_CONTACT_INFO(contact);
+
+	wallops_title = g_strdup_printf(_("WALLOPS from %s"),
+	                                purple_contact_info_get_name_for_display(info));
+	notification = purple_notification_new(NULL, wallops_title);
+	g_free(wallops_title);
+
+	account = purple_connection_get_account(connection);
+	purple_notification_set_account(notification, account);
+	purple_notification_set_subtitle(notification, params[0]);
+	purple_notification_set_icon_name(notification, PURPLE_IRCV3_ICON_NAME);
+
+	manager = purple_notification_manager_get_default();
+	purple_notification_manager_add(manager, notification);
+	g_clear_object(&notification);
+
+	return TRUE;
+}
--- a/protocols/ircv3/purpleircv3messagehandlers.h	Thu Oct 31 23:48:31 2024 -0500
+++ b/protocols/ircv3/purpleircv3messagehandlers.h	Thu Oct 31 23:53:14 2024 -0500
@@ -47,6 +47,7 @@
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_quit(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_nick(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_error(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
+G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_wallops(IbisClient *client, const char *command, IbisMessage *message, gpointer data);
 
 G_END_DECLS
 
--- a/protocols/ircv3/purpleircv3protocol.c	Thu Oct 31 23:48:31 2024 -0500
+++ b/protocols/ircv3/purpleircv3protocol.c	Thu Oct 31 23:53:14 2024 -0500
@@ -252,7 +252,7 @@
 		"id", "prpl-ircv3",
 		"name", "IRCv3",
 		"description", _("Version 3 of Internet Relay Chat (IRC)."),
-		"icon-name", "im-ircv3",
+		"icon-name", PURPLE_IRCV3_ICON_NAME,
 		"icon-resource-path", "/im/pidgin/libpurple/ircv3/icons",
 		"options", OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL |
 		           OPT_PROTO_SLASH_COMMANDS_NATIVE,

mercurial