diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-01 17:29:21 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2007-07-01 17:29:21 +0100 | 
| commit | b9f8b870f7b884747b747be91ce0ac797a7c6e82 (patch) | |
| tree | c9878ed7826e424306c2e8956f636ac0db1d9513 /protocols | |
| parent | 2758cfed0abcb529975af34fdb4d2603febbf1a3 (diff) | |
Better handling of private messages via groupchats.
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/jabber/conference.c | 8 | ||||
| -rw-r--r-- | protocols/jabber/jabber.c | 6 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 1 | ||||
| -rw-r--r-- | protocols/jabber/jabber_util.c | 37 | ||||
| -rw-r--r-- | protocols/jabber/message.c | 11 | 
5 files changed, 54 insertions, 9 deletions
| diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index 1b392655..d8c18df7 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -127,7 +127,9 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  		/* If this one wasn't set yet, this buddy just joined the chat.  		   Slightly hackish way of finding out eh? ;-) */ -		/* This is pretty messy... */ +		/* This is pretty messy... Here it sets ext_jid to the real +		   JID of the participant. Works for non-anonymized channels. +		   Might break if someone joins a chat twice, though. */  		for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next )  			if( ( s = xt_find_attr( c, "xmlns" ) ) &&  			    ( strcmp( s, XMLNS_MUC_USER ) == 0 ) ) @@ -136,7 +138,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  				if( ( s = xt_find_attr( c, "jid" ) ) )  				{  					/* Yay, found what we need. :-) */ -					bud->ext_jid = g_strdup( s ); +					bud->ext_jid = jabber_normalize( s );  					break;  				}  			} @@ -145,7 +147,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu  		if( bud->ext_jid == NULL )  		{  			if( bud == jc->me ) -				bud->ext_jid = g_strdup( ic->acc->user ); +				bud->ext_jid = jabber_normalize( ic->acc->user );  			else  				/* Don't want the nick to be at the end, so let's  				   think of some slightly different notation to use diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index f09583ec..e1cef48b 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -223,12 +223,16 @@ static int jabber_buddy_msg( struct im_connection *ic, char *who, char *message,  	struct jabber_data *jd = ic->proto_data;  	struct jabber_buddy *bud;  	struct xt_node *node; +	char *s;  	int st;  	if( g_strcasecmp( who, JABBER_XMLCONSOLE_HANDLE ) == 0 )  		return jabber_write( ic, message, strlen( message ) ); -	bud = jabber_buddy_by_jid( ic, who, 0 ); +	if( ( s = strchr( who, '=' ) ) && jabber_chat_by_name( ic, s + 1 ) ) +		bud = jabber_buddy_by_ext_jid( ic, who, 0 ); +	else +		bud = jabber_buddy_by_jid( ic, who, 0 );  	node = xt_new_node( "body", message, NULL );  	node = jabber_make_packet( "message", "chat", bud ? bud->full_jid : who, node ); diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 2fb01fdc..51550af8 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -194,6 +194,7 @@ typedef enum  struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid );  struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags ); +struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid, get_buddy_flags_t flags );  int jabber_buddy_remove( struct im_connection *ic, char *full_jid );  int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid );  struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 4dae3287..53f97ff0 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -319,6 +319,8 @@ struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid_  	}  	else  	{ +		/* Keep in mind that full_jid currently isn't really +		   a full JID... */  		new->bare_jid = g_strdup( full_jid );  		g_hash_table_insert( jd->buddies, new->bare_jid, new );  	} @@ -332,7 +334,8 @@ struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid_  	else  	{  		/* Let's waste some more bytes of RAM instead of to make -		   memory management a total disaster here.. */ +		   memory management a total disaster here. And it saves +		   me one g_free() call in this function. :-P */  		new->full_jid = full_jid;  	} @@ -427,6 +430,38 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  	}  } +/* I'm keeping a separate ext_jid attribute to save a JID that makes sense +   to export to BitlBee. This is mainly for groupchats right now. It's +   a bit of a hack, but I just think having the user nickname in the hostname +   part of the hostmask doesn't look nice on IRC. Normally you can convert +   a normal JID to ext_jid by swapping the part before and after the / and +   replacing the / with a =. But there should be some stripping (@s are +   allowed in Jabber nicks...). */ +struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid_, get_buddy_flags_t flags ) +{ +	struct jabber_buddy *bud; +	char *s, *jid; +	 +	jid = jabber_normalize( jid_ ); +	 +	if( ( s = strchr( jid, '=' ) ) == NULL ) +		return NULL; +	 +	for( bud = jabber_buddy_by_jid( ic, s + 1, GET_BUDDY_FIRST ); bud; bud = bud->next ) +	{ +		/* Hmmm, could happen if not all people in the chat are anonymized? */ +		if( bud->ext_jid == NULL ) +			continue; +		 +		if( strcmp( bud->ext_jid, jid ) == 0 ) +			break; +	} +	 +	g_free( jid ); +	 +	return bud; +} +  /* Remove one specific full JID from our list. Use this when a buddy goes     off-line (because (s)he can still be online from a different location.     XXX: See above, we should accept bare JIDs too... */ diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index 198fc3b9..52ee3a53 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -52,7 +52,10 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data )  		if( ( s = strchr( from, '/' ) ) )  		{  			if( bud ) +			{  				bud->last_act = time( NULL ); +				from = bud->ext_jid ? : bud->bare_jid; +			}  			else  				*s = 0; /* We need to generate a bare JID now. */  		} @@ -80,7 +83,7 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data )  			fullmsg = g_string_append( fullmsg, body->text );  		if( fullmsg->len > 0 ) -			imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str, +			imcb_buddy_msg( ic, from, fullmsg->str,  			                0, jabber_get_timestamp( node ) );  		g_string_free( fullmsg, TRUE ); @@ -89,18 +92,18 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data )  		if( xt_find_node( node->children, "composing" ) )  		{  			bud->flags |= JBFLAG_DOES_XEP85; -			imcb_buddy_typing( ic, bud ? bud->bare_jid : from, OPT_TYPING ); +			imcb_buddy_typing( ic, from, OPT_TYPING );  		}  		/* No need to send a "stopped typing" signal when there's a message. */  		else if( xt_find_node( node->children, "active" ) && ( body == NULL ) )  		{  			bud->flags |= JBFLAG_DOES_XEP85; -			imcb_buddy_typing( ic, bud ? bud->bare_jid : from, 0 ); +			imcb_buddy_typing( ic, from, 0 );  		}  		else if( xt_find_node( node->children, "paused" ) )  		{  			bud->flags |= JBFLAG_DOES_XEP85; -			imcb_buddy_typing( ic, bud ? bud->bare_jid : from, OPT_THINKING ); +			imcb_buddy_typing( ic, from, OPT_THINKING );  		}  		if( s ) | 
