Add Purple.Conversation.find_message_by_id draft purple_conversation_find_message_by_id tip

Sun, 10 Aug 2025 23:44:08 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:44:08 +0800
branch
purple_conversation_find_message_by_id
changeset 43309
099e1dfb856b
parent 43308
6a22b547f0c8

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.

libpurple/purpleconversation.c file | annotate | diff | comparison | revisions
libpurple/purpleconversation.h file | annotate | diff | comparison | revisions
--- 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);
--- 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 <glib-object.h>
 
 #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.

mercurial