# HG changeset patch # User Marcus Lundblad # Date 1242246543 0 # Node ID eeee4309d3d85ecf57bdd4ff9dc67ef84c3b00c5 # Parent 727d960a75a452f2b599ea001045da5e8b743d18 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. diff -r 727d960a75a4 -r eeee4309d3d8 ChangeLog --- a/ChangeLog Wed May 13 18:13:03 2009 +0000 +++ b/ChangeLog Wed May 13 20:29:03 2009 +0000 @@ -38,6 +38,9 @@ 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) diff -r 727d960a75a4 -r eeee4309d3d8 libpurple/protocols/jabber/buddy.c --- a/libpurple/protocols/jabber/buddy.c Wed May 13 18:13:03 2009 +0000 +++ b/libpurple/protocols/jabber/buddy.c Wed May 13 20:29:03 2009 +0000 @@ -74,7 +74,7 @@ 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); diff -r 727d960a75a4 -r eeee4309d3d8 libpurple/protocols/jabber/chat.c --- a/libpurple/protocols/jabber/chat.c Wed May 13 18:13:03 2009 +0000 +++ b/libpurple/protocols/jabber/chat.c Wed May 13 20:29:03 2009 +0000 @@ -1162,5 +1162,59 @@ 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); +} diff -r 727d960a75a4 -r eeee4309d3d8 libpurple/protocols/jabber/chat.h --- a/libpurple/protocols/jabber/chat.h Wed May 13 18:13:03 2009 +0000 +++ b/libpurple/protocols/jabber/chat.h Wed May 13 20:29:03 2009 +0000 @@ -95,5 +95,8 @@ 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_ */ diff -r 727d960a75a4 -r eeee4309d3d8 libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Wed May 13 18:13:03 2009 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed May 13 20:29:03 2009 +0000 @@ -3359,7 +3359,7 @@ 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); diff -r 727d960a75a4 -r eeee4309d3d8 libpurple/protocols/jabber/message.c --- a/libpurple/protocols/jabber/message.c Wed May 13 18:13:03 2009 +0000 +++ b/libpurple/protocols/jabber/message.c Wed May 13 20:29:03 2009 +0000 @@ -921,11 +921,12 @@ 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 @@ } 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 @@ 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 @@ JabberMessage *jm; JabberStream *js; char *xhtml; + char *tmp; if(!msg || !gc) return 0; @@ -1220,6 +1233,11 @@ 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("%s", xhtml);