diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2007-06-04 14:22:05 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2007-06-04 14:22:05 +0100 | 
| commit | d06eabf19ec3f849d8bab22c13d43e4eba9a48ee (patch) | |
| tree | 0528ff030b32b1de53967641ce29f44653286012 | |
| parent | 54f2f55f983f4b6bb8a58772bbd1137580e3307f (diff) | |
Added imcb_buddy_nick_hint so the Jabber conference module can suggest sane
nicknames for chatroom participants. There'll probably be a lot of
underscores now, but this is by far the cleanest way to implement this, I
think. At least now whispers will work properly. Also using this function
call to set names for ICQ contacts in a slightly saner way.
| -rw-r--r-- | nick.c | 14 | ||||
| -rw-r--r-- | nick.h | 1 | ||||
| -rw-r--r-- | protocols/jabber/conference.c | 3 | ||||
| -rw-r--r-- | protocols/jabber/iq.c | 6 | ||||
| -rw-r--r-- | protocols/nogaim.c | 47 | ||||
| -rw-r--r-- | protocols/nogaim.h | 1 | ||||
| -rw-r--r-- | protocols/oscar/oscar.c | 1 | 
7 files changed, 47 insertions, 26 deletions
| @@ -56,7 +56,6 @@ char *nick_get( account_t *acc, const char *handle )  {  	static char nick[MAX_NICK_LENGTH+1];  	char *store_handle, *found_nick; -	int inf_protection = 256;  	memset( nick, 0, MAX_NICK_LENGTH + 1 ); @@ -82,6 +81,17 @@ char *nick_get( account_t *acc, const char *handle )  	}  	g_free( store_handle ); +	/* Make sure the nick doesn't collide with an existing one by adding +	   underscores and that kind of stuff, if necessary. */ +	nick_dedupe( acc, handle, nick ); +	 +	return nick; +} + +void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] ) +{ +	int inf_protection = 256; +	  	/* Now, find out if the nick is already in use at the moment, and make  	   subtle changes to make it unique. */  	while( !nick_ok( nick ) || user_find( acc->irc, nick ) ) @@ -119,8 +129,6 @@ char *nick_get( account_t *acc, const char *handle )  			break;  		}  	} -	 -	return nick;  }  /* Just check if there is a nickname set for this buddy or if we'd have to @@ -25,6 +25,7 @@  void nick_set( account_t *acc, const char *handle, const char *nick );  char *nick_get( account_t *acc, const char *handle ); +void nick_dedupe( account_t *acc, const char *handle, char nick[MAX_NICK_LENGTH+1] );  int nick_saved( account_t *acc, const char *handle );  void nick_del( account_t *acc, const char *handle );  void nick_strip( char *nick ); diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index a97590ba..b77e037b 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -159,6 +159,9 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  		if( s ) *s = 0; /* Should NEVER be NULL, but who knows... */  		imcb_chat_add_buddy( chat, bud->ext_jid );  		if( s ) *s = '/'; +		 +		if( bud != jc->me ) +			imcb_buddy_nick_hint( ic, bud->ext_jid, bud->resource );  	}  	else if( type ) /* This only gets called if type is NULL or "unavailable" */  	{ diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 2aa9d432..62e6a183 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -372,7 +372,11 @@ static xt_status jabber_parse_roster( struct im_connection *ic, struct xt_node *  					imcb_add_buddy( ic, jid, ( group && group->text_len ) ?  					                           group->text : NULL ); -				imcb_rename_buddy( ic, jid, name ); +				if( name ) +				{ +					imcb_rename_buddy( ic, jid, name ); +					imcb_buddy_nick_hint( ic, jid, name ); +				}  			}  			else if( strcmp( sub, "remove" ) == 0 )  			{ diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 5a9f5b3e..71cebacd 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -427,7 +427,6 @@ struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle )  void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )  {  	user_t *u = user_findhandle( ic, handle ); -	char *s, newnick[MAX_NICK_LENGTH+1];  	if( !u || !realname ) return; @@ -439,30 +438,34 @@ void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )  		if( ( ic->flags & OPT_LOGGED_IN ) && set_getbool( &ic->irc->set, "display_namechanges" ) )  			imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname ); -		 -		if( !u->online && !nick_saved( ic->acc, handle ) ) -		{ -			/* Detect numeric handles: */ -			for( s = u->user; isdigit( *s ); s++ ); -			 -			if( *s == 0 ) -			{ -				/* If we reached the end of the string, it only contained numbers. -				   Seems to be an ICQ# then, so hopefully realname contains -				   something more useful. */ -				strcpy( newnick, realname ); -				 -				/* Some processing to make sure this string is a valid IRC nickname. */ -				nick_strip( newnick ); -				if( set_getbool( &ic->irc->set, "lcnicks" ) ) -					nick_lc( newnick ); -				 -				u->nick = g_strdup( newnick ); -			} -		}  	}  } +/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM +   modules to suggest a nickname for a handle. */ +void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) +{ +	user_t *u = user_findhandle( ic, handle ); +	char newnick[MAX_NICK_LENGTH+1]; +	 +	if( !u->online && !nick_saved( ic->acc, handle ) ) +	{ +		/* Only do this if the person isn't online yet (which should +		   be the case if we just added it) and if the user hasn't +		   assigned a nickname to this buddy already. */ +		 +		strcpy( newnick, nick ); +		 +		/* Some processing to make sure this string is a valid IRC nickname. */ +		nick_strip( newnick ); +		if( set_getbool( &ic->irc->set, "lcnicks" ) ) +			nick_lc( newnick ); +		 +		nick_dedupe( ic->acc, handle, newnick ); +		 +		u->nick = g_strdup( newnick ); +	} +}  /* prpl.c */ diff --git a/protocols/nogaim.h b/protocols/nogaim.h index 6bbee6f7..74a63306 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -193,6 +193,7 @@ G_MODULE_EXPORT void imcb_add_buddy( struct im_connection *ic, char *handle, cha  G_MODULE_EXPORT void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group );  G_MODULE_EXPORT struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle );  G_MODULE_EXPORT void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname ); +G_MODULE_EXPORT void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick );  /* Buddy activity */  G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ); diff --git a/protocols/oscar/oscar.c b/protocols/oscar/oscar.c index b72c683a..39d14811 100644 --- a/protocols/oscar/oscar.c +++ b/protocols/oscar/oscar.c @@ -2021,6 +2021,7 @@ static int gaim_ssi_parselist(aim_session_t *sess, aim_frame_t *fr, ...) {  					imcb_add_buddy(ic, curitem->name, NULL);  					if (realname) { +						imcb_buddy_nick_hint(ic, curitem->name, realname);  						imcb_rename_buddy(ic, curitem->name, realname);  						g_free(realname);  					} | 
