adium: e458e71b: Add a GHashTable to PurpleConvChatBuddy ...

zacw at adiumx.com zacw at adiumx.com
Mon Apr 13 23:55:47 EDT 2009


-----------------------------------------------------------------
Revision: e458e71beb6cabc19c7d0fa57cd3c4cb699a9b76
Ancestor: f6830aae63dd2f1ffe438068066ee2322d88d8e6
Author: zacw at adiumx.com
Date: 2009-04-13T23:43:09
Branch: im.pidgin.adium
URL: http://d.pidgin.im/viewmtn/revision/info/e458e71beb6cabc19c7d0fa57cd3c4cb699a9b76

Modified files:
        libpurple/conversation.c libpurple/conversation.h
        libpurple/protocols/irc/irc.h libpurple/protocols/irc/msgs.c
        libpurple/protocols/irc/parse.c

ChangeLog: 

Add a GHashTable to PurpleConvChatBuddy to store attributes of a buddy. Specifically, userhost and realname for IRC contacts.

-------------- next part --------------
============================================================
--- libpurple/conversation.c	73d3d0a936e4d7ecaf9e4213ca4798cf18c663d5
+++ libpurple/conversation.c	31c4acd7890ec64280f3128aebc45a42a10e387f
@@ -2023,6 +2023,8 @@ purple_conv_chat_cb_new(const char *name
 	cb->name = g_strdup(name);
 	cb->flags = flags;
 	cb->alias = g_strdup(alias);
+	cb->attributes = g_hash_table_new_full(g_str_hash, g_str_equal,
+										   g_free, g_free);
 
 	PURPLE_DBUS_REGISTER_POINTER(cb, PurpleConvChatBuddy);
 	return cb;
@@ -2055,6 +2057,7 @@ purple_conv_chat_cb_destroy(PurpleConvCh
 	g_free(cb->alias);
 	g_free(cb->alias_key);
 	g_free(cb->name);
+	g_hash_table_unref(cb->attributes);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(cb);
 	g_free(cb);
@@ -2068,7 +2071,39 @@ purple_conv_chat_cb_get_name(PurpleConvC
 	return cb->name;
 }
 
+const char *
+purple_conv_chat_cb_get_attribute(PurpleConvChatBuddy *cb, const char *key)
+{
+	g_return_val_if_fail(cb != NULL, NULL);
+	
+	return g_hash_table_lookup(cb->attributes, key);
+}
+
 GList *
+purple_conv_chat_cb_get_attribute_keys(PurpleConvChatBuddy *cb)
+{
+	g_return_val_if_fail(cb != NULL, NULL);
+	
+	return g_hash_table_get_keys(cb->attributes);
+}
+
+void
+purple_conv_chat_cb_set_attribute(PurpleConvChat *chat, PurpleConvChatBuddy *cb, const char *key, const char *value)
+{
+	g_return_if_fail(cb != NULL);
+	g_return_if_fail(key != NULL);
+	g_return_if_fail(value != NULL);
+	
+	g_hash_table_replace(cb->attributes, g_strdup(key), g_strdup(value));
+	
+	PurpleConversation *conv = purple_conv_chat_get_conversation(chat);
+	PurpleConversationUiOps *ops = purple_conversation_get_ui_ops(conv);
+	
+	if (ops != NULL && ops->chat_update_user != NULL)
+		ops->chat_update_user(conv, cb->name);
+}
+
+GList *
 purple_conversation_get_extended_menu(PurpleConversation *conv)
 {
 	GList *menu = NULL;
============================================================
--- libpurple/conversation.h	11e5d0c3f04f8ee6d722d3101486ffc18df47738
+++ libpurple/conversation.h	c70c2f54a7b1af52d887971b98c1ac9b9c7c3357
@@ -300,6 +300,9 @@ struct _PurpleConvChatBuddy
 	PurpleConvChatBuddyFlags flags;  /**< A bitwise OR of flags for this participant,
 	                                  *   such as whether they are a channel operator.
 	                                  */
+	GHashTable *attributes;			 /**< A hash table of attributes about the user, such as
+									  *   real name, user at host, etc.
+									  */
 };
 
 /**
@@ -1340,6 +1343,35 @@ const char *purple_conv_chat_cb_get_name
 const char *purple_conv_chat_cb_get_name(PurpleConvChatBuddy *cb);
 
 /**
+ * Get an attribute of a chat buddy
+ *
+ * @param cb	The chat buddy.
+ * @param key	The key of the attribute.
+ *
+ * @return The value of the attribute key.
+ */
+const char *purple_conv_chat_cb_get_attribute(PurpleConvChatBuddy *cb, const char *key);
+
+/**
+ * Get the keys of all atributes of a chat buddy
+ *
+ * @param cb	The chat buddy.
+ *
+ * @return A list of the attributes of a chat buddy.
+ */
+GList *purple_conv_chat_cb_get_attribute_keys(PurpleConvChatBuddy *cb);
+	
+/**
+ * Set an attribute of a chat buddy
+ *
+ * @param chat	The chat.
+ * @param cb	The chat buddy.
+ * @param key	The key of the attribute.
+ * @param value	The value of the attribute.
+ */
+void purple_conv_chat_cb_set_attribute(PurpleConvChat *chat, PurpleConvChatBuddy *cb, const char *key, const char *value);
+	
+/**
  * Destroys a chat buddy
  *
  * @param cb The chat buddy to destroy
============================================================
--- libpurple/protocols/irc/irc.h	a8868ca914d28d8cc42de7f923b89ac05c641554
+++ libpurple/protocols/irc/irc.h	03d495c6aa3d0c213073609ba954efe91b5da109
@@ -160,6 +160,7 @@ void irc_msg_whois(struct irc_conn *irc,
 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args);
 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args);
 void irc_msg_whois(struct irc_conn *irc, const char *name, const char *from, char **args);
+void irc_msg_who(struct irc_conn *irc, const char *name, const char *from, char **args);
 
 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args);
 
============================================================
--- libpurple/protocols/irc/msgs.c	dbb4ea177269ee632ad39eb70e9e180d35ba9151
+++ libpurple/protocols/irc/msgs.c	381064a378e99354fc22587d096737990ef4dede
@@ -415,6 +415,34 @@ void irc_msg_endwhois(struct irc_conn *i
 	memset(&irc->whois, 0, sizeof(irc->whois));
 }
 
+void irc_msg_who(struct irc_conn *irc, const char *name, const char *from, char **args)
+{
+	if (!strcmp(name, "352")) {
+		PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, args[1], irc->account);
+		if (!conv) {
+			purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got a WHO response for %s, which doesn't exist\n", args[1]);
+			return;
+		}
+
+		PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), args[5]);
+		if (!cb) {
+			purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got a WHO response for %s who isn't a buddy.\n", args[5]);
+			return;
+		}
+
+		PurpleConvChat *chat = PURPLE_CONV_CHAT(conv);
+		
+		char *userhost = g_strdup_printf("%s@%s", args[2], args[3]);
+		char *realname = g_strdup(args[8]);
+		
+		purple_conv_chat_cb_set_attribute(chat, cb, "userhost", userhost);
+		purple_conv_chat_cb_set_attribute(chat, cb, "realname", realname);
+		
+		g_free(userhost);
+		g_free(realname);
+	}
+}
+
 void irc_msg_list(struct irc_conn *irc, const char *name, const char *from, char **args)
 {
 	if (!irc->roomlist)
@@ -801,6 +829,7 @@ void irc_msg_join(struct irc_conn *irc, 
 {
 	PurpleConnection *gc = purple_account_get_connection(irc->account);
 	PurpleConversation *convo;
+	PurpleConvChat *chat;
 	char *nick = irc_mask_nick(from), *userhost;
 	struct irc_buddy *ib;
 	static int id = 1;
@@ -824,6 +853,12 @@ void irc_msg_join(struct irc_conn *irc, 
 		}
 		purple_conversation_set_data(convo, IRC_NAMES_FLAG,
 					   GINT_TO_POINTER(FALSE));
+		
+		// Get the real name and user host for all participants.
+		char *buf = irc_format(irc, "vc", "WHO", args[0]);
+		irc_send(irc, buf);
+		g_free(buf);
+		
 		/* Until purple_conversation_present does something that
 		 * one would expect in Pidgin, this call produces buggy
 		 * behavior both for the /join and auto-join cases. */
@@ -839,8 +874,14 @@ void irc_msg_join(struct irc_conn *irc, 
 	}
 
 	userhost = irc_mask_userhost(from);
-	purple_conv_chat_add_user(PURPLE_CONV_CHAT(convo), nick, userhost, PURPLE_CBFLAGS_NONE, TRUE);
-
+	chat = PURPLE_CONV_CHAT(convo);
+	
+	purple_conv_chat_add_user(chat, nick, userhost, PURPLE_CBFLAGS_NONE, TRUE);
+	
+	PurpleConvChatBuddy *cb = purple_conv_chat_cb_find(chat, nick);
+	
+	purple_conv_chat_cb_set_attribute(chat, cb, "userhost", userhost);
+	
 	if ((ib = g_hash_table_lookup(irc->buddies, nick)) != NULL) {
 		ib->flag = TRUE;
 		irc_buddy_status(nick, ib, irc);
============================================================
--- libpurple/protocols/irc/parse.c	c11997c11f4d9d31784bee342152c6813019b8a1
+++ libpurple/protocols/irc/parse.c	8fc0790367a4492c4e69edbc82fe613715c4710e
@@ -65,6 +65,7 @@ static struct _irc_msg {
 	{ "319", "nn:", irc_msg_whois },	/* Whois channels		*/
 	{ "320", "nn:", irc_msg_whois },	/* Whois (fn ident)		*/
 	{ "314", "nnnvv:", irc_msg_whois },	/* Whowas user			*/
+	{ "315", "nt:", irc_msg_who }, /* end of WHO channel */
 	{ "369", "nt:", irc_msg_endwhois },	/* End of WHOWAS		*/
 	{ "321", "*", irc_msg_list },		/* Start of list		*/
 	{ "322", "ncv:", irc_msg_list },	/* List.			*/
@@ -73,6 +74,7 @@ static struct _irc_msg {
 	{ "331", "nc:",	irc_msg_topic },	/* No channel topic		*/
 	{ "332", "nc:", irc_msg_topic },	/* Channel topic		*/
 	{ "333", "*", irc_msg_ignore },		/* Topic setter stuff		*/
+	{ "352", "nvcvnvvv:", irc_msg_who },	/* Channel WHO			*/
 	{ "353", "nvc:", irc_msg_names },	/* Names list			*/
 	{ "366", "nc:", irc_msg_names },	/* End of names			*/
 	{ "367", "ncnnv", irc_msg_ban },	/* Ban list			*/


More information about the Commits mailing list