aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-04-07 04:59:01 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2010-04-07 04:59:01 +0100
commit3e5766022e8103765d62343956cf1aeba34b4d82 (patch)
tree6d36decd2eecb0950c072ec805cb02a6ae5b3c8e
parentd4efddfb7d34a8409cf78dd337f3933e0ed11d08 (diff)
Show timestamps for offline messages. Including a timezone setting for
people using servers outside their own timezone.
-rw-r--r--doc/user-guide/commands.xml15
-rw-r--r--irc.c1
-rw-r--r--protocols/nogaim.c105
-rw-r--r--protocols/nogaim.h1
4 files changed, 118 insertions, 4 deletions
diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml
index 833ea00f..c8f2de4c 100644
--- a/doc/user-guide/commands.xml
+++ b/doc/user-guide/commands.xml
@@ -838,6 +838,21 @@
</description>
</bitlbee-setting>
+ <bitlbee-setting name="timezone" type="string" scope="global">
+ <default>local</default>
+ <possible-values>local, utc, gmt, timezone-spec</possible-values>
+
+ <description>
+ <para>
+ If message timestamps are available for offline messages or chatroom backlogs, BitlBee will display them as part of the message. By default it will use the local timezone. If you're not in the same timezone as the BitlBee server, you can adjust the timestamps using this setting.
+ </para>
+
+ <para>
+ Values local/utc/gmt should be self-explanatory. timezone-spec is a time offset in hours:minutes, for example: -8 for Pacific Standard Time, +2 for Central European Summer Time, +5:30 for Indian Standard Time.
+ </para>
+ </description>
+ </bitlbee-setting>
+
<bitlbee-setting name="tls" type="boolean" scope="account">
<default>try</default>
diff --git a/irc.c b/irc.c
index 8cd4a33a..b68c5adb 100644
--- a/irc.c
+++ b/irc.c
@@ -198,6 +198,7 @@ irc_t *irc_new( int fd )
s = set_add( &irc->set, "status", NULL, set_eval_away_status, irc );
s->flags |= SET_NULL_OK;
s = set_add( &irc->set, "strip_html", "true", NULL, irc );
+ s = set_add( &irc->set, "timezone", "local", set_eval_timezone, irc );
s = set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
s = set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc );
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index c326e378..3b4fe060 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -38,6 +38,7 @@
#include "chat.h"
static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
+static char *format_timestamp( irc_t *irc, time_t msg_ts );
GSList *connections;
@@ -717,7 +718,7 @@ void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags,
void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
{
irc_t *irc = ic->irc;
- char *wrapped;
+ char *wrapped, *ts;
user_t *u;
u = user_findhandle( ic, handle );
@@ -759,10 +760,18 @@ void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, ui
if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
strip_html( msg );
-
+
+ if( ( ts = format_timestamp( irc, sent_at ) ) )
+ {
+ char *new = g_strconcat( ts, msg, NULL );
+ g_free( ts );
+ ts = msg = new;
+ }
+
wrapped = word_wrap( msg, 425 );
irc_msgfrom( irc, u->nick, wrapped );
g_free( wrapped );
+ g_free( ts );
}
void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags )
@@ -866,7 +875,9 @@ void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t fl
wrapped = word_wrap( msg, 425 );
if( c && u )
{
- irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
+ char *ts = format_timestamp( ic->irc, sent_at );
+ irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped );
+ g_free( ts );
}
else
{
@@ -1060,8 +1071,94 @@ char *set_eval_away_devoice( set_t *set, char *value )
return value;
}
+char *set_eval_timezone( set_t *set, char *value )
+{
+ char *s;
+
+ if( strcmp( value, "local" ) == 0 ||
+ strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
+ return value;
+
+ /* Otherwise: +/- at the beginning optional, then one or more numbers,
+ possibly followed by a colon and more numbers. Don't bother bound-
+ checking them since users are free to shoot themselves in the foot. */
+ s = value;
+ if( *s == '+' || *s == '-' )
+ s ++;
+
+ /* \d+ */
+ if( !isdigit( *s ) )
+ return SET_INVALID;
+ while( *s && isdigit( *s ) ) s ++;
+
+ /* EOS? */
+ if( *s == '\0' )
+ return value;
+
+ /* Otherwise, colon */
+ if( *s != ':' )
+ return SET_INVALID;
+ s ++;
+
+ /* \d+ */
+ if( !isdigit( *s ) )
+ return SET_INVALID;
+ while( *s && isdigit( *s ) ) s ++;
+
+ /* EOS */
+ return *s == '\0' ? value : SET_INVALID;
+}
-
+static char *format_timestamp( irc_t *irc, time_t msg_ts )
+{
+ time_t now_ts = time( NULL );
+ struct tm now, msg;
+ char *set;
+
+ /* If the timestamp is <= 0 or less than a minute ago, discard it as
+ it doesn't seem to add to much useful info and/or might be noise. */
+ if( msg_ts <= 0 || msg_ts > now_ts - 60 )
+ return NULL;
+
+ set = set_getstr( &irc->set, "timezone" );
+ if( strcmp( set, "local" ) == 0 )
+ {
+ localtime_r( &now_ts, &now );
+ localtime_r( &msg_ts, &msg );
+ }
+ else
+ {
+ int hr, min = 0, sign = 60;
+
+ if( set[0] == '-' )
+ {
+ sign *= -1;
+ set ++;
+ }
+ else if( set[0] == '+' )
+ {
+ set ++;
+ }
+
+ if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
+ {
+ msg_ts += sign * ( hr * 60 + min );
+ now_ts += sign * ( hr * 60 + min );
+ }
+
+ gmtime_r( &now_ts, &now );
+ gmtime_r( &msg_ts, &msg );
+ }
+
+ if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
+ return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
+ msg.tm_hour, msg.tm_min, msg.tm_sec );
+ else
+ return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
+ "%02d:%02d:%02d\x02]\x02 ",
+ msg.tm_year + 1900, msg.tm_mon, msg.tm_mday,
+ msg.tm_hour, msg.tm_min, msg.tm_sec );
+}
/* The plan is to not allow straight calls to prpl functions anymore, but do
them all from some wrappers. We'll start to define some down here: */
diff --git a/protocols/nogaim.h b/protocols/nogaim.h
index a523a3a5..3c5e539f 100644
--- a/protocols/nogaim.h
+++ b/protocols/nogaim.h
@@ -323,6 +323,7 @@ void imc_add_block( struct im_connection *ic, char *handle );
void imc_rem_block( struct im_connection *ic, char *handle );
/* Misc. stuff */
+char *set_eval_timezone( set_t *set, char *value );
char *set_eval_away_devoice( set_t *set, char *value );
gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond );
void cancel_auto_reconnect( struct account *a );