diff options
-rw-r--r-- | irc.h | 1 | ||||
-rw-r--r-- | irc_channel.c | 37 | ||||
-rw-r--r-- | irc_im.c | 9 | ||||
-rw-r--r-- | irc_send.c | 4 | ||||
-rw-r--r-- | irc_user.c | 5 |
5 files changed, 47 insertions, 9 deletions
@@ -286,6 +286,7 @@ void irc_channel_free_soon( irc_channel_t *ic ); int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu ); int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu, irc_channel_del_user_type_t type, const char *msg ); irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu ); +struct irc_channel *irc_channel_with_user( irc_t *irc, irc_user_t *iu ); int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who ); void irc_channel_user_set_mode( irc_channel_t *ic, irc_user_t *iu, irc_channel_user_flags_t flags ); void irc_channel_set_mode( irc_channel_t *ic, const char *s ); diff --git a/irc_channel.c b/irc_channel.c index 60426ac0..15b1744a 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -291,6 +291,43 @@ irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu ) return NULL; } +/* Find a channel we're currently in, that currently has iu in it. */ +struct irc_channel *irc_channel_with_user( irc_t *irc, irc_user_t *iu ) +{ + GSList *l; + + for( l = irc->channels; l; l = l->next ) + { + irc_channel_t *ic = l->data; + + if( strcmp( set_getstr( &ic->set, "type" ), "control" ) != 0 ) + continue; + + if( ( ic->flags & IRC_CHANNEL_JOINED ) && + irc_channel_has_user( ic, iu ) ) + return ic; + } + + /* If there was no match, try once more but just see if the user + *would* be in the channel, i.e. if s/he were online. */ + if( iu->bu == NULL ) + return NULL; + + for( l = irc->channels; l; l = l->next ) + { + irc_channel_t *ic = l->data; + + if( strcmp( set_getstr( &ic->set, "type" ), "control" ) != 0 ) + continue; + + if( ( ic->flags & IRC_CHANNEL_JOINED ) && + irc_channel_wants_user( ic, iu ) ) + return ic; + } + + return NULL; +} + int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *iu ) { g_free( ic->topic ); @@ -54,6 +54,11 @@ static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu ) bu->ui_data = iu = irc_user_new( irc, nick ); iu->bu = bu; + if( set_getbool( &irc->b->set, "private" ) ) + iu->last_channel = NULL; + else + iu->last_channel = irc_channel_with_user( irc, iu ); + if( ( s = strchr( bu->handle, '@' ) ) ) { iu->host = g_strdup( s + 1 ); @@ -209,8 +214,8 @@ static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg_, { if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) ic = iu->last_channel; - else if( irc->default_channel->flags & IRC_CHANNEL_JOINED ) - ic = irc->default_channel; + else + ic = irc_channel_with_user( irc, iu ); } if( ic ) @@ -126,8 +126,8 @@ void irc_usermsg( irc_t *irc, char *format, ... ) { if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) ic = iu->last_channel; - else if( irc->default_channel->flags & IRC_CHANNEL_JOINED ) - ic = irc->default_channel; + else + ic = irc_channel_with_user( irc, irc->root ); } if( ic ) @@ -34,11 +34,6 @@ irc_user_t *irc_user_new( irc_t *irc, const char *nick ) iu->nick = g_strdup( nick ); iu->user = iu->host = iu->fullname = iu->nick; - if( set_getbool( &irc->b->set, "private" ) ) - iu->last_channel = NULL; - else - iu->last_channel = irc->default_channel; - iu->key = g_strdup( nick ); nick_lc( iu->key ); /* Using the hash table for speed and irc->users for easy iteration |