--- a/libpurple/purplecontact.c Fri Dec 01 01:09:14 2023 -0600
+++ b/libpurple/purplecontact.c Fri Dec 01 02:18:28 2023 -0600
@@ -18,8 +18,7 @@
#include "purplecontact.h"
-#include "purpleenums.h"
+#include "purpleconversationmanager.h" PurpleContactInfo parent;
@@ -141,3 +140,37 @@
+purple_contact_find_dm(PurpleContact *contact, gboolean create) { + PurpleConversation *conversation = NULL; + PurpleConversationManager *manager = NULL; + const char *name = NULL; + g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL); + manager = purple_conversation_manager_get_default(); + name = purple_contact_info_get_username(PURPLE_CONTACT_INFO(contact)); + conversation = purple_conversation_manager_find_im(manager, + if(PURPLE_IS_CONVERSATION(conversation)) { + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "account", contact->account, + "type", PurpleConversationTypeDM, + purple_conversation_manager_register(manager, conversation); + /* The manager holds a reference, so we're just returning that. */ + g_object_unref(conversation); --- a/libpurple/purplecontact.h Fri Dec 01 01:09:14 2023 -0600
+++ b/libpurple/purplecontact.h Fri Dec 01 02:18:28 2023 -0600
@@ -40,6 +40,7 @@
#include "purpleaccount.h"
+#include "purpleconversation.h" @@ -79,6 +80,25 @@
PurpleAccount *purple_contact_get_account(PurpleContact *contact);
+ * purple_contact_find_dm: + * @contact: The instance. + * @create: Whether or not to create a new DM if one can't be found. + * Attempts to find a conversation for @contact in the default + * [class@ContactManager] by using @contact's username. + * If no existing direct messages exists for @contact and @create is %TRUE, + * then a new direct message will be created and registered in the default + * [class@ConversationManager]. + * Returns: (transfer none) (nullable): The conversation or %NULL. +PurpleConversation *purple_contact_find_dm(PurpleContact *contact, gboolean create); #endif /* PURPLE_CONTACT_H */
--- a/pidgin/pidgincontactlist.c Fri Dec 01 01:09:14 2023 -0600
+++ b/pidgin/pidgincontactlist.c Fri Dec 01 02:18:28 2023 -0600
@@ -191,13 +191,9 @@
pidgin_contact_list_activate_cb(GtkListView *self, guint position,
G_GNUC_UNUSED gpointer data)
- PurpleAccount *account = NULL;
PurpleContactInfo *info = NULL;
- PurpleConversation *conversation = NULL;
- PurpleConversationManager *manager = NULL;
PurplePerson *person = NULL;
GtkSelectionModel *model = NULL;
- const char *name = NULL;
model = gtk_list_view_get_model(self);
@@ -210,22 +206,7 @@
info = purple_person_get_priority_contact_info(person);
- account = purple_contact_get_account(PURPLE_CONTACT(info));
- name = purple_contact_info_get_username(info);
- manager = purple_conversation_manager_get_default();
- conversation = purple_conversation_manager_find_im(manager, account, name);
- if(!PURPLE_IS_CONVERSATION(conversation)) {
- conversation = g_object_new(
- PURPLE_TYPE_CONVERSATION,
- "type", PurpleConversationTypeDM,
- purple_conversation_manager_register(manager, conversation);
- g_clear_object(&conversation);
+ purple_contact_find_dm(PURPLE_CONTACT(info), TRUE);