Thu, 16 Feb 2023 08:21:31 -0600
IRCv3: Add support for the msgid specification
Testing Done:
Connected to my local ergo sent some messages and verified the id's were stored in `history.db` and that they matched what the server sent that I verified via `ngrep`.
Bugs closed: PIDGIN-17739
Reviewed at https://reviews.imfreedom.org/r/2218/
--- a/libpurple/protocols/ircv3/README.md Thu Feb 16 08:13:28 2023 -0600 +++ b/libpurple/protocols/ircv3/README.md Thu Feb 16 08:21:31 2023 -0600 @@ -19,3 +19,4 @@ * cap-notify * sasl (right now just PLAIN works) * message-tags +* msgid
--- a/libpurple/protocols/ircv3/purpleircv3capabilities.c Thu Feb 16 08:13:28 2023 -0600 +++ b/libpurple/protocols/ircv3/purpleircv3capabilities.c Thu Feb 16 08:21:31 2023 -0600 @@ -101,6 +101,18 @@ } /****************************************************************************** + * Callbacks + *****************************************************************************/ +static void +ircv3_capabilities_message_tags_ack_cb(PurpleIRCv3Capabilities *capabilities, + G_GNUC_UNUSED const char *capability, + G_GNUC_UNUSED gpointer data) +{ + /* We have message tags so add the stuff we support that depends on it. */ + purple_ircv3_capabilities_lookup_and_request(capabilities, "msgid"); +} + +/****************************************************************************** * PurpleIRCv3Capabilities Implementation *****************************************************************************/ static void @@ -133,7 +145,13 @@ /* message-tags is used for a lot of stuff so we need to tell everyone we * do in fact support it. */ - purple_ircv3_capabilities_lookup_and_request(capabilities, "message-tags"); + if(purple_ircv3_capabilities_lookup_and_request(capabilities, + "message-tags")) + { + g_signal_connect(capabilities, "ack::message-tags", + G_CALLBACK(ircv3_capabilities_message_tags_ack_cb), + NULL); + } } /******************************************************************************
--- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c Thu Feb 16 08:13:28 2023 -0600 +++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c Thu Feb 16 08:21:31 2023 -0600 @@ -70,7 +70,7 @@ } gboolean -purple_ircv3_message_handler_privmsg(G_GNUC_UNUSED GHashTable *tags, +purple_ircv3_message_handler_privmsg(GHashTable *tags, const char *source, const char *command, guint n_params, @@ -86,6 +86,9 @@ PurpleConversationManager *conversation_manager = NULL; PurpleMessage *message = NULL; PurpleMessageFlags flags = PURPLE_MESSAGE_RECV; + GDateTime *dt = NULL; + gpointer raw_id = NULL; + const char *id = NULL; const char *target = NULL; if(n_params != 2) { @@ -128,12 +131,29 @@ g_object_unref(conversation); } + /* Grab the msgid if one was provided. */ + if(g_hash_table_lookup_extended(tags, "msgid", NULL, &raw_id)) { + if(!purple_strempty(raw_id)) { + id = raw_id; + } + } + if(purple_strequal(command, "NOTICE")) { flags |= PURPLE_MESSAGE_NOTIFY; } - message = purple_message_new_incoming(account, source, params[1], flags, - 0); + dt = g_date_time_new_now_local(); + + message = g_object_new( + PURPLE_TYPE_MESSAGE, + "author", source, + "contents", params[1], + "flags", flags, + "id", id, + "timestamp", dt, + NULL); + + g_date_time_unref(dt); purple_conversation_write_message(conversation, message);