/dev/tomkiewicz/new-smileys: 066c0f932b33: Smileys: MSN: reimple...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 4 20:29:50 EDT 2014


Changeset: 066c0f932b330f7209e695d2c1e01d30fd91419f
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-05 02:29 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/066c0f932b33

Description:

Smileys: MSN: reimplement msn_msg_grab_emoticons to use new API

diffstat:

 libpurple/protocols/jabber/message.c |   3 ++-
 libpurple/protocols/msn/msg.c        |   1 -
 libpurple/protocols/msn/msn.c        |  31 ++++++++++++-------------------
 libpurple/smiley-parser.c            |  13 ++++++++++---
 libpurple/smiley-parser.h            |   3 ++-
 5 files changed, 26 insertions(+), 25 deletions(-)

diffs (135 lines):

diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c
--- a/libpurple/protocols/jabber/message.c
+++ b/libpurple/protocols/jabber/message.c
@@ -941,7 +941,8 @@ jabber_message_smileyfy_xhtml(JabberMess
 	if (!jabber_conv_support_custom_smileys(jm->js, conv, jm->to))
 		return NULL;
 
-	found_smileys = purple_smiley_find(purple_smiley_custom_get_list(), xhtml);
+	found_smileys = purple_smiley_find(purple_smiley_custom_get_list(),
+		xhtml, TRUE);
 	if (!found_smileys)
 		return NULL;
 
diff --git a/libpurple/protocols/msn/msg.c b/libpurple/protocols/msn/msg.c
--- a/libpurple/protocols/msn/msg.c
+++ b/libpurple/protocols/msn/msg.c
@@ -1002,7 +1002,6 @@ void msn_emoticon_msg(MsnCmdProc *cmdpro
 			/* TODO: cache lookup by "sha1" */
 
 			/* XXX: maybe handle end_cb and smiley download failures? */
-			/* TODO: BUG: only emoticons from the first message are being received, others are not */
 			purple_debug_info("msn", "requesting smiley: %s", smile);
 			msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj);
 		}
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -38,6 +38,7 @@
 #include "session.h"
 #include "smiley.h"
 #include "smiley-custom.h"
+#include "smiley-parser.h"
 #include "state.h"
 #include "util.h"
 #include "cmds.h"
@@ -1469,28 +1470,19 @@ static void msn_emoticon_destroy(MsnEmot
 
 static GSList* msn_msg_grab_emoticons(const char *msg, const char *username)
 {
-	//TODO: replace it with:
-	//found_smileys = purple_smiley_find(purple_smiley_custom_get_list(), xhtml)
-	//but: is it xhtml?
-	GSList *list;
-	GList *smileys;
-	PurpleSmiley *smiley;
-	PurpleStoredImage *img;
-	char *ptr;
+	GSList *list = NULL;
+	GList *smileys, *it;
 	MsnEmoticon *emoticon;
 	int length;
 
-	list = NULL;
-	smileys = purple_smiley_list_get_all(purple_smiley_custom_get_list());
 	length = strlen(msg);
 
-	for (; smileys; smileys = g_list_delete_link(smileys, smileys)) {
-		smiley = smileys->data;
-
-		ptr = g_strstr_len(msg, length, purple_smiley_get_shortcut(smiley));
-
-		if (!ptr)
-			continue;
+	smileys = purple_smiley_find(purple_smiley_custom_get_list(),
+		msg, FALSE);
+
+	for (it = smileys; it; it = g_list_next(it)) {
+		PurpleSmiley *smiley = it->data;
+		PurpleStoredImage *img;
 
 		img = purple_smiley_get_image(smiley);
 
@@ -1498,11 +1490,12 @@ static GSList* msn_msg_grab_emoticons(co
 		emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley));
 		emoticon->ps = smiley;
 		emoticon->obj = msn_object_new_from_image(img,
-				purple_imgstore_get_filename(img),
-				username, MSN_OBJECT_EMOTICON);
+			purple_smiley_get_path(smiley),
+			username, MSN_OBJECT_EMOTICON);
 
 		list = g_slist_prepend(list, emoticon);
 	}
+	g_list_free(smileys);
 
 	return list;
 }
diff --git a/libpurple/smiley-parser.c b/libpurple/smiley-parser.c
--- a/libpurple/smiley-parser.c
+++ b/libpurple/smiley-parser.c
@@ -133,13 +133,15 @@ smiley_find_cb(const gchar *word, gpoint
 }
 
 GList *
-purple_smiley_find(PurpleSmileyList *smileys, const gchar *html_message)
+purple_smiley_find(PurpleSmileyList *smileys, const gchar *message,
+	gboolean is_html)
 {
 	PurpleTrie *trie;
 	GHashTable *found_smileys;
 	GList *found_list;
+	gchar *escaped_message = NULL;
 
-	if (html_message == NULL || html_message[0] == '\0')
+	if (message == NULL || message[0] == '\0')
 		return NULL;
 
 	if (smileys == NULL || purple_smiley_list_is_empty(smileys))
@@ -148,8 +150,13 @@ purple_smiley_find(PurpleSmileyList *smi
 	trie = purple_smiley_list_get_trie(smileys);
 	g_return_val_if_fail(trie != NULL, NULL);
 
+	if (!is_html)
+		message = escaped_message = g_markup_escape_text(message, -1);
+
 	found_smileys = g_hash_table_new(g_direct_hash, g_direct_equal);
-	purple_trie_find(trie, html_message, smiley_find_cb, found_smileys);
+	purple_trie_find(trie, message, smiley_find_cb, found_smileys);
+
+	g_free(escaped_message);
 
 	found_list = g_hash_table_get_values(found_smileys);
 	g_hash_table_destroy(found_smileys);
diff --git a/libpurple/smiley-parser.h b/libpurple/smiley-parser.h
--- a/libpurple/smiley-parser.h
+++ b/libpurple/smiley-parser.h
@@ -41,6 +41,7 @@ purple_smiley_parse(PurpleConversation *
 	gboolean use_remote_smileys, PurpleSmileyParseCb cb, gpointer ui_data);
 
 GList *
-purple_smiley_find(PurpleSmileyList *smileys, const gchar *html_message);
+purple_smiley_find(PurpleSmileyList *smileys, const gchar *message,
+	gboolean is_html);
 
 #endif /* _PURPLE_SMILEY_PARSER_H_ */



More information about the Commits mailing list