# HG changeset patch # User Mikael Berthe # Date 1152898343 -7200 # Node ID fc30221b952d833bd74fd99748ae0f67cfe511ec # Parent 12fa2ae6445d7fcb57d9c6a3612c29870518e2e6 Fix an autoaway problem This patch fixes an autoaway related issue introduced in the previous changeset. scr_GetAutoAwayTimeout() should not return a null timeout when the user status do not need auto-away (i.e. status != online,free). This patch also tries to save a few time() calls. diff -r 12fa2ae6445d -r fc30221b952d mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Tue Jul 11 22:50:48 2006 +0200 +++ b/mcabber/src/jabglue.c Fri Jul 14 19:32:23 2006 +0200 @@ -191,19 +191,25 @@ tv.tv_sec = 60; tv.tv_usec = 0; + time(&now); + if (KeepaliveDelay) { - time(&now); - if (now > LastPingTime + (time_t)KeepaliveDelay) { + if (now >= LastPingTime + (time_t)KeepaliveDelay) { tv.tv_sec = 0; } else { tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now; } } - autoaway_timeout = scr_GetAutoAwayTimeout(); - if (tv.tv_sec > autoaway_timeout) + autoaway_timeout = scr_GetAutoAwayTimeout(now); + if (tv.tv_sec > autoaway_timeout) { tv.tv_sec = autoaway_timeout; + } + if (!tv.tv_sec) + tv.tv_usec = 350000; + + scr_DoUpdate(); if (select(jc->fd + 1, &fds, NULL, NULL, &tv) > 0) { if (FD_ISSET(jc->fd, &fds)) jab_poll(jc, 0); diff -r 12fa2ae6445d -r fc30221b952d mcabber/src/main.c --- a/mcabber/src/main.c Tue Jul 11 22:50:48 2006 +0200 +++ b/mcabber/src/main.c Fri Jul 14 19:32:23 2006 +0200 @@ -339,7 +339,6 @@ if (update_roster) scr_DrawRoster(); - scr_DoUpdate(); jb_main(); } } diff -r 12fa2ae6445d -r fc30221b952d mcabber/src/screen.c --- a/mcabber/src/screen.c Tue Jul 11 22:50:48 2006 +0200 +++ b/mcabber/src/screen.c Fri Jul 14 19:32:23 2006 +0200 @@ -1300,16 +1300,20 @@ } } -unsigned int scr_GetAutoAwayTimeout() +unsigned int scr_GetAutoAwayTimeout(time_t now) { + enum imstatus cur_st; unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); - time_t now; if (Autoaway || !autoaway_timeout) - return (unsigned)INT_MAX; + return 86400; - time(&now); - if (now > LastActivity + (time_t)autoaway_timeout) + cur_st = jb_getstatus(); + // Auto-away is disabled for the following states + if ((cur_st != available) && (cur_st != freeforchat)) + return 86400; + + if (now >= LastActivity + (time_t)autoaway_timeout) return 0; else return LastActivity + (time_t)autoaway_timeout - now; diff -r 12fa2ae6445d -r fc30221b952d mcabber/src/screen.h --- a/mcabber/src/screen.h Tue Jul 11 22:50:48 2006 +0200 +++ b/mcabber/src/screen.h Fri Jul 14 19:32:23 2006 +0200 @@ -91,7 +91,7 @@ inline void scr_Beep(void); -unsigned int scr_GetAutoAwayTimeout(); +unsigned int scr_GetAutoAwayTimeout(time_t now); void scr_CheckAutoAway(int activity); // For commands...