qulogic/pidgin

IRCv3: Add support for updating topics

7 months ago, Gary Kramlich
55eff782a478
Parents 2884199a5a08
Children 02c38caf387b
IRCv3: Add support for updating topics

This only sets the text as we need a helper to find or create a contact info to
do the topic author.

Testing Done:
Set and unset the topic from another client and verified it was displayed correctly including on join.

Reviewed at https://reviews.imfreedom.org/r/2817/
--- a/libpurple/protocols/ircv3/meson.build Thu Nov 16 03:53:39 2023 -0600
+++ b/libpurple/protocols/ircv3/meson.build Thu Nov 16 20:26:13 2023 -0600
@@ -14,6 +14,7 @@
IRCV3_HEADERS = [
'purpleircv3capabilities.h',
'purpleircv3connection.h',
+ 'purpleircv3constants.h',
'purpleircv3core.h',
'purpleircv3message.h',
'purpleircv3messagehandlers.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/ircv3/purpleircv3constants.h Thu Nov 16 20:26:13 2023 -0600
@@ -0,0 +1,53 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ */
+#if !defined(PURPLE_IRCV3_GLOBAL_HEADER_INSIDE) && \
+ !defined(PURPLE_IRCV3_COMPILATION)
+# error "only <libpurple/protocols/ircv3.h> may be included directly"
+#endif
+
+#ifndef PURPLE_IRCV3_CONSTANTS_H
+#define PURPLE_IRCV3_CONSTANTS_H
+
+/**
+ * PURPLE_IRCV3_MSG_TOPIC:
+ *
+ * A constant for the IRC %TOPIC message.
+ *
+ * Since: 3.0.0
+ */
+#define PURPLE_IRCV3_MSG_TOPIC ("TOPIC")
+
+/**
+ * PURPLE_IRCV3_RPL_NOTOPIC:
+ *
+ * A constant for the IRC %NOTOPIC reply.
+ *
+ * Since: 3.0.0
+ */
+#define PURPLE_IRCV3_RPL_NOTOPIC ("331")
+
+/**
+ * PURPLE_IRCV3_RPL_TOPIC:
+ *
+ * A constant for the IRC %TOPIC reply.
+ *
+ * Since: 3.0.0
+ */
+#define PURPLE_IRCV3_RPL_TOPIC ("332")
+
+#endif /* PURPLE_IRCV3_CONSTANTS_H */
--- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c Thu Nov 16 03:53:39 2023 -0600
+++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c Thu Nov 16 20:26:13 2023 -0600
@@ -21,6 +21,7 @@
#include "purpleircv3messagehandlers.h"
#include "purpleircv3connection.h"
+#include "purpleircv3constants.h"
#include "purpleircv3core.h"
#include "purpleircv3source.h"
@@ -227,3 +228,74 @@
return TRUE;
}
+
+gboolean
+purple_ircv3_message_handler_topic(PurpleIRCv3Message *message,
+ GError **error,
+ gpointer data)
+{
+ PurpleIRCv3Connection *connection = data;
+ PurpleConversation *conversation = NULL;
+ GStrv params = NULL;
+ const char *channel = NULL;
+ const char *command = NULL;
+ const char *topic = NULL;
+ guint n_params = 0;
+
+ command = purple_ircv3_message_get_command(message);
+ params = purple_ircv3_message_get_params(message);
+ n_params = g_strv_length(params);
+
+ if(purple_strequal(command, PURPLE_IRCV3_MSG_TOPIC)) {
+ if(n_params != 2) {
+ g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
+ "received TOPIC with %u parameters, expected 2",
+ n_params);
+
+ return FALSE;
+ }
+
+ channel = params[0];
+ topic = params[1];
+ } else if(purple_strequal(command, PURPLE_IRCV3_RPL_NOTOPIC)) {
+ if(n_params != 3) {
+ g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
+ "received RPL_NOTOPIC with %u parameters, expected 3",
+ n_params);
+
+ return FALSE;
+ }
+
+ channel = params[1];
+ topic = "";
+ } else if(purple_strequal(command, PURPLE_IRCV3_RPL_TOPIC)) {
+ if(n_params != 3) {
+ g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
+ "received RPL_TOPIC with %u parameters, expected 3",
+ n_params);
+
+ return FALSE;
+ }
+
+ channel = params[1];
+ topic = params[2];
+ } else {
+ g_set_error(error, PURPLE_IRCV3_DOMAIN, 0, "unexpected command %s",
+ command);
+
+ return FALSE;
+ }
+
+ conversation = purple_ircv3_connection_find_or_create_conversation(connection,
+ channel);
+ if(!PURPLE_IS_CONVERSATION(conversation)) {
+ g_set_error(error, PURPLE_IRCV3_DOMAIN, 0,
+ "failed to find or create channel '%s'", channel);
+
+ return FALSE;
+ }
+
+ purple_conversation_set_topic(conversation, topic);
+
+ return TRUE;
+}
--- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.h Thu Nov 16 03:53:39 2023 -0600
+++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.h Thu Nov 16 20:26:13 2023 -0600
@@ -55,6 +55,7 @@
G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_status_ignore_param0(PurpleIRCv3Message *message, GError **error, gpointer data);
G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_ping(PurpleIRCv3Message *message, GError **error, gpointer data);
G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_privmsg(PurpleIRCv3Message *message, GError **error, gpointer data);
+G_GNUC_INTERNAL gboolean purple_ircv3_message_handler_topic(PurpleIRCv3Message *message, GError **error, gpointer data);
G_END_DECLS
--- a/libpurple/protocols/ircv3/purpleircv3parser.c Thu Nov 16 03:53:39 2023 -0600
+++ b/libpurple/protocols/ircv3/purpleircv3parser.c Thu Nov 16 20:26:13 2023 -0600
@@ -19,6 +19,7 @@
#include "purpleircv3parser.h"
#include "purpleircv3capabilities.h"
+#include "purpleircv3constants.h"
#include "purpleircv3core.h"
#include "purpleircv3message.h"
#include "purpleircv3messagehandlers.h"
@@ -442,6 +443,14 @@
purple_ircv3_parser_add_handler(parser, "PRIVMSG",
purple_ircv3_message_handler_privmsg);
+ /* Topic stuff. */
+ purple_ircv3_parser_add_handler(parser, PURPLE_IRCV3_MSG_TOPIC,
+ purple_ircv3_message_handler_topic);
+ purple_ircv3_parser_add_handler(parser, PURPLE_IRCV3_RPL_NOTOPIC,
+ purple_ircv3_message_handler_topic);
+ purple_ircv3_parser_add_handler(parser, PURPLE_IRCV3_RPL_TOPIC,
+ purple_ircv3_message_handler_topic);
+
/* Post Registration Greetings */
purple_ircv3_parser_add_handlers(parser,
purple_ircv3_message_handler_status_ignore_param0,