aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/twitter
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2011-03-29 00:28:46 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2011-03-29 00:28:46 +0100
commitce81acd6242513c5fcf6cf2224f9b1137701e14e (patch)
treec7749cd23ae2d57ab3c6cde0ba4818381a000bfa /protocols/twitter
parentf01bc6f174e15d5dcc530a0136a556bfbc22d236 (diff)
For #721, add the numbers in front of tweets if show_ids is enabled. Left
to do: Document the feature and allow using the numbers in rt/replies.
Diffstat (limited to 'protocols/twitter')
-rw-r--r--protocols/twitter/twitter.c7
-rw-r--r--protocols/twitter/twitter.h12
-rw-r--r--protocols/twitter/twitter_lib.c70
3 files changed, 78 insertions, 11 deletions
diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c
index 63f648df..f4230cf7 100644
--- a/protocols/twitter/twitter.c
+++ b/protocols/twitter/twitter.c
@@ -244,6 +244,9 @@ static void twitter_init( account_t *acc )
s = set_add( &acc->set, "mode", "chat", set_eval_mode, acc );
s->flags |= ACC_SET_OFFLINE_ONLY;
+ s = set_add( &acc->set, "show_ids", "false", set_eval_bool, acc );
+ s->flags |= ACC_SET_OFFLINE_ONLY;
+
s = set_add( &acc->set, "oauth", def_oauth, set_eval_bool, acc );
}
@@ -290,6 +293,9 @@ static void twitter_login( account_t *acc )
imcb_add_buddy( ic, name, NULL );
imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL );
+ if( set_getbool( &acc->set, "show_ids" ) )
+ td->log = g_new0( struct twitter_log_data, TWITTER_LOG_LENGTH );
+
imcb_log( ic, "Connecting" );
twitter_login_finish( ic );
@@ -318,6 +324,7 @@ static void twitter_logout( struct im_connection *ic )
g_free( td->url_host );
g_free( td->url_path );
g_free( td->pass );
+ g_free( td->log );
g_free( td );
}
diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h
index 98f16835..1fddcbd1 100644
--- a/protocols/twitter/twitter.h
+++ b/protocols/twitter/twitter.h
@@ -37,6 +37,8 @@ typedef enum
TWITTER_HAVE_FRIENDS = 1,
} twitter_flags_t;
+struct twitter_log_data;
+
struct twitter_data
{
char* user;
@@ -55,6 +57,9 @@ struct twitter_data
char *url_path;
char *prefix; /* Used to generate contact + channel name. */
+
+ struct twitter_log_data *log;
+ int log_id;
};
struct twitter_user_data
@@ -63,6 +68,13 @@ struct twitter_user_data
time_t last_time;
};
+#define TWITTER_LOG_LENGTH 100
+struct twitter_log_data
+{
+ guint64 id;
+ struct bee_user *bu;
+};
+
/**
* This has the same function as the msn_connections GSList. We use this to
* make sure the connection is still alive in callbacks before we do anything
diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c
index c8e4e76d..e8fb3530 100644
--- a/protocols/twitter/twitter_lib.c
+++ b/protocols/twitter/twitter_lib.c
@@ -66,7 +66,7 @@ struct twitter_xml_status {
time_t created_at;
char *text;
struct twitter_xml_user *user;
- guint64 id;
+ guint64 id, reply_to;
};
static void twitter_groupchat_init(struct im_connection *ic);
@@ -409,6 +409,10 @@ static xt_status twitter_xt_get_status( struct xt_node *node, struct twitter_xml
{
txs->id = g_ascii_strtoull (child->text, NULL, 10);
}
+ else if (g_strcasecmp( "in_reply_to_status_id", child->name ) == 0)
+ {
+ txs->reply_to = g_ascii_strtoull (child->text, NULL, 10);
+ }
}
/* If it's a truncated retweet, get the original because dots suck. */
@@ -501,6 +505,41 @@ void twitter_get_home_timeline(struct im_connection *ic, gint64 next_cursor)
}
}
+static char *twitter_msg_add_id(struct im_connection *ic,
+ struct twitter_xml_status *txs, const char *prefix)
+{
+ struct twitter_data *td = ic->proto_data;
+ char *ret = NULL;
+
+ if (!set_getbool(&ic->acc->set, "show_ids"))
+ {
+ if (*prefix)
+ return g_strconcat(prefix, txs->text, NULL);
+ else
+ return NULL;
+ }
+
+ td->log[td->log_id].id = txs->id;
+ td->log[td->log_id].bu = bee_user_by_handle(ic->bee, ic, txs->user->screen_name);
+ if (txs->reply_to)
+ {
+ int i;
+ for (i = 0; i < TWITTER_LOG_LENGTH; i ++)
+ if (td->log[i].id == txs->reply_to)
+ {
+ ret = g_strdup_printf( "\002[\002%02d->%02d\002]\002 %s%s",
+ td->log_id, i, prefix, txs->text);
+ break;
+ }
+ }
+ if (ret == NULL)
+ ret = g_strdup_printf( "\002[\002%02d\002]\002 %s%s",
+ td->log_id, prefix, txs->text);
+ td->log_id = (td->log_id + 1) % TWITTER_LOG_LENGTH;
+
+ return ret;
+}
+
static void twitter_groupchat_init(struct im_connection *ic)
{
char *name_hint;
@@ -542,6 +581,8 @@ static void twitter_groupchat(struct im_connection *ic, GSList *list)
for ( l = list; l ; l = g_slist_next(l) )
{
+ char *msg;
+
status = l->data;
if (status->user == NULL || status->text == NULL)
continue;
@@ -549,16 +590,20 @@ static void twitter_groupchat(struct im_connection *ic, GSList *list)
twitter_add_buddy(ic, status->user->screen_name, status->user->name);
strip_html(status->text);
+ msg = twitter_msg_add_id(ic, status, "");
// Say it!
if (g_strcasecmp(td->user, status->user->screen_name) == 0)
- imcb_chat_log (gc, "You: %s", status->text);
+ imcb_chat_log(gc, "You: %s", msg ? msg : status->text);
else
- imcb_chat_msg (gc, status->user->screen_name, status->text, 0, status->created_at );
+ imcb_chat_msg(gc, status->user->screen_name,
+ msg ? msg : status->text, 0, status->created_at );
+
+ g_free(msg);
// Update the home_timeline_id to hold the highest id, so that by the next request
- // we won't pick up the updates allready in the list.
- td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
+ // we won't pick up the updates already in the list.
+ td->home_timeline_id = MAX(td->home_timeline_id, status->id);
}
}
@@ -583,27 +628,30 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList *list)
for ( l = list; l ; l = g_slist_next(l) )
{
- char *text = NULL;
+ char *prefix = NULL, *text = NULL;
status = l->data;
strip_html( status->text );
if( mode_one )
- text = g_strdup_printf( "\002<\002%s\002>\002 %s",
- status->user->screen_name, status->text );
+ prefix = g_strdup_printf("\002<\002%s\002>\002 ",
+ status->user->screen_name);
else
twitter_add_buddy(ic, status->user->screen_name, status->user->name);
+ text = twitter_msg_add_id(ic, status, prefix ? prefix : "");
+
imcb_buddy_msg( ic,
mode_one ? from : status->user->screen_name,
- mode_one ? text : status->text,
+ text ? text : status->text,
0, status->created_at );
// Update the home_timeline_id to hold the highest id, so that by the next request
- // we won't pick up the updates allready in the list.
- td->home_timeline_id = td->home_timeline_id < status->id ? status->id : td->home_timeline_id;
+ // we won't pick up the updates already in the list.
+ td->home_timeline_id = MAX(td->home_timeline_id, status->id);
g_free( text );
+ g_free( prefix );
}
}