Changeset 1201fcb for protocols


Ignore:
Timestamp:
2015-06-08T03:42:11Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
53c7799
Parents:
61e7e02
Message:

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.

Location:
protocols/twitter
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r61e7e02 r1201fcb  
    10121012                        twitter_log(ic, "Tweet `%s' does not exist", cmd[1]);
    10131013                } else {
    1014                         /* More common link is twitter.com/$UID/status/$ID (and that's
    1015                          * what this will 302 to) but can't generate that since for RTs,
    1016                          * bu here points at the retweeter while id contains the id of
    1017                          * the original message. */
    1018                         twitter_log(ic, "https://twitter.com/statuses/%lld", id);
     1014                        twitter_status_show_url(ic, id);
    10191015                }
    10201016                goto eof;
  • protocols/twitter/twitter_lib.c

    r61e7e02 r1201fcb  
    15731573        g_free(args[1]);
    15741574}
     1575
     1576static void twitter_http_status_show_url(struct http_request *req)
     1577{
     1578        struct im_connection *ic = req->data;
     1579        json_value *parsed, *id;
     1580        const char *name;
     1581
     1582        // Check if the connection is still active.
     1583        if (!g_slist_find(twitter_connections, ic)) {
     1584                return;
     1585        }
     1586
     1587        if (!(parsed = twitter_parse_response(ic, req))) {
     1588                return;
     1589        }
     1590
     1591        /* for the parson branch:
     1592        name = json_object_dotget_string(json_object(parsed), "user.screen_name");
     1593        id = json_object_get_integer(json_object(parsed), "id");
     1594        */
     1595
     1596        name = json_o_str(json_o_get(parsed, "user"), "screen_name");
     1597        id = json_o_get(parsed, "id");
     1598
     1599        if (name && id && id->type == json_integer) {
     1600                twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id->u.integer);
     1601        } else {
     1602                twitter_log(ic, "Error: could not fetch tweet url.");
     1603        }
     1604
     1605        json_value_free(parsed);
     1606}
     1607
     1608void twitter_status_show_url(struct im_connection *ic, guint64 id)
     1609{
     1610        char *url = g_strdup_printf("%s%" G_GUINT64_FORMAT "%s", TWITTER_STATUS_SHOW_URL, id, ".json");
     1611        twitter_http(ic, url, twitter_http_status_show_url, ic, 0, NULL, 0);
     1612        g_free(url);
     1613}
  • protocols/twitter/twitter_lib.h

    r61e7e02 r1201fcb  
    9696void twitter_report_spam(struct im_connection *ic, char *screen_name);
    9797void twitter_favourite_tweet(struct im_connection *ic, guint64 id);
     98void twitter_status_show_url(struct im_connection *ic, guint64 id);
    9899
    99100#endif //_TWITTER_LIB_H
Note: See TracChangeset for help on using the changeset viewer.