# HG changeset patch # User Gong Zhile # Date 1754840648 -28800 # Node ID 099e1dfb856ba7c1b601fe89d37df4cd919a726a # Parent 6a22b547f0c8da50b7c5bab16bdfe0588fc292b7 Add Purple.Conversation.find_message_by_id The method was added so that a protocol or plugin could easily lookup for the reference for a message. This will be especially useful when a protocol received a quoted message but only with an id. diff -r 6a22b547f0c8 -r 099e1dfb856b libpurple/purpleconversation.c --- a/libpurple/purpleconversation.c Sat Aug 09 18:21:54 2025 -0500 +++ b/libpurple/purpleconversation.c Sun Aug 10 23:44:08 2025 +0800 @@ -2291,6 +2291,25 @@ return member; } +PurpleMessage * +purple_conversation_find_message_by_id(PurpleConversation *conversation, + const char *id) +{ + GListModel *model = G_LIST_MODEL(conversation->messages); + guint n_items = g_list_model_get_n_items(model); + + g_return_val_if_fail(id != NULL, NULL); + + for (guint i = 0; i < n_items; i++) { + PurpleMessage *message = PURPLE_MESSAGE(g_list_model_get_item(model, i)); + + if (purple_strequal(purple_message_get_id(message), id)) + return message; + } + + return NULL; +} + const char * purple_conversation_get_url(PurpleConversation *conversation) { g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), NULL); diff -r 6a22b547f0c8 -r 099e1dfb856b libpurple/purpleconversation.h --- a/libpurple/purpleconversation.h Sat Aug 09 18:21:54 2025 -0500 +++ b/libpurple/purpleconversation.h Sun Aug 10 23:44:08 2025 +0800 @@ -31,6 +31,7 @@ #include #include "purpleimage.h" +#include "purplemessage.h" #include "purpleconversationmembers.h" #include "purpletyping.h" #include "purpleversion.h" @@ -1044,6 +1045,19 @@ PurpleConversationMember *purple_conversation_find_or_add_member(PurpleConversation *conversation, PurpleContactInfo *info, gboolean announce, const char *message); /** + * purple_conversation_find_message_by_id: + * @id: The id of the message. + * + * Looks up a message in a conversation based on its id property. + * + * Returns: (transfer none): The message if found, otherwise %NULL. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +PurpleMessage *purple_conversation_find_message_by_id(PurpleConversation *conversation, const char *id); + +/** * purple_conversation_get_url: * * Gets the URL associated with the conversation.