diff options
Diffstat (limited to 'protocols/twitter/twitter.c')
| -rw-r--r-- | protocols/twitter/twitter.c | 105 | 
1 files changed, 95 insertions, 10 deletions
| diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 8bc6140a..9d3b743c 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -304,7 +304,7 @@ static void twitter_main_loop_start(struct im_connection *ic)  struct groupchat *twitter_groupchat_init(struct im_connection *ic)  { -	char *name_hint; +	char *name_hint, *tmp;  	struct groupchat *gc;  	struct twitter_data *td = ic->proto_data;  	GSList *l; @@ -315,7 +315,14 @@ struct groupchat *twitter_groupchat_init(struct im_connection *ic)  	td->timeline_gc = gc = imcb_chat_new(ic, "twitter/timeline"); -	name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user); +	tmp = set_getstr(&ic->acc->set, "channel_name"); +	 +	if (tmp == NULL || strlen(tmp) == 0) { +		name_hint = g_strdup_printf("%s_%s", td->prefix, ic->acc->user); +	} else { +		name_hint = g_strdup(tmp); +	} +  	imcb_chat_name_hint(gc, name_hint);  	g_free(name_hint); @@ -343,8 +350,10 @@ void twitter_login_finish(struct im_connection *ic)  	} else if (!(td->flags & TWITTER_MODE_ONE) &&  	           !(td->flags & TWITTER_HAVE_FRIENDS)) {  		imcb_log(ic, "Getting contact list"); +  		twitter_get_friends_ids(ic, -1);  		twitter_get_mutes_ids(ic, -1); +		twitter_get_blocks_ids(ic, -1);  		twitter_get_noretweets_ids(ic, -1);  	} else {  		twitter_main_loop_start(ic); @@ -518,6 +527,23 @@ static char *set_eval_commands(set_t * set, char *value)  	}  } +static char *set_eval_channel_name(set_t * set, char *value) +{ +	size_t len; + +	if (value == NULL) { +		return NULL; +	} + +	len = strlen(value); + +	if (len < MAX_NICK_LENGTH && len > 0) { +		return value; +	} else { +		return NULL; +	} +} +  static char *set_eval_mode(set_t * set, char *value)  {  	if (g_strcasecmp(value, "one") == 0 || @@ -528,6 +554,15 @@ static char *set_eval_mode(set_t * set, char *value)  	}  } +static char *set_eval_id_length(set_t * set, char *value) +{ +	int len = atoi(value); +	if (len >= 1 || len <= 4) +		return value; + +	return SET_INVALID; +} +  static void twitter_init(account_t * acc)  {  	set_t *s; @@ -572,6 +607,12 @@ static void twitter_init(account_t * acc)  	s = set_add(&acc->set, "strip_newlines", "false", set_eval_bool, acc); +	s = set_add(&acc->set, "id_length", "2", set_eval_id_length, acc); +	s->flags |= ACC_SET_OFFLINE_ONLY; + +	s = set_add(&acc->set, "channel_name", NULL, set_eval_channel_name, acc); +	s->flags |= ACC_SET_OFFLINE_ONLY; +  	s = set_add(&acc->set, "_last_tweet", "0", NULL, acc);  	s->flags |= SET_HIDDEN | SET_NOSAVE; @@ -592,6 +633,7 @@ static void twitter_login(account_t * acc)  	char name[strlen(acc->user) + 9];  	url_t url;  	char *s; +	size_t i;  	if (!url_set(&url, set_getstr(&ic->acc->set, "base_url")) ||  	    (url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS)) { @@ -649,8 +691,17 @@ static void twitter_login(account_t * acc)  	imcb_add_buddy(ic, name, NULL);  	imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL); -	td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH); +	td->id_length = set_getint(&ic->acc->set, "id_length"); +	td->log_length = 0; +	for (i = 0; i < td->id_length; i++) { +		td->log_length = (td->log_length << 4) + 0x0F; +	} +	td->log_length += 1; + +	td->log = g_new0(struct twitter_log_data, td->log_length); +	td->filter_log = g_new0(struct twitter_log_data, td->log_length);  	td->log_id = -1; +	td->filter_log_id = -1;  	s = set_getstr(&ic->acc->set, "mode");  	if (g_strcasecmp(s, "one") == 0) { @@ -661,6 +712,10 @@ static void twitter_login(account_t * acc)  		td->flags |= TWITTER_MODE_CHAT;  	} +	td->mutes_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); +	td->blocks_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); +	td->noretweets_ids = g_hash_table_new_full(g_str_hash, (GEqualFunc)strcmp, (GDestroyNotify)g_free, NULL); +  	twitter_login_finish(ic);  } @@ -686,11 +741,9 @@ static void twitter_logout(struct im_connection *ic)  			b_event_remove(td->filter_update_id);  		} -		g_slist_foreach(td->mutes_ids, (GFunc) g_free, NULL); -		g_slist_free(td->mutes_ids); - -		g_slist_foreach(td->noretweets_ids, (GFunc) g_free, NULL); -		g_slist_free(td->noretweets_ids); +		g_hash_table_unref(td->mutes_ids); +		g_hash_table_unref(td->blocks_ids); +		g_hash_table_unref(td->noretweets_ids);  		http_close(td->stream);  		twitter_filter_remove_all(ic); @@ -894,7 +947,7 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha  		if (arg[0] == '#') {  			arg++;  		} -		if (parse_int64(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { +		if (parse_int64(arg, 16, &id) && id < td->log_length) {  			bu = td->log[id].bu;  			id = td->log[id].id;  		} else if (parse_int64(arg, 10, &id)) { @@ -985,7 +1038,8 @@ static void twitter_handle_command(struct im_connection *ic, char *message)  		twitter_report_spam(ic, screen_name);  		goto eof; -	} else if (g_strcasecmp(cmd[0], "rt") == 0 && cmd[1]) { +	} else if ((g_strcasecmp(cmd[0], "rt") == 0 || +		    g_strcasecmp(cmd[0], "retweet") == 0) && cmd[1]) {  		id = twitter_message_id_from_command_arg(ic, cmd[1], NULL);  		td->last_status_id = 0; @@ -1024,12 +1078,43 @@ static void twitter_handle_command(struct im_connection *ic, char *message)  			twitter_status_show_url(ic, id);  		}  		goto eof; +	} else if (g_strcasecmp(cmd[0], "quote") == 0 && cmd[1]) { +		id = twitter_message_id_from_command_arg(ic, cmd[1], NULL); + +		td->last_status_id = 0; +		if (id) { +			twitter_status_quote_post(ic, id, cmd[2]); +		} else { +			twitter_log(ic, "User '%s' does not exist or didn't " +				    "post any statuses recently", cmd[1]); +		} +		goto eof;  	} else if (g_strcasecmp(cmd[0], "post") == 0) {  		message += 5;  		allow_post = TRUE; +	} else if (g_strcasecmp(cmd[0], "dm") == 0 && cmd[1] && cmd[2]) { +		if ((bu = bee_user_by_handle(ic->bee, ic, cmd[1]))) { +			twitter_direct_messages_new(ic, bu->handle, cmd[2]); +		} else { +			twitter_direct_messages_new(ic, cmd[1], cmd[2]); +		} +		goto eof; +	} else if (g_strcasecmp(cmd[0], "rtoff") == 0 && cmd[1]) { +		twitter_retweet_enable_disable(ic, cmd[1], 0); +		goto eof; +	} else if (g_strcasecmp(cmd[0], "rton") == 0 && cmd[1]) { +		twitter_retweet_enable_disable(ic, cmd[1], 1); +		goto eof; +	} else if (g_strcasecmp(cmd[0], "block") == 0 && cmd[1]) { +		twitter_block_create_destroy(ic, cmd[1], 1); +		goto eof; +	} else if (g_strcasecmp(cmd[0], "unblock") == 0 && cmd[1]) { +		twitter_block_create_destroy(ic, cmd[1], 0); +		goto eof;  	} +  	if (allow_post) {  		char *s; | 
