Changeset 3e57660 for protocols


Ignore:
Timestamp:
2010-04-07T03:59:01Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
123cac7
Parents:
d4efddf
Message:

Show timestamps for offline messages. Including a timezone setting for
people using servers outside their own timezone.

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    rd4efddf r3e57660  
    3939
    4040static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
     41static char *format_timestamp( irc_t *irc, time_t msg_ts );
    4142
    4243GSList *connections;
     
    718719{
    719720        irc_t *irc = ic->irc;
    720         char *wrapped;
     721        char *wrapped, *ts;
    721722        user_t *u;
    722723       
     
    760761            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    761762                strip_html( msg );
    762 
     763       
     764        if( ( ts = format_timestamp( irc, sent_at ) ) )
     765        {
     766                char *new = g_strconcat( ts, msg, NULL );
     767                g_free( ts );
     768                ts = msg = new;
     769        }
     770       
    763771        wrapped = word_wrap( msg, 425 );
    764772        irc_msgfrom( irc, u->nick, wrapped );
    765773        g_free( wrapped );
     774        g_free( ts );
    766775}
    767776
     
    867876        if( c && u )
    868877        {
    869                 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
     878                char *ts = format_timestamp( ic->irc, sent_at );
     879                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped );
     880                g_free( ts );
    870881        }
    871882        else
     
    10611072}
    10621073
    1063 
    1064 
     1074char *set_eval_timezone( set_t *set, char *value )
     1075{
     1076        char *s;
     1077       
     1078        if( strcmp( value, "local" ) == 0 ||
     1079            strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
     1080                return value;
     1081       
     1082        /* Otherwise: +/- at the beginning optional, then one or more numbers,
     1083           possibly followed by a colon and more numbers. Don't bother bound-
     1084           checking them since users are free to shoot themselves in the foot. */
     1085        s = value;
     1086        if( *s == '+' || *s == '-' )
     1087                s ++;
     1088       
     1089        /* \d+ */
     1090        if( !isdigit( *s ) )
     1091                return SET_INVALID;
     1092        while( *s && isdigit( *s ) ) s ++;
     1093       
     1094        /* EOS? */
     1095        if( *s == '\0' )
     1096                return value;
     1097       
     1098        /* Otherwise, colon */
     1099        if( *s != ':' )
     1100                return SET_INVALID;
     1101        s ++;
     1102       
     1103        /* \d+ */
     1104        if( !isdigit( *s ) )
     1105                return SET_INVALID;
     1106        while( *s && isdigit( *s ) ) s ++;
     1107       
     1108        /* EOS */
     1109        return *s == '\0' ? value : SET_INVALID;
     1110}
     1111
     1112static char *format_timestamp( irc_t *irc, time_t msg_ts )
     1113{
     1114        time_t now_ts = time( NULL );
     1115        struct tm now, msg;
     1116        char *set;
     1117       
     1118        /* If the timestamp is <= 0 or less than a minute ago, discard it as
     1119           it doesn't seem to add to much useful info and/or might be noise. */
     1120        if( msg_ts <= 0 || msg_ts > now_ts - 60 )
     1121                return NULL;
     1122       
     1123        set = set_getstr( &irc->set, "timezone" );
     1124        if( strcmp( set, "local" ) == 0 )
     1125        {
     1126                localtime_r( &now_ts, &now );
     1127                localtime_r( &msg_ts, &msg );
     1128        }
     1129        else
     1130        {
     1131                int hr, min = 0, sign = 60;
     1132               
     1133                if( set[0] == '-' )
     1134                {
     1135                        sign *= -1;
     1136                        set ++;
     1137                }
     1138                else if( set[0] == '+' )
     1139                {
     1140                        set ++;
     1141                }
     1142               
     1143                if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
     1144                {
     1145                        msg_ts += sign * ( hr * 60 + min );
     1146                        now_ts += sign * ( hr * 60 + min );
     1147                }
     1148               
     1149                gmtime_r( &now_ts, &now );
     1150                gmtime_r( &msg_ts, &msg );
     1151        }
     1152       
     1153        if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
     1154                return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
     1155                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1156        else
     1157                return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
     1158                                        "%02d:%02d:%02d\x02]\x02 ",
     1159                                        msg.tm_year + 1900, msg.tm_mon, msg.tm_mday,
     1160                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1161}
    10651162
    10661163/* The plan is to not allow straight calls to prpl functions anymore, but do
  • protocols/nogaim.h

    rd4efddf r3e57660  
    324324
    325325/* Misc. stuff */
     326char *set_eval_timezone( set_t *set, char *value );
    326327char *set_eval_away_devoice( set_t *set, char *value );
    327328gboolean auto_reconnect( gpointer data, gint fd, b_input_condition cond );
Note: See TracChangeset for help on using the changeset viewer.