aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-06-26 22:26:41 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-06-26 22:26:41 +0100
commit92c8d410eb1d26bfe876ae119734772f46c9a7da (patch)
tree190d75fe792453a01fcc8eca822ade7c5d7e5bf1
parent41d415beaa1fd3bdd67a12686fc35386e5b81108 (diff)
Remember in which channel the user talked to someone and show responses in
that same channel.
-rw-r--r--irc.h9
-rw-r--r--irc_channel.c2
-rw-r--r--irc_commands.c2
-rw-r--r--irc_im.c24
-rw-r--r--irc_user.c5
5 files changed, 22 insertions, 20 deletions
diff --git a/irc.h b/irc.h
index 82652013..e6a4dcf9 100644
--- a/irc.h
+++ b/irc.h
@@ -65,7 +65,9 @@ typedef struct irc
struct irc_user *root;
struct irc_user *user;
- char *last_root_cmd;
+ char *last_root_cmd; /* Either the nickname from which the last root
+ msg came, or the last channel root was talked
+ to. */
char *password; /* HACK: Used to save the user's password, but before
logging in, this may contain a password we should
@@ -79,7 +81,7 @@ typedef struct irc
GSList *users, *channels;
struct irc_channel *default_channel;
GHashTable *nick_user_hash;
- GHashTable *watches;
+ GHashTable *watches; /* See irc_cmd_watch() */
gint r_watch_source_id;
gint w_watch_source_id;
@@ -90,7 +92,7 @@ typedef struct irc
typedef enum
{
- IRC_USER_PRIVATE = 1,
+ /* Replaced with iu->last_channel IRC_USER_PRIVATE = 1, */
IRC_USER_AWAY = 2,
} irc_user_flags_t;
@@ -107,6 +109,7 @@ typedef struct irc_user
char *key;
irc_user_flags_t flags;
+ struct irc_channel *last_channel;
GString *pastebuf; /* Paste buffer (combine lines into a multiline msg). */
guint pastebuf_timer;
diff --git a/irc_channel.c b/irc_channel.c
index 133a6de9..da6abbe4 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -374,7 +374,7 @@ static gboolean control_channel_privmsg( irc_channel_t *ic, const char *msg )
iu = irc_user_by_name( irc, to );
if( iu && iu->f->privmsg )
{
- iu->flags &= ~IRC_USER_PRIVATE;
+ iu->last_channel = ic;
iu->f->privmsg( iu, s );
}
else
diff --git a/irc_commands.c b/irc_commands.c
index b1fc74bf..5a0843ec 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -305,7 +305,7 @@ static void irc_cmd_privmsg( irc_t *irc, char **cmd )
}
else if( iu->f->privmsg )
{
- iu->flags |= IRC_USER_PRIVATE;
+ iu->last_channel = NULL;
iu->f->privmsg( iu, cmd[2] );
}
}
diff --git a/irc_im.c b/irc_im.c
index ee86d4b1..ada92b16 100644
--- a/irc_im.c
+++ b/irc_im.c
@@ -33,12 +33,13 @@ static const struct irc_user_funcs irc_user_im_funcs;
static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )
{
irc_user_t *iu;
+ irc_t *irc = (irc_t*) bee->ui_data;
char nick[MAX_NICK_LENGTH+1], *s;
memset( nick, 0, MAX_NICK_LENGTH + 1 );
strcpy( nick, nick_get( bu->ic->acc, bu->handle ) );
- bu->ui_data = iu = irc_user_new( (irc_t*) bee->ui_data, nick );
+ bu->ui_data = iu = irc_user_new( irc, nick );
iu->bu = bu;
if( ( s = strchr( bu->handle, '@' ) ) )
@@ -62,21 +63,17 @@ static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu )
iu->user = g_strdup( bu->handle );
}
- if( set_getbool( &bee->set, "private" ) )
- iu->flags |= IRC_USER_PRIVATE;
-
if( bu->flags & BEE_USER_LOCAL )
{
char *s = set_getstr( &bee->set, "handle_unknown" );
if( strcmp( s, "add_private" ) == 0 )
- iu->flags |= IRC_USER_PRIVATE;
+ iu->last_channel = NULL;
else if( strcmp( s, "add_channel" ) == 0 )
- iu->flags &= ~IRC_USER_PRIVATE;
+ iu->last_channel = irc->default_channel;
}
iu->f = &irc_user_im_funcs;
- //iu->last_typing_notice = 0;
return TRUE;
}
@@ -179,7 +176,6 @@ void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu )
static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, time_t sent_at )
{
irc_t *irc = bee->ui_data;
- irc_channel_t *ic = irc->default_channel;
irc_user_t *iu = (irc_user_t *) bu->ui_data;
char *dst, *prefix = NULL;
char *wrapped, *ts = NULL;
@@ -187,16 +183,16 @@ static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, t
if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) )
ts = irc_format_timestamp( irc, sent_at );
- if( iu->flags & IRC_USER_PRIVATE )
+ if( iu->last_channel )
{
- dst = irc->user->nick;
- prefix = ts;
- ts = NULL;
+ dst = iu->last_channel->name;
+ prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" );
}
else
{
- dst = ic->name;
- prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" );
+ dst = irc->user->nick;
+ prefix = ts;
+ ts = NULL;
}
wrapped = word_wrap( msg, 425 );
diff --git a/irc_user.c b/irc_user.c
index 9758350a..2706eb67 100644
--- a/irc_user.c
+++ b/irc_user.c
@@ -33,7 +33,10 @@ 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;
- iu->flags = set_getbool( &irc->b->set, "private" ) ? IRC_USER_PRIVATE : 0;
+ 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 );