changeset 29010:db0762fbb60b

jabber: Document jabber_find_unnormalized_im_conv (and my guess as to why it exists instead of using purple_find_conversation_with_account).
author Paul Aurich <paul@darkrain42.org>
date Wed, 10 Feb 2010 05:06:36 +0000
parents 4fb74d76c2df
children a363b5aff793
files libpurple/protocols/jabber/jutil.c libpurple/protocols/jabber/jutil.h libpurple/protocols/jabber/message.c libpurple/protocols/jabber/presence.c
diffstat 4 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jutil.c	Wed Feb 10 04:35:10 2010 +0000
+++ b/libpurple/protocols/jabber/jutil.c	Wed Feb 10 05:06:36 2010 +0000
@@ -652,18 +652,17 @@
 }
 
 PurpleConversation *
-jabber_find_unnormalized_conv(const char *name, PurpleAccount *account)
+jabber_find_unnormalized_im_conv(const char *name, PurpleAccount *account)
 {
 	PurpleConversation *c = NULL;
 	GList *cnv;
 
 	g_return_val_if_fail(name != NULL, NULL);
 
-	for(cnv = purple_get_conversations(); cnv; cnv = cnv->next) {
+	for (cnv = purple_get_ims(); cnv; cnv = cnv->next) {
 		c = (PurpleConversation*)cnv->data;
-		if(purple_conversation_get_type(c) == PURPLE_CONV_TYPE_IM &&
-				!purple_utf8_strcasecmp(name, purple_conversation_get_name(c)) &&
-				account == purple_conversation_get_account(c))
+		if (account == purple_conversation_get_account(c) &&
+				!purple_utf8_strcasecmp(name, purple_conversation_get_name(c)))
 			return c;
 	}
 
--- a/libpurple/protocols/jabber/jutil.h	Wed Feb 10 04:35:10 2010 +0000
+++ b/libpurple/protocols/jabber/jutil.h	Wed Feb 10 05:06:36 2010 +0000
@@ -63,7 +63,17 @@
  */
 char *jabber_saslprep(const char *);
 
-PurpleConversation *jabber_find_unnormalized_conv(const char *name, PurpleAccount *account);
+/**
+ * Search for an IM conversation with this specific user (including resource).
+ * This is an alternative to purple_find_conversation_with_account(), which
+ * calls purple_normalize (so if a conversation was found, we'd need to compare
+ * the conversation name to see if the resources match).
+ *
+ * This function saves a call to purple_normalize(), at the expense of
+ * iterating over every open IM conversation.  For most usages, I think
+ * this tradeoff is OK.
+ */
+PurpleConversation *jabber_find_unnormalized_im_conv(const char *name, PurpleAccount *account);
 
 char *jabber_calculate_data_sha1sum(gconstpointer data, size_t len);
 #endif /* PURPLE_JABBER_JUTIL_H_ */
--- a/libpurple/protocols/jabber/message.c	Wed Feb 10 04:35:10 2010 +0000
+++ b/libpurple/protocols/jabber/message.c	Wed Feb 10 05:06:36 2010 +0000
@@ -75,7 +75,7 @@
 	jb = jabber_buddy_find(jm->js, jm->from, TRUE);
 	jbr = jabber_buddy_find_resource(jb, jid->resource);
 
-	if(jabber_find_unnormalized_conv(jm->from, account)) {
+	if(jabber_find_unnormalized_im_conv(jm->from, account)) {
 		from = g_strdup(jm->from);
 	} else  if(jid->node) {
 		if (jid->resource) {
--- a/libpurple/protocols/jabber/presence.c	Wed Feb 10 04:35:10 2010 +0000
+++ b/libpurple/protocols/jabber/presence.c	Wed Feb 10 05:06:36 2010 +0000
@@ -1004,7 +1004,7 @@
 			PurpleConversation *conv;
 
 			jabber_buddy_remove_resource(jb, jid->resource);
-			if((conv = jabber_find_unnormalized_conv(from, js->gc->account)))
+			if((conv = jabber_find_unnormalized_im_conv(from, js->gc->account)))
 				/*
 				 * If a resource went offline (or the buddy unsubscribed),
 				 * send further messages to the bare JID.  (This is also