From f60079b74053a53da3720b992c603fddf75ff1dd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Tue, 25 May 2010 23:26:54 +0100 Subject: Allow one to run the configure script from a different directory and put all build files in there. I need this to properly make Debian package variants (i.e. libpurple and native). --- protocols/twitter/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'protocols/twitter') diff --git a/protocols/twitter/Makefile b/protocols/twitter/Makefile index ca1e4695..8a4b97f9 100644 --- a/protocols/twitter/Makefile +++ b/protocols/twitter/Makefile @@ -7,6 +7,9 @@ ### DEFINITIONS -include ../../Makefile.settings +ifdef SRCDIR +SRCDIR := $(SRCDIR)protocols/twitter/ +endif # [SH] Program variables objects = twitter.o twitter_http.o twitter_lib.o @@ -32,7 +35,7 @@ distclean: clean $(objects): ../../Makefile.settings Makefile -$(objects): %.o: %.c +$(objects): %.o: $(SRCDIR)%.c @echo '*' Compiling $< @$(CC) -c $(CFLAGS) $< -o $@ -- cgit v1.2.3 From 534e4069e0cfa8aee82f82603dc3ca05562a85dd Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 10 Jul 2010 01:30:39 +0100 Subject: Translate "nick:" to "@nick" in Twitter rooms to make tab completion easier. Not working yet with stripped/mangled nicknames. --- protocols/twitter/twitter.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'protocols/twitter') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 2e3ab634..f3fe8922 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -315,8 +315,28 @@ static void twitter_remove_buddy( struct im_connection *ic, char *who, char *gro static void twitter_chat_msg( struct groupchat *c, char *message, int flags ) { - if( c && message && twitter_length_check(c->ic, message)) - twitter_post_status(c->ic, message); + if( c && message && twitter_length_check( c->ic, message ) ) + { + char *s, *new = NULL; + + if( ( s = strchr( message, ':' ) ) || + ( s = strchr( message, ',' ) ) ) + { + bee_user_t *bu; + + new = g_strdup( message ); + new[s-message] = '\0'; + if( ( bu = bee_user_by_handle( c->ic->bee, c->ic, new ) ) ) + { + sprintf( new, "@%s", bu->handle ); + new[s-message+1] = ' '; + message = new; + } + } + + twitter_post_status( c->ic, message ); + g_free( new ); + } } static void twitter_chat_invite( struct groupchat *c, char *who, char *message ) -- cgit v1.2.3 From ffcdf1329ad0401ace5a0355160ac7c249869431 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 17 Jul 2010 16:06:56 +0100 Subject: When using non-Twitter Twitter API services, prefix the channel and contact name with that service name, not always Twitter. This is especially useful when having multiple accounts on different sites with the same username. Also adding an "identica" protocol entry for convenience. Based on a patch from kensanata, bug #648. --- protocols/twitter/twitter.c | 37 ++++++++++++++++++++++++++++++------- protocols/twitter/twitter.h | 2 ++ protocols/twitter/twitter_lib.c | 4 ++-- protocols/twitter/twitter_lib.h | 1 + 4 files changed, 35 insertions(+), 9 deletions(-) (limited to 'protocols/twitter') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index f3fe8922..f718eeb7 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -118,7 +118,7 @@ static gboolean twitter_oauth_callback( struct oauth_info *info ) return FALSE; } - sprintf( name, "twitter_%s", ic->acc->user ); + sprintf( name, "%s_%s", td->prefix, ic->acc->user ); msg = g_strdup_printf( "To finish OAuth authentication, please visit " "%s and respond with the resulting PIN code.", info->auth_url ); @@ -171,8 +171,21 @@ static gboolean twitter_length_check( struct im_connection *ic, gchar *msg ) static void twitter_init( account_t *acc ) { set_t *s; + char *def_url; + char *def_oauth; - s = set_add( &acc->set, "base_url", TWITTER_API_URL, NULL, acc ); + if( strcmp( acc->prpl->name, "twitter" ) == 0 ) + { + def_url = TWITTER_API_URL; + def_oauth = "true"; + } + else /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */ + { + def_url = IDENTICA_API_URL; + def_oauth = "false"; + } + + s = set_add( &acc->set, "base_url", def_url, NULL, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add( &acc->set, "message_length", "140", set_eval_int, acc ); @@ -180,7 +193,7 @@ static void twitter_init( account_t *acc ) s = set_add( &acc->set, "mode", "one", set_eval_mode, acc ); s->flags |= ACC_SET_OFFLINE_ONLY; - s = set_add( &acc->set, "oauth", "true", set_eval_bool, acc ); + s = set_add( &acc->set, "oauth", def_oauth, set_eval_bool, acc ); } /** @@ -213,12 +226,16 @@ static void twitter_login( account_t *acc ) td->url_path = g_strdup( url.file ); else td->url_path = g_strdup( "" ); + if( g_str_has_suffix( url.host, ".com" ) ) + td->prefix = g_strndup( url.host, strlen( url.host ) - 4 ); + else + td->prefix = g_strdup( url.host ); td->user = acc->user; if( strstr( acc->pass, "oauth_token=" ) ) td->oauth_info = oauth_from_string( acc->pass, &twitter_oauth ); - sprintf( name, "twitter_%s", acc->user ); + sprintf( name, "%s_%s", td->prefix, acc->user ); imcb_add_buddy( ic, name, NULL ); imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); @@ -246,6 +263,7 @@ static void twitter_logout( struct im_connection *ic ) if( td ) { oauth_info_free( td->oauth_info ); + g_free( td->prefix ); g_free( td->url_host ); g_free( td->url_path ); g_free( td->pass ); @@ -261,9 +279,10 @@ static void twitter_logout( struct im_connection *ic ) static int twitter_buddy_msg( struct im_connection *ic, char *who, char *message, int away ) { struct twitter_data *td = ic->proto_data; + int plen = strlen( td->prefix ); - if (g_strncasecmp(who, "twitter_", 8) == 0 && - g_strcasecmp(who + 8, ic->acc->user) == 0) + if (g_strncasecmp(who, td->prefix, plen) == 0 && who[plen] == '_' && + g_strcasecmp(who + plen + 1, ic->acc->user) == 0) { if( set_getbool( &ic->acc->set, "oauth" ) && td->oauth_info && td->oauth_info->token == NULL ) @@ -415,10 +434,14 @@ void twitter_initmodule() ret->rem_deny = twitter_rem_deny; ret->send_typing = twitter_send_typing; ret->handle_cmp = g_strcasecmp; + + register_protocol(ret); + /* And an identi.ca variant: */ + ret = g_memdup(ret, sizeof(struct prpl)); + ret->name = "identica"; register_protocol(ret); // Initialise the twitter_connections GSList. twitter_connections = NULL; } - diff --git a/protocols/twitter/twitter.h b/protocols/twitter/twitter.h index e61d32be..b7e41fc5 100644 --- a/protocols/twitter/twitter.h +++ b/protocols/twitter/twitter.h @@ -52,6 +52,8 @@ struct twitter_data int url_port; char *url_host; char *url_path; + + char *prefix; /* Used to generate contact + channel name. */ }; /** diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index b4b460d3..1bf5257c 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -458,7 +458,7 @@ static void twitter_groupchat_init(struct im_connection *ic) td->home_timeline_gc = gc = imcb_chat_new( ic, "home/timeline" ); - name_hint = g_strdup_printf( "Twitter_%s", ic->acc->user ); + name_hint = g_strdup_printf( "%s_%s", td->prefix, ic->acc->user ); imcb_chat_name_hint( gc, name_hint ); g_free( name_hint ); } @@ -518,7 +518,7 @@ static void twitter_private_message_chat(struct im_connection *ic, GSList *list) if( mode_one ) { - g_snprintf( from, sizeof( from ) - 1, "twitter_%s", ic->acc->user ); + g_snprintf( from, sizeof( from ) - 1, "%s_%s", td->prefix, ic->acc->user ); from[MAX_STRING-1] = '\0'; } diff --git a/protocols/twitter/twitter_lib.h b/protocols/twitter/twitter_lib.h index 6b90f9bb..5a3c3f68 100644 --- a/protocols/twitter/twitter_lib.h +++ b/protocols/twitter/twitter_lib.h @@ -29,6 +29,7 @@ #include "twitter_http.h" #define TWITTER_API_URL "http://twitter.com" +#define IDENTICA_API_URL "http://identi.ca/api" /* Status URLs */ #define TWITTER_STATUS_UPDATE_URL "/statuses/update.xml" -- cgit v1.2.3 From 5c18a7632da2507ee9f8e63fafa46061163e3e3c Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Sat, 17 Jul 2010 16:51:01 +0100 Subject: Store exact Twitter usernames for all Twitter contacts when using mode=chat, so that xxx:->@xxx translation always works properly (even when the nick was stripped/etc). --- protocols/twitter/twitter_lib.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'protocols/twitter') diff --git a/protocols/twitter/twitter_lib.c b/protocols/twitter/twitter_lib.c index 1bf5257c..620850ab 100644 --- a/protocols/twitter/twitter_lib.c +++ b/protocols/twitter/twitter_lib.c @@ -124,7 +124,12 @@ static void twitter_add_buddy(struct im_connection *ic, char *name, const char * imcb_add_buddy( ic, name, NULL ); imcb_rename_buddy( ic, name, fullname ); if (g_strcasecmp(mode, "chat") == 0) + { + /* Necessary so that nicks always get translated to the + exact Twitter username. */ + imcb_buddy_nick_hint( ic, name, name ); imcb_chat_add_buddy( td->home_timeline_gc, name ); + } else if (g_strcasecmp(mode, "many") == 0) imcb_buddy_status( ic, name, OPT_LOGGED_IN, NULL, NULL ); } -- cgit v1.2.3