# HG changeset patch # User Mikael Berthe # Date 1162378618 -3600 # Node ID ef10906691bb86c29a895ce5eeb3bb0c1fe6dca4 # Parent 35e7913affb73cf5c9d3d09f24bca00138544552 Chatstates: add composing timeout diff -r 35e7913affb7 -r ef10906691bb mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Wed Nov 01 00:57:56 2006 +0100 +++ b/mcabber/src/jabglue.c Wed Nov 01 11:56:58 2006 +0100 @@ -170,7 +170,7 @@ { time_t now; fd_set fds; - long autoaway_timeout; + long timeout; struct timeval tv; static time_t last_eviqs_check = 0; @@ -202,11 +202,20 @@ } } - autoaway_timeout = scr_GetAutoAwayTimeout(now); - if (tv.tv_sec > autoaway_timeout) { - tv.tv_sec = autoaway_timeout; + // Check auto-away timeout + timeout = scr_GetAutoAwayTimeout(now); + if (tv.tv_sec > timeout) { + tv.tv_sec = timeout; } +#if defined JEP0022 || defined JEP0085 + // Check composing timeout + timeout = scr_GetChatStatesTimeout(now); + if (tv.tv_sec > timeout) { + tv.tv_sec = timeout; + } +#endif + if (!tv.tv_sec) tv.tv_usec = 350000; diff -r 35e7913affb7 -r ef10906691bb mcabber/src/screen.c --- a/mcabber/src/screen.c Wed Nov 01 00:57:56 2006 +0100 +++ b/mcabber/src/screen.c Wed Nov 01 11:56:58 2006 +0100 @@ -95,8 +95,9 @@ static GList *cmdhisto_cur; static char cmdhisto_backup[INPUTLINE_LENGTH+1]; -static int chatstate; +static int chatstate; /* (0=active, 1=composing, 2=paused) */ static bool lock_chatstate; +static time_t chatstate_timestamp; #define MAX_KEYSEQ_LENGTH 8 @@ -1369,7 +1370,7 @@ } } -unsigned int scr_GetAutoAwayTimeout(time_t now) +long int scr_GetAutoAwayTimeout(time_t now) { enum imstatus cur_st; unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); @@ -1388,6 +1389,51 @@ return LastActivity + (time_t)autoaway_timeout - now; } +// set_chatstate(state) +// Set the current chat state (0=active, 1=composing, 2=paused) +// If the chat state has changed, call jb_send_chatstate() +static inline void set_chatstate(int state) +{ +#if defined JEP0022 || defined JEP0085 + if (!chatmode) + state = 0; + if (state != chatstate) { + chatstate = state; + if (current_buddy && + buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) { + guint jep_state; + if (chatstate == 1) + jep_state = ROSTER_EVENT_COMPOSING; + else if (chatstate == 2) + jep_state = ROSTER_EVENT_PAUSED; + else + jep_state = ROSTER_EVENT_ACTIVE; + jb_send_chatstate(BUDDATA(current_buddy), jep_state); + } + if (!chatstate) + chatstate_timestamp = 0; + } +#endif +} + +#if defined JEP0022 || defined JEP0085 +inline long int scr_GetChatStatesTimeout(time_t now) +{ + // Check if we're currently composing... + if (chatstate != 1 || !chatstate_timestamp) + return 86400; + + // If the timeout is reached, let's change the state right now. + if (now >= chatstate_timestamp + COMPOSING_TIMEOUT) { + chatstate_timestamp = now; + set_chatstate(2); + return 86400; + } + + return chatstate_timestamp + COMPOSING_TIMEOUT - now; +} +#endif + // Check if we should enter/leave automatic away status void scr_CheckAutoAway(int activity) { @@ -1411,30 +1457,6 @@ } } -// set_chatstate(state) -// Set the current chat state (0=active, 1=composing, 2=paused) -static inline void set_chatstate(int state) -{ -#if defined JEP0022 || defined JEP0085 - if (!chatmode) - state = 0; - if (state != chatstate) { - chatstate = state; - if (current_buddy && - buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_USER) { - guint jep_state; - if (chatstate == 1) - jep_state = ROSTER_EVENT_COMPOSING; - else if (chatstate == 2) - jep_state = ROSTER_EVENT_PAUSED; - else - jep_state = ROSTER_EVENT_ACTIVE; - jb_send_chatstate(BUDDATA(current_buddy), jep_state); - } - } -#endif -} - // set_current_buddy(newbuddy) // Set the current_buddy to newbuddy (if not NULL) // Lock the newbuddy, and unlock the previous current_buddy @@ -2793,6 +2815,8 @@ set_chatstate(0); else set_chatstate(1); + if (chatstate) + time(&chatstate_timestamp); } return 0; } diff -r 35e7913affb7 -r ef10906691bb mcabber/src/screen.h --- a/mcabber/src/screen.h Wed Nov 01 00:57:56 2006 +0100 +++ b/mcabber/src/screen.h Wed Nov 01 11:56:58 2006 +0100 @@ -26,6 +26,11 @@ // Note: message length is limited by the HBB_BLOCKSIZE size too #define MULTILINE_MAX_LINE_NUMBER 299 +// When chatstates are enabled, timeout (in seconds) before "composing" +// becomes "paused" because of user inactivity. +// Warning: setting this very low will cause more network traffic. +#define COMPOSING_TIMEOUT 8L + enum colors { COLOR_GENERAL = 3, COLOR_MSGOUT, @@ -91,9 +96,13 @@ inline void scr_Beep(void); -unsigned int scr_GetAutoAwayTimeout(time_t now); +long int scr_GetAutoAwayTimeout(time_t now); void scr_CheckAutoAway(int activity); +#if defined JEP0022 || defined JEP0085 +long int scr_GetChatStatesTimeout(time_t now); +#endif + // For commands... void scr_RosterTop(void); void scr_RosterBottom(void);