aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc.h1
-rw-r--r--irc_channel.c37
-rw-r--r--irc_im.c9
-rw-r--r--irc_send.c4
-rw-r--r--irc_user.c5
5 files changed, 47 insertions, 9 deletions
diff --git a/irc.h b/irc.h
index e8def513..bae11a39 100644
--- a/irc.h
+++ b/irc.h
@@ -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 );
diff --git a/irc_im.c b/irc_im.c
index 73ad697a..4e847d35 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -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 )
diff --git a/irc_send.c b/irc_send.c
index eb22139d..02f4b5d4 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -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 )
diff --git a/irc_user.c b/irc_user.c
index 53d63eab..db6fe531 100644
--- a/irc_user.c
+++ b/irc_user.c
@@ -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