diff options
author | William Pettersson <william.pettersson@gmail.com> | 2015-01-11 15:08:37 +1000 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-01-26 04:50:54 -0300 |
commit | ce402b20d82ec323e6bd5e306de934773590742d (patch) | |
tree | 10e545944b9602a53300e97354f011395d2b0afd /protocols/twitter/twitter_lib.c | |
parent | dfaa46d37c5a71e7d8c413c7c9714db854b8b559 (diff) |
Twitter format strings
Allow users to specify how tweets should be displayed
3 new settings are available to set how tweets are displayed:
- twitter_format_string for normal tweets
- retweet_format_string for retweets
- reply_format_string for replies
For full documentation see the help files
Diffstat (limited to 'protocols/twitter/twitter_lib.c')
-rw-r--r-- | protocols/twitter/twitter_lib.c | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index c8956606..b827a139 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -62,6 +62,7 @@ struct twitter_xml_status { guint64 id, rt_id; /* Usually equal, with RTs id == *original* id */ guint64 reply_to; gboolean from_filter; + struct twitter_xml_status *rt; }; /** @@ -87,6 +88,7 @@ static void txs_free(struct twitter_xml_status *txs) g_free(txs->text); txu_free(txs->user); + txs_free(txs->rt); g_free(txs); } @@ -488,9 +490,9 @@ static struct twitter_xml_status *twitter_xt_get_status(const json_value *node) struct twitter_xml_status *rtxs = twitter_xt_get_status(rt); if (rtxs) { g_free(txs->text); - txs->text = g_strdup_printf("RT @%s: %s", rtxs->user->screen_name, rtxs->text); + txs->text = g_strdup(rtxs->text); txs->id = rtxs->id; - txs_free(rtxs); + txs->rt = rtxs; } } else if (entities) { txs->text = expand_entities(txs->text, entities); @@ -608,6 +610,49 @@ static gboolean twitter_xt_get_status_list(struct im_connection *ic, const json_ return TRUE; } +/** + * Function to properly format a tweet as per the users configuration. + */ +static char *twitter_msg_get_text(struct im_connection *ic, int log_id, int reply_to, + struct twitter_xml_status *txs, const char *prefix) { + gchar * format = set_getstr(&ic->acc->set, "format_string"); + GString * text = g_string_new(NULL); + + gchar *c; + if (reply_to != -1) + format = set_getstr(&ic->acc->set, "reply_format_string"); + if (txs->rt) + format = set_getstr(&ic->acc->set, "retweet_format_string"); + + for (c = format; *c ; c++) { + if (!(*c == '%' && *(c+1))) { + text = g_string_append_c(text, *c); + continue; + } + c++; // Move past the % + switch (*c) { + case 'i': + g_string_append_printf(text, "%02x", log_id); + break; + case 'r': + if (reply_to != -1) // In case someone does put %r in the wrong format_string + g_string_append_printf(text, "%02x", reply_to); + break; + case 'a': + if (txs->rt) // In case someone does put %a in the wrong format_string + text = g_string_append(text, txs->rt->user->screen_name); + break; + case 'c': + text = g_string_append(text, txs->text); + break; + default: + text = g_string_append_c(text, *c); + } + } + text = g_string_prepend(text, prefix); + return g_string_free(text, FALSE); +} + /* Will log messages either way. Need to keep track of IDs for stream deduping. Plus, show_ids is on by default and I don't see why anyone would disable it. */ static char *twitter_msg_add_id(struct im_connection *ic, @@ -646,19 +691,7 @@ static char *twitter_msg_add_id(struct im_connection *ic, if (g_strcasecmp(txs->user->screen_name, td->user) == 0) td->log[td->log_id].id = txs->rt_id; - if (set_getbool(&ic->acc->set, "show_ids")) { - if (reply_to != -1) - return g_strdup_printf("\002[\002%02x->%02x\002]\002 %s%s", - td->log_id, reply_to, prefix, txs->text); - else - return g_strdup_printf("\002[\002%02x\002]\002 %s%s", - td->log_id, prefix, txs->text); - } else { - if (*prefix) - return g_strconcat(prefix, txs->text, NULL); - else - return NULL; - } + return twitter_msg_get_text(ic, td->log_id, reply_to, txs, prefix); } /** |