diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2015-05-03 18:47:19 +0200 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2015-05-03 18:47:19 +0200 |
commit | c43146d9308aea2025c0a0520c9e2d40758d9e8d (patch) | |
tree | 78d6beb3ba68cf62d5cb7ba31d23cefca95dbdbe | |
parent | cd607102faf6c6bfd1485a4a08d1ec70f9c22345 (diff) |
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.
-rw-r--r-- | protocols/twitter/twitter.c | 16 | ||||
-rw-r--r-- | protocols/twitter/twitter.h | 12 | ||||
-rw-r--r-- | protocols/twitter/twitter_lib.c | 2 |
3 files changed, 25 insertions, 5 deletions
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; diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index 7cfd9148..5a1a4f63 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -100,7 +100,9 @@ struct twitter_user_data { #define TWITTER_LOG_LENGTH 256 struct twitter_log_data { guint64 id; - struct bee_user *bu; /* DANGER: can be a dead pointer. Check it first. */ + /* DANGER: bu can be a dead pointer. Check it first. + * twitter_message_id_from_command_arg() will do this. */ + struct bee_user *bu; }; /** @@ -110,6 +112,14 @@ struct twitter_log_data { */ extern GSList *twitter_connections; +/** + * Evil hack: Fake bee_user which will always point at the local user. + * Sometimes used as a return value by twitter_message_id_from_command_arg. + * NOT thread safe but don't you dare to even think of ever making BitlBee + * threaded. :-) + */ +extern bee_user_t twitter_log_local_user; + void twitter_login_finish(struct im_connection *ic); struct http_request; diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 536d88d8..17bceb9f 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -700,6 +700,8 @@ static char *twitter_msg_add_id(struct im_connection *ic, original tweet's id should be remembered for deduplicating. */ if (g_strcasecmp(txs->user->screen_name, td->user) == 0) { td->log[td->log_id].id = txs->rt_id; + /* More useful than NULL. */ + td->log[td->log_id].bu = &twitter_log_local_user; } if (set_getbool(&ic->acc->set, "show_ids")) { |