changeset 331:b4c846870b3c

improved handling of RT string
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 13 Oct 2009 02:45:03 +0900
parents cc41ee1f5d3a
children 227852ee649c
files main.c util.c util.h
diffstat 3 files changed, 31 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Mon Oct 12 21:51:13 2009 +0900
+++ b/main.c	Tue Oct 13 02:45:03 2009 +0900
@@ -362,6 +362,7 @@
     twitter_debug("called\n");
 
     gint service = get_service_type(conv);
+    gchar *linkstr = NULL, *tmpstr = NULL;
 
     /* check if the conversation is between twitter */
     if(service == unknown_service)
@@ -398,7 +399,8 @@
     } /* send */
 
     /* strip all markups */
-    strip_markup(buffer, TRUE);
+//    strip_markup(buffer, TRUE);
+    strip_markup(buffer, FALSE);
 
     /* playsound */
     if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) {
@@ -409,14 +411,8 @@
     }
 
     if(service == twitter_service) {
-        /* escape pseudo command (to show the same result as
-           sending message) */
-        if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
-            escape(buffer);
-        }
-
         /* replace ptmsgid=123 with appropriate links */
-        twitter_add_links(buffer);
+        linkstr = twitter_make_link_string(buffer);
     }
 
     /* translate */
@@ -446,7 +442,6 @@
         translate(buffer, GROUP_IDENTICA, service);
     }
 
-#if 0
     if(service == twitter_service) {
         /* escape pseudo command (to show the same result as
            sending message) */
@@ -454,10 +449,11 @@
             escape(buffer);
         }
 
-        /* replace ptmsgid=123 with appropriate links */
-        twitter_add_links(buffer);
+        tmpstr = g_strconcat(*buffer, linkstr, NULL);
+        g_free(linkstr);
+        g_free(*buffer);
+        *buffer = tmpstr;
     }
-#endif
 
     if(purple_prefs_get_bool(OPT_STRIP_EXCESS_LF)) {
         translate(buffer, EXCESS_LF, service);
--- a/util.c	Mon Oct 12 21:51:13 2009 +0900
+++ b/util.c	Tue Oct 13 02:45:03 2009 +0900
@@ -485,9 +485,12 @@
         return TRUE;
     }
     else if(strstr(cmd, "retweet-twitter")) {
+        gchar *msg0;
         sender = g_hash_table_lookup(params, "user");
         idstr = g_hash_table_lookup(params, "id");
-        msg = g_hash_table_lookup(params, "msg");
+        msg0 = g_hash_table_lookup(params, "msg");
+        msg = g_uri_unescape_string(msg0, NULL);
+
         if(idstr)
             msgid = strtoull(idstr, NULL, 10);
 
@@ -501,6 +504,7 @@
         twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid);
 
         recipient = g_strdup_printf("RT @%s: %s", sender, msg);
+        g_free(msg);
         gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
                                          recipient, -1);
 
@@ -516,11 +520,11 @@
     return FALSE;
 }
 
-void
-twitter_add_links(gchar **str)
+gchar *
+twitter_make_link_string(gchar **str)
 {
     GMatchInfo *match_info = NULL;
-    gchar *tmpstr0 = NULL, *tmpstr = NULL;
+    gchar *boddy0 = NULL, *boddy = NULL;
     gchar *newstr = NULL, *match = NULL;
     gchar *linkstr = NULL;
     gchar *user = NULL;
@@ -528,11 +532,15 @@
     twitter_debug("called\n");
 
     /* buffer without ptmsgid=123 */
-    tmpstr0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
-    tmpstr = g_regex_replace(regp[MESSAGE_ID], tmpstr0, -1, 0, "", 0, NULL);
-    g_free(tmpstr0);
-    tmpstr0 = NULL;
-    twitter_debug("tmpstr = %s\n", tmpstr);
+    boddy0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL);
+    boddy = g_regex_replace(regp[MESSAGE_ID], boddy0, -1, 0, "", 0, NULL);
+    g_free(boddy0);
+    boddy0 = NULL;
+    twitter_debug("boddy = %s\n", boddy);
+
+    boddy0 = g_uri_escape_string(boddy, " !$()*,;:@/?#[]", TRUE);
+    g_free(boddy);
+    boddy = boddy0;
 
     /* sender */
     g_regex_match(regp[SENDER], *str, 0, &match_info);
@@ -550,12 +558,12 @@
         linkstr = g_strdup_printf(LINK_FORMAT_TWITTER,
                                  match, user,          /* Reply */
                                  match,                /* Favorite */
-                                 match, user, tmpstr); /* Retweet */
+                                 match, user, boddy);  /* Retweet */
 
         twitter_debug("linkstr = %s\n", linkstr);
 
         newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0,
-                                 linkstr,
+                                 "",
                                  0, NULL);
 
         twitter_debug("newstr = %s\n", newstr);
@@ -563,8 +571,6 @@
         g_free(*str);
         *str = newstr;
 
-        g_free(linkstr);
-
         g_free(match);
         match = NULL;
 
@@ -573,5 +579,7 @@
     }
 
     g_free(user);
-    g_free(tmpstr);
+    g_free(boddy);
+
+    return linkstr;
 }
--- a/util.h	Mon Oct 12 21:51:13 2009 +0900
+++ b/util.h	Tue Oct 13 02:45:03 2009 +0900
@@ -5,7 +5,7 @@
 void strip_markup(gchar **str, gboolean escape);
 gchar *strip_html_markup(const gchar *src);
 gboolean ensure_path_exists(const char *dir);
-void twitter_add_links(gchar **str);
+gchar *twitter_make_link_string(gchar **str);
 
 gboolean is_twitter_conv(PurpleConversation *conv);
 gboolean is_wassr_account(PurpleAccount *account, const char *name);