aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroger <roger@elvex.org.ar>2015-01-16 16:50:24 -0300
committerdequis <dx@dxzone.com.ar>2015-01-16 16:50:24 -0300
commit7549d0074aa4917e62106ac285b05baa1e76c1e9 (patch)
tree59180b84a6a987133c7b61185d3ff8dd4a87f83f
parent885d294fad822b5275a68127ab2ab925d1df1a0e (diff)
twitter: start stream from last tweet on connect/reconnect
This works by setting the last_tweet hidden account setting to the ID of the last shown tweet.
-rw-r--r--protocols/twitter/twitter.c7
-rw-r--r--protocols/twitter/twitter_lib.c7
2 files changed, 13 insertions, 1 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index ca32b3ce..8e3fec77 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -50,6 +50,10 @@ static void twitter_main_loop_start(struct im_connection *ic)
{
struct twitter_data *td = ic->proto_data;
+ char *last_tweet = set_getstr(&ic->acc->set, "last_tweet");
+ if (last_tweet)
+ td->timeline_id = g_ascii_strtoull(last_tweet, NULL, 0);
+
/* Create the room now that we "logged in". */
if (td->flags & TWITTER_MODE_CHAT)
twitter_groupchat_init(ic);
@@ -326,6 +330,9 @@ static void twitter_init(account_t * acc)
s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc);
+ s = set_add(&acc->set, "last_tweet", "0", NULL, acc);
+ s->flags |= SET_HIDDEN;
+
if (strcmp(acc->prpl->name, "twitter") == 0) {
s = set_add(&acc->set, "stream", "true", set_eval_bool, acc);
s->flags |= ACC_SET_OFFLINE_ONLY;
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index b1995e73..3d579d7c 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -720,6 +720,7 @@ static void twitter_status_show_msg(struct im_connection *ic, struct twitter_xml
static void twitter_status_show(struct im_connection *ic, struct twitter_xml_status *status)
{
struct twitter_data *td = ic->proto_data;
+ char *last_id_str;
if (status->user == NULL || status->text == NULL)
return;
@@ -737,6 +738,10 @@ static void twitter_status_show(struct im_connection *ic, struct twitter_xml_sta
// Update the timeline_id to hold the highest id, so that by the next request
// we won't pick up the updates already in the list.
td->timeline_id = MAX(td->timeline_id, status->rt_id);
+
+ last_id_str = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
+ set_setstr(&ic->acc->set, "last_tweet", last_id_str);
+ g_free(last_id_str);
}
static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o);
@@ -1001,7 +1006,7 @@ static void twitter_get_home_timeline(struct im_connection *ic, gint64 next_curs
args[3] = "true";
if (td->timeline_id) {
args[4] = "since_id";
- args[5] = g_strdup_printf("%llu", (long long unsigned int) td->timeline_id);
+ args[5] = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
}
if (twitter_http(ic, TWITTER_HOME_TIMELINE_URL, twitter_http_get_home_timeline, ic, 0, args,