From 9ed817598e0f46b786ab988098ea25294a53e151 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 2 May 2015 23:03:35 +0200 Subject: Add "url" command to Twitter module to get web URL for a Tweet. --- protocols/twitter/twitter.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'protocols/twitter/twitter.c') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 95384573..4dc1785e 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -1002,6 +1002,19 @@ static void twitter_handle_command(struct im_connection *ic, char *message) message = cmd[2]; in_reply_to = id; allow_post = TRUE; + } else if (g_strcasecmp(cmd[0], "url") == 0) { + id = twitter_message_id_from_command_arg(ic, cmd[1], &bu); + 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); + } + goto eof; + } else if (g_strcasecmp(cmd[0], "post") == 0) { message += 5; allow_post = TRUE; -- cgit v1.2.3 From c43146d9308aea2025c0a0520c9e2d40758d9e8d Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sun, 3 May 2015 18:47:19 +0200 Subject: Make replies to self work in Twitter. Difficult because there's no bee_user struct pointing at the user themselves so instead just fake one for very limited use. --- protocols/twitter/twitter.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'protocols/twitter/twitter.c') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 4dc1785e..421a0552 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -866,6 +866,8 @@ static gboolean twitter_parse_id(char *string, int base, guint64 *id) return TRUE; } +bee_user_t twitter_log_local_user; + /** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID * into a twitter tweet ID. * @@ -896,10 +898,6 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { bu = td->log[id].bu; id = td->log[id].id; - /* Beware of dangling pointers! */ - if (!g_slist_find(ic->bee->users, bu)) { - bu = NULL; - } } else if (twitter_parse_id(arg, 10, &id)) { /* Allow normal tweet IDs as well; not a very useful feature but it's always been there. Just ignore @@ -910,6 +908,16 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha } } if (bu_) { + if (bu == &twitter_log_local_user) { + /* HACK alert. There's no bee_user object for the local + * user so just fake one for the few cmds that need it. */ + twitter_log_local_user.handle = td->user; + } else { + /* Beware of dangling pointers! */ + if (!g_slist_find(ic->bee->users, bu)) { + bu = NULL; + } + } *bu_ = bu; } return id; -- cgit v1.2.3