pidgin: 191873f7: Support custom smileys in MUCs (when all...

malu at pidgin.im malu at pidgin.im
Wed May 13 16:30:49 EDT 2009


-----------------------------------------------------------------
Revision: 191873f724e4551edc337f1e018980f32c41391b
Ancestor: de00ba4608f6410625b80dbfb07287b668eee937
Author: malu at pidgin.im
Date: 2009-05-13T20:29:03
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/191873f724e4551edc337f1e018980f32c41391b

Modified files:
        ChangeLog libpurple/protocols/jabber/buddy.c
        libpurple/protocols/jabber/chat.c
        libpurple/protocols/jabber/chat.h
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/message.c

ChangeLog: 

Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.

-------------- next part --------------
============================================================
--- ChangeLog	278d1a28e38a2e9affa109cc17f06e0f08309ed5
+++ ChangeLog	7af34040ef314dbf0062464b88dd7852efc81aed
@@ -38,6 +38,9 @@ version 2.6.0 (??/??/2009):
 	  contains formatting.
 	* Show when the user was last logged in when doing "Get Info" on an offline
 	  buddy, provided the server supports it.
+	* Support custom smileys in MUCs (only when all participants supports the
+	  "Bits of Binary" extension, and a maximum of 10 participants are in the
+	  chat (to avoid getting too many fetch requests).
 
 	Yahoo:
 	* P2P file transfers. (Sulabh Mahajan)
============================================================
--- libpurple/protocols/jabber/buddy.c	15ad67da0121fb68446daaee594980c653276b7c
+++ libpurple/protocols/jabber/buddy.c	3ba51c7b8e6d13e0c4d2bb6180eab4cc0b137552
@@ -74,7 +74,7 @@ JabberBuddy *jabber_buddy_find(JabberStr
 	if (js->buddies == NULL)
 		return NULL;
 
-	if(!(realname = jabber_normalize(js->gc->account, name)))
+	if(!(realname = jabber_get_bare_jid(name)))
 		return NULL;
 
 	jb = g_hash_table_lookup(js->buddies, realname);
============================================================
--- libpurple/protocols/jabber/chat.c	366bf5c22ad7d35fc6296a5833d80365fcb85b74
+++ libpurple/protocols/jabber/chat.c	6846472fc29aeffb1a62285bf7121c37d3691881
@@ -1162,5 +1162,59 @@ void jabber_chat_disco_traffic(JabberCha
 	g_free(room_jid);
 }
 
+typedef struct {
+	const gchar *cap;
+	gboolean *all_support;
+	JabberBuddy *jb;
+} JabberChatCapsData;
 
+static void
+jabber_chat_all_participants_have_capability_foreach(gpointer key,
+                                                     gpointer value,
+                                                     gpointer user_data)
+{
+	const gchar *cap = ((JabberChatCapsData *) user_data)->cap;
+	gboolean *all_support = ((JabberChatCapsData *) user_data)->all_support;
+	JabberBuddy *jb = ((JabberChatCapsData *) user_data)->jb;
+	JabberChatMember *member = (JabberChatMember *) value;
+	const gchar *resource = member->handle;
+	JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource);
 
+	if (jbr) {
+		*all_support &= jabber_resource_has_capability(jbr, cap);
+	} else {
+		*all_support = FALSE;
+	}
+}
+
+gboolean
+jabber_chat_all_participants_have_capability(const JabberChat *chat,
+	const gchar *cap)
+{
+	gchar *chat_jid = NULL;
+	JabberBuddy *jb = NULL;
+	gboolean all_support = TRUE;
+	JabberChatCapsData data;
+
+	chat_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
+	jb = jabber_buddy_find(chat->js, chat_jid, FALSE);
+
+	if (jb) {
+		data.cap = cap;
+		data.all_support = &all_support;
+		data.jb = jb;
+
+		g_hash_table_foreach(chat->members, 
+			jabber_chat_all_participants_have_capability_foreach, &data);
+	} else {
+		all_support = FALSE;
+	}
+	g_free(chat_jid);
+	return all_support;
+}
+
+guint
+jabber_chat_get_num_participants(const JabberChat *chat)
+{
+	return g_hash_table_size(chat->members);
+}
============================================================
--- libpurple/protocols/jabber/chat.h	1b58e910562b02a48d253ba6857a9acfa9670b64
+++ libpurple/protocols/jabber/chat.h	b208bfc5b773bcf3e0c60b65b028b4f853be9edc
@@ -95,5 +95,8 @@ char *jabber_roomlist_room_serialize(Pur
 
 char *jabber_roomlist_room_serialize(PurpleRoomlistRoom *room);
 
+gboolean jabber_chat_all_participants_have_capability(const JabberChat *chat,
+	const gchar *cap);
+guint jabber_chat_get_num_participants(const JabberChat *chat);
 
 #endif /* PURPLE_JABBER_CHAT_H_ */
============================================================
--- libpurple/protocols/jabber/jabber.c	4309ede5f6dfeb83d4a2169c5495a60b50cb244f
+++ libpurple/protocols/jabber/jabber.c	f61a71df206bfcebf263458cdb67d84177e88eb0
@@ -3359,7 +3359,7 @@ jabber_init_plugin(PurplePlugin *plugin)
 	jabber_add_feature(XEP_0224_NAMESPACE, jabber_buzz_isenabled);
 
 	/* Bits Of Binary */
-	jabber_add_feature(XEP_0231_NAMESPACE, jabber_custom_smileys_isenabled);
+	jabber_add_feature(XEP_0231_NAMESPACE, 0);
 
 	/* Jingle features! */
 	jabber_add_feature(JINGLE, 0);
============================================================
--- libpurple/protocols/jabber/message.c	ddcc5b005fa515cfef4849208c2bf972bd171e13
+++ libpurple/protocols/jabber/message.c	62c03ff25feb19dc484c4fe67f1ae5a045fd2f6d
@@ -921,11 +921,12 @@ jabber_conv_support_custom_smileys(const
 
 static gboolean
 jabber_conv_support_custom_smileys(const PurpleConnection *gc,
-								   const PurpleConversation *conv,
+								   PurpleConversation *conv,
 								   const gchar *who)
 {
 	JabberStream *js = (JabberStream *) gc->proto_data;
 	JabberBuddy *jb;
+	JabberChat *chat;
 
 	if (!js) {
 		purple_debug_error("jabber",
@@ -934,7 +935,6 @@ jabber_conv_support_custom_smileys(const
 	}
 
 	switch (purple_conversation_get_type(conv)) {
-		/* for the time being, we will not support custom smileys in MUCs */
 		case PURPLE_CONV_TYPE_IM:
 			jb = jabber_buddy_find(js, who, FALSE);
 			if (jb) {
@@ -943,6 +943,18 @@ jabber_conv_support_custom_smileys(const
 				return FALSE;
 			}
 			break;
+		case PURPLE_CONV_TYPE_CHAT:
+			chat = jabber_chat_find_by_conv(conv);
+			if (chat) {
+				/* do not attempt to send custom smileys in a MUC with more than
+				 10 people, to avoid getting too many BoB requests */
+				return jabber_chat_get_num_participants(chat) <= 10 &&
+					jabber_chat_all_participants_have_capability(chat, 
+						XEP_0231_NAMESPACE);
+			} else {
+				return FALSE;
+			}
+			break;
 		default:
 			return FALSE;
 			break;
@@ -1203,6 +1215,7 @@ int jabber_message_send_chat(PurpleConne
 	JabberMessage *jm;
 	JabberStream *js;
 	char *xhtml;
+	char *tmp;
 
 	if(!msg || !gc)
 		return 0;
@@ -1220,6 +1233,11 @@ int jabber_message_send_chat(PurpleConne
 	jm->id = jabber_get_next_id(jm->js);
 
 	purple_markup_html_to_xhtml(msg, &xhtml, &jm->body);
+	tmp = jabber_message_smileyfy_xhtml(jm, xhtml);
+	if (tmp) {
+		g_free(xhtml);
+		xhtml = tmp;
+	}
 
 	if (chat->xhtml && !jabber_xhtml_plain_equal(xhtml, jm->body))
 		jm->xhtml = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html>", xhtml);


More information about the Commits mailing list