diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-07 18:41:45 +0000 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-07 18:41:45 +0000 | 
| commit | c32f492758759c04d8b6239a7862648c9d32c4d8 (patch) | |
| tree | 628612ec0d2c431519a0a3741df7e4c6609db7f1 /protocols/nogaim.c | |
| parent | 1c2eaa3c99a2e7fbe264b06e559f3d709b9a080d (diff) | |
| parent | 0e99548ba9c6ec9c78367e05b676dab90b5261a4 (diff) | |
Merging in improved away/status message code.
Diffstat (limited to 'protocols/nogaim.c')
| -rw-r--r-- | protocols/nogaim.c | 98 | 
1 files changed, 49 insertions, 49 deletions
| diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 21f7dcb1..3d2cff5c 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -1,7 +1,7 @@    /********************************************************************\    * BitlBee -- An IRC to other IM-networks gateway                     *    *                                                                    * -  * Copyright 2002-2006 Wilmer van der Gaast and others                * +  * Copyright 2002-2010 Wilmer van der Gaast and others                *    \********************************************************************/  /* @@ -267,9 +267,8 @@ void imcb_connected( struct im_connection *ic )  	ic->keepalive = b_timeout_add( 60000, send_keepalive, ic );  	ic->flags |= OPT_LOGGED_IN; -	/* Also necessary when we're not away, at least for some of the -	   protocols. */ -	imc_set_away( ic, u->away ); +	/* Necessary to send initial presence status, even if we're not away. */ +	imc_away_send_update( ic );  	/* Apparently we're connected successfully, so reset the  	   exponential backoff timer. */ @@ -1069,51 +1068,30 @@ int imc_chat_msg( struct groupchat *c, char *msg, int flags )  	return 1;  } -static char *imc_away_alias_find( GList *gcm, char *away ); +static char *imc_away_state_find( GList *gcm, char *away, char **message ); -int imc_set_away( struct im_connection *ic, char *away ) +int imc_away_send_update( struct im_connection *ic )  { -	GList *m, *ms; -	char *s; -	 -	if( !away ) away = ""; -	ms = m = ic->acc->prpl->away_states( ic ); -	 -	while( m ) -	{ -		if( *away ) -		{ -			if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) -				break; -		} -		else -		{ -			if( g_strcasecmp( m->data, "Available" ) == 0 ) -				break; -			if( g_strcasecmp( m->data, "Online" ) == 0 ) -				break; -		} -		m = m->next; -	} +	char *away, *msg; -	if( m ) +	away = set_getstr( &ic->acc->set, "away" ) ? +	     : set_getstr( &ic->irc->set, "away" ); +	if( away && *away )  	{ -		ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL ); +		GList *m = ic->acc->prpl->away_states( ic ); +		msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL; +		away = imc_away_state_find( m, away, &msg ) ? : m->data;  	} -	else +	else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )  	{ -		s = imc_away_alias_find( ms, away ); -		if( s ) -		{ -			ic->acc->prpl->set_away( ic, s, away ); -			if( set_getbool( &ic->irc->set, "debug" ) ) -				imcb_log( ic, "Setting away state to %s", s ); -		} -		else -			ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away ); +		away = NULL; +		msg = set_getstr( &ic->acc->set, "status" ) ? +		    : set_getstr( &ic->irc->set, "status" );  	} -	return( 1 ); +	ic->acc->prpl->set_away( ic, away, msg ); +	 +	return 1;  }  static char *imc_away_alias_list[8][5] = @@ -1128,16 +1106,33 @@ static char *imc_away_alias_list[8][5] =  	{ NULL }  }; -static char *imc_away_alias_find( GList *gcm, char *away ) +static char *imc_away_state_find( GList *gcm, char *away, char **message )  {  	GList *m;  	int i, j; +	for( m = gcm; m; m = m->next ) +		if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) +		{ +			/* At least the Yahoo! module works better if message +			   contains no data unless it adds something to what +			   we have in state already. */ +			if( strlen( m->data ) == strlen( away ) ) +				*message = NULL; +			 +			return m->data; +		} +	  	for( i = 0; *imc_away_alias_list[i]; i ++ )  	{ +		int keep_message; +		  		for( j = 0; imc_away_alias_list[i][j]; j ++ )  			if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 ) +			{ +				keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );  				break; +			}  		if( !imc_away_alias_list[i][j] )	/* If we reach the end, this row */  			continue;			/* is not what we want. Next!    */ @@ -1145,17 +1140,22 @@ static char *imc_away_alias_find( GList *gcm, char *away )  		/* Now find an entry in this row which exists in gcm */  		for( j = 0; imc_away_alias_list[i][j]; j ++ )  		{ -			m = gcm; -			while( m ) -			{ +			for( m = gcm; m; m = m->next )  				if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 ) -					return( imc_away_alias_list[i][j] ); -				m = m->next; -			} +				{ +					if( !keep_message ) +						*message = NULL; +					 +					return imc_away_alias_list[i][j]; +				}  		} +		 +		/* No need to look further, apparently this state doesn't +		   have any good alias for this protocol. */ +		break;  	} -	return( NULL ); +	return NULL;  }  void imc_add_allow( struct im_connection *ic, char *handle ) | 
