diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-11-20 20:25:44 +0000 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-11-20 20:25:44 +0000 |
commit | bb151f7aad467bf29c6e5ca552088f7f0b8ec876 (patch) | |
tree | ae64dfee90c7beec134cb6a1f2832eb0ec095996 /irc_channel.c | |
parent | d68365c5a799556a9375ac7e08d78d7dc80010ce (diff) |
Added irc_channel_with_user() function to find a suitable channel to show
a user's message in, instead of just &bitlbee by default.
Diffstat (limited to 'irc_channel.c')
-rw-r--r-- | irc_channel.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 ); |