aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-06-08 00:42:11 -0300
committerdequis <dx@dxzone.com.ar>2015-06-08 00:42:11 -0300
commit1201fcb6272cdba734594f9358ba2d08db1afec9 (patch)
treefafd01c3ca58fd33f4bb0ad0c1439931456748cf
parent61e7e02096c7910addba32a9060a5e0cba68284b (diff)
twitter: show full url in the url command, with username
By asking the server for the username. Storing the username somewhere would have made sense, but this command isn't going to be used very often, so, whatever.
-rw-r--r--protocols/twitter/twitter.c6
-rw-r--r--protocols/twitter/twitter_lib.c39
-rw-r--r--protocols/twitter/twitter_lib.h1
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