From f26d9a3e54a89b640902d6ffad4f3d32b76dc97e Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 24 Nov 2012 14:10:34 +0000 Subject: Add help info for "stream" setting. Also, disable it for non-Twitter accounts. --- doc/user-guide/commands.xml | 15 +++++++++++++++ protocols/twitter/twitter.c | 21 ++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 7a4baa73..1f463815 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -1022,6 +1022,21 @@ + + + true + + + + For Twitter accounts, this setting enables use of the Streaming API. This automatically gives you incoming DMs as well. + + + + For other Twitter-like services, this setting is not supported. + + + + 20 diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 6bde497a..b7eacc4b 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -64,13 +64,17 @@ static void twitter_main_loop_start(struct im_connection *ic) imcb_log(ic, "Getting initial statuses"); - // Run this once. After this queue the main loop function. + // Run this once. After this queue the main loop function (or open the + // stream if available). twitter_main_loop(ic, -1, 0); if (set_getbool(&ic->acc->set, "stream")) { /* That fetch was just to get backlog, the stream will give us the rest. \o/ */ twitter_open_stream(ic); + + /* Stream sends keepalives (empty lines) or actual data at + least twice a minute. Disconnect if this stops. */ ic->flags |= OPT_PONGS; } else { /* Not using the streaming API, so keep polling the old- @@ -95,7 +99,6 @@ void twitter_login_finish(struct im_connection *ic) !(td->flags & TWITTER_HAVE_FRIENDS)) { imcb_log(ic, "Getting contact list"); twitter_get_friends_ids(ic, -1); - //twitter_get_statuses_friends(ic, -1); } else twitter_main_loop_start(ic); } @@ -288,12 +291,14 @@ static void twitter_init(account_t * acc) s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); - s = set_add(&acc->set, "stream", "true", set_eval_bool, acc); - s->flags |= ACC_SET_OFFLINE_ONLY; + if (strcmp(acc->prpl->name, "twitter") == 0) { + s = set_add(&acc->set, "stream", "true", set_eval_bool, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + } } /** - * Login method. Since the twitter API works with seperate HTTP request we + * Login method. Since the twitter API works with separate HTTP request we * only save the user and pass to the twitter_data object. */ static void twitter_login(account_t * acc) @@ -311,6 +316,12 @@ static void twitter_login(account_t * acc) return; } + if (!strstr(url.host, "twitter.com") && + set_getbool(&ic->acc->set, "stream")) { + imcb_error(ic, "Warning: The streaming API is only supported by Twitter, " + "and you seem to be connecting to a different service."); + } + imcb_log(ic, "Connecting"); twitter_connections = g_slist_append(twitter_connections, ic); -- cgit v1.2.3