diff options
-rw-r--r-- | protocols/twitter/twitter.c | 6 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 39 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.h | 1 |
3 files changed, 41 insertions, 5 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 7eb948ad..b619b1e5 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -1011,11 +1011,7 @@ static void twitter_handle_command(struct im_connection *ic, char *message) if (!id) { twitter_log(ic, "Tweet `%s' does not exist", cmd[1]); } else { - /* More common link is twitter.com/$UID/status/$ID (and that's - * what this will 302 to) but can't generate that since for RTs, - * bu here points at the retweeter while id contains the id of - * the original message. */ - twitter_log(ic, "https://twitter.com/statuses/%lld", id); + twitter_status_show_url(ic, id); } goto eof; diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 17bceb9f..40adb992 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -1572,3 +1572,42 @@ void twitter_favourite_tweet(struct im_connection *ic, guint64 id) ic, 1, args, 2, TWITTER_HTTP_USER_ACK); g_free(args[1]); } + +static void twitter_http_status_show_url(struct http_request *req) +{ + struct im_connection *ic = req->data; + json_value *parsed, *id; + const char *name; + + // Check if the connection is still active. + if (!g_slist_find(twitter_connections, ic)) { + return; + } + + if (!(parsed = twitter_parse_response(ic, req))) { + return; + } + + /* for the parson branch: + name = json_object_dotget_string(json_object(parsed), "user.screen_name"); + id = json_object_get_integer(json_object(parsed), "id"); + */ + + name = json_o_str(json_o_get(parsed, "user"), "screen_name"); + id = json_o_get(parsed, "id"); + + if (name && id && id->type == json_integer) { + twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id->u.integer); + } else { + twitter_log(ic, "Error: could not fetch tweet url."); + } + + json_value_free(parsed); +} + +void twitter_status_show_url(struct im_connection *ic, guint64 id) +{ + char *url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", TWITTER_STATUS_SHOW_URL, id, ".json"); + twitter_http(ic, url, twitter_http_status_show_url, ic, 0, NULL, 0); + g_free(url); +} diff --git a/protocols/twitter/twitter_lib.h b/protocols/twitter/twitter_lib.h index ee103100..002376b1 100644 --- a/protocols/twitter/twitter_lib.h +++ b/protocols/twitter/twitter_lib.h @@ -95,6 +95,7 @@ void twitter_status_destroy(struct im_connection *ic, guint64 id); void twitter_status_retweet(struct im_connection *ic, guint64 id); void twitter_report_spam(struct im_connection *ic, char *screen_name); void twitter_favourite_tweet(struct im_connection *ic, guint64 id); +void twitter_status_show_url(struct im_connection *ic, guint64 id); #endif //_TWITTER_LIB_H |