diff options
author | Gary Kramlich <grim@reaperworld.com> | 2023-02-16 08:21:31 -0600 |
---|---|---|
committer | Gary Kramlich <grim@reaperworld.com> | 2023-02-16 08:21:31 -0600 |
commit | 0932c2427e1517e29efd28d1b641da8598f07cfb (patch) | |
tree | 93ca2f3713fe2391f08c142c653a363121872e9b /libpurple | |
parent | 8cc4bba0eaaae7c6aebca5a40abeb85370bc6073 (diff) | |
download | pidgin-0932c2427e1517e29efd28d1b641da8598f07cfb.tar.gz |
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/
Diffstat (limited to 'libpurple')
-rw-r--r-- | libpurple/protocols/ircv3/README.md | 1 | ||||
-rw-r--r-- | libpurple/protocols/ircv3/purpleircv3capabilities.c | 20 | ||||
-rw-r--r-- | libpurple/protocols/ircv3/purpleircv3messagehandlers.c | 26 |
3 files changed, 43 insertions, 4 deletions
diff --git a/libpurple/protocols/ircv3/README.md b/libpurple/protocols/ircv3/README.md index 3fa2c1fa5a..8df607539c 100644 --- a/libpurple/protocols/ircv3/README.md +++ b/libpurple/protocols/ircv3/README.md @@ -19,3 +19,4 @@ us know! * cap-notify * sasl (right now just PLAIN works) * message-tags +* msgid diff --git a/libpurple/protocols/ircv3/purpleircv3capabilities.c b/libpurple/protocols/ircv3/purpleircv3capabilities.c index 35ac8c165c..44685ce91c 100644 --- a/libpurple/protocols/ircv3/purpleircv3capabilities.c +++ b/libpurple/protocols/ircv3/purpleircv3capabilities.c @@ -101,6 +101,18 @@ purple_ircv3_capabilities_add(PurpleIRCv3Capabilities *capabilities, } /****************************************************************************** + * 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 @@ purple_ircv3_capabilities_default_ready_cb(PurpleIRCv3Capabilities *capabilities /* 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); + } } /****************************************************************************** diff --git a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c index 88b1f5ba1c..08d813f211 100644 --- a/libpurple/protocols/ircv3/purpleircv3messagehandlers.c +++ b/libpurple/protocols/ircv3/purpleircv3messagehandlers.c @@ -70,7 +70,7 @@ purple_ircv3_message_handler_ping(G_GNUC_UNUSED GHashTable *tags, } 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 @@ purple_ircv3_message_handler_privmsg(G_GNUC_UNUSED GHashTable *tags, 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 @@ purple_ircv3_message_handler_privmsg(G_GNUC_UNUSED GHashTable *tags, 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); |