Mercurial > pidgin-twitter
diff util.c @ 347:33d2551727ba
embed "in reply to foo" link to each reply message
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Mon, 14 Dec 2009 20:14:31 +0900 |
| parents | dbebabe99035 |
| children | 059e962ee26a |
line wrap: on
line diff
--- a/util.c Mon Dec 14 15:07:52 2009 +0900 +++ b/util.c Mon Dec 14 20:14:31 2009 +0900 @@ -529,23 +529,22 @@ twitter_rip_link_string(gchar **str) { GMatchInfo *match_info = NULL; - gchar *boddy0 = NULL, *boddy = NULL; + gchar *body0 = NULL, *body = NULL; gchar *newstr = NULL, *linkstr = NULL; - gchar *match = NULL; - gchar *idstr = NULL, *user = NULL; + gchar *user = NULL; twitter_debug("called\n"); - /* buffer without ptmsgid=123 */ - 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); + /* buffer without pttag= */ + body0 = g_regex_replace(regp[SENDER], *str, -1, 0, "", 0, NULL); + body = g_regex_replace(regp[PTTAG_TWITTER], body0, -1, 0, "", 0, NULL); + g_free(body0); + body0 = NULL; + twitter_debug("body = %s\n", body); - boddy0 = g_uri_escape_string(boddy, " !$()*,;:@/?#[]", TRUE); - g_free(boddy); - boddy = boddy0; + body0 = g_uri_escape_string(body, " !$()*,;:@/?#[]", TRUE); + g_free(body); + body = body0; /* sender */ g_regex_match(regp[SENDER], *str, 0, &match_info); @@ -557,36 +556,60 @@ } /* link string */ - g_regex_match(regp[MESSAGE_ID], *str, 0, &match_info); + g_regex_match(regp[PTTAG_TWITTER], *str, 0, &match_info); if(match_info) { - match = g_match_info_fetch(match_info, 1); - idstr = match ? match : "0"; - linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, - idstr, user, /* Reply */ - idstr, /* Favorite */ - idstr, /* Retweet */ - idstr, user, boddy); /* Quotetweet */ + gchar *msg_id_str = NULL; + gchar *in_reply_to_status_id_str = NULL; + long long unsigned int in_reply_to_status_id = 0; + + msg_id_str = g_match_info_fetch(match_info, 1); + in_reply_to_status_id_str = g_match_info_fetch(match_info, 2); + in_reply_to_status_id = strtoull(in_reply_to_status_id_str, NULL, 10); + g_free(in_reply_to_status_id_str); + in_reply_to_status_id_str = NULL; + + if(in_reply_to_status_id) { + gchar *in_reply_to_screen_name; + + in_reply_to_screen_name = g_match_info_fetch(match_info, 3); + linkstr = g_strdup_printf(IN_REPLY_TO_FORMAT_TWITTER LINK_FORMAT_TWITTER, + in_reply_to_screen_name, + in_reply_to_status_id, + in_reply_to_screen_name, + msg_id_str, user, /* Reply */ + msg_id_str, /* Favorite */ + msg_id_str, /* Retweet */ + msg_id_str, user, body); /* Quotetweet */ + + g_free(in_reply_to_screen_name); + in_reply_to_screen_name = NULL; + } + else { + linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, + msg_id_str, user, /* Reply */ + msg_id_str, /* Favorite */ + msg_id_str, /* Retweet */ + msg_id_str, user, body); /* Quotetweet */ + } twitter_debug("linkstr = %s\n", linkstr); - newstr = g_regex_replace(regp[MESSAGE_ID], *str, -1, 0, - "", - 0, NULL); + newstr = g_regex_replace(regp[PTTAG_TWITTER], *str, -1, 0, "", 0, NULL); twitter_debug("newstr = %s\n", newstr); g_free(*str); *str = newstr; - g_free(match); - match = NULL; + g_free(msg_id_str); + msg_id_str = NULL; g_match_info_free(match_info); match_info = NULL; } g_free(user); - g_free(boddy); + g_free(body); return linkstr; }
