1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /gone to allow configurable delay for </gone> state

This commit is contained in:
James Booth 2012-12-19 23:31:25 +00:00
parent a281d396d6
commit 3d6ebf48ec
5 changed files with 58 additions and 4 deletions

View File

@ -27,10 +27,10 @@
#include "chat_session.h"
#include "log.h"
#include "preferences.h"
#define PAUSED_TIMOUT 10.0
#define INACTIVE_TIMOUT 30.0
#define GONE_TIMOUT 600.0
static void _chat_session_free(ChatSession session);
@ -113,7 +113,7 @@ chat_session_no_activity(const char * const recipient)
if (session->active_timer != NULL) {
gdouble elapsed = g_timer_elapsed(session->active_timer, NULL);
if (elapsed > GONE_TIMOUT) {
if ((prefs_get_gone() != 0) && (elapsed > (prefs_get_gone() * 60.0))) {
if (session->state != CHAT_STATE_GONE) {
session->sent = FALSE;
}
@ -127,8 +127,7 @@ chat_session_no_activity(const char * const recipient)
} else if (elapsed > PAUSED_TIMOUT) {
if ((session->state != CHAT_STATE_PAUSED) &&
(session->state != CHAT_STATE_ACTIVE)) {
if (session->state == CHAT_STATE_COMPOSING) {
session->sent = FALSE;
}
session->state = CHAT_STATE_PAUSED;

View File

@ -113,6 +113,7 @@ static gboolean _cmd_set_chlog(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_history(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_states(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_outtype(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_gone(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_autoping(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_titlebar(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_autoaway(gchar **args, struct cmd_help_t help);
@ -459,6 +460,17 @@ static struct cmd_t setting_commands[] =
"Chat states must be enabled for this to work, see the /states command.",
NULL } } },
{ "/gone",
_cmd_set_gone, parse_args, 1, 1,
{ "/gone minutes", "Send 'gone' state to recipient.",
{ "/gone minutes",
"--------------",
"Send a 'gone' state to the recipient after the specified number of minutes."
"This indicates to the recipient's client that you have left the conversation.",
"A value of 0 will disable sending this chat state automatically after a period.",
"Chat states must be enabled for this to work, see the /states command.",
NULL } } },
{ "/history",
_cmd_set_history, parse_args, 1, 1,
{ "/history on|off", "Chat history in message windows.",
@ -1684,6 +1696,25 @@ _cmd_set_outtype(gchar **args, struct cmd_help_t help)
"Sending typing notifications", prefs_set_outtype);
}
static gboolean
_cmd_set_gone(gchar **args, struct cmd_help_t help)
{
char *value = args[0];
gint period = atoi(value);
prefs_set_gone(period);
if (period == 0) {
cons_show("Automatic leaving conversations after period disabled.");
} else if (period == 1) {
cons_show("Leaving conversations after 1 minute of inactivity.");
} else {
cons_show("Leaving conversations after %d minutes of inactivity.", period);
}
return TRUE;
}
static gboolean
_cmd_set_notify(gchar **args, struct cmd_help_t help)
{

View File

@ -140,6 +140,19 @@ prefs_set_outtype(gboolean value)
_save_prefs();
}
gint
prefs_get_gone(void)
{
return g_key_file_get_integer(prefs, "chatstates", "gone", NULL);
}
void
prefs_set_gone(gint value)
{
g_key_file_set_integer(prefs, "chatstates", "gone", value);
_save_prefs();
}
gboolean
prefs_get_notify_typing(void)
{

View File

@ -65,6 +65,8 @@ gboolean prefs_get_states(void);
void prefs_set_states(gboolean value);
gboolean prefs_get_outtype(void);
void prefs_set_outtype(gboolean value);
gint prefs_get_gone(void);
void prefs_set_gone(gint value);
gchar * prefs_get_theme(void);
void prefs_set_theme(gchar *value);

View File

@ -1259,6 +1259,15 @@ cons_show_chat_prefs(void)
cons_show("Send composing (/outtype) : ON");
else
cons_show("Send composing (/outtype) : OFF");
gint gone_time = prefs_get_gone();
if (gone_time == 0) {
cons_show("Leave conversation (/gone) : OFF");
} else if (gone_time == 1) {
cons_show("Leave conversation (/gone) : 1 minute");
} else {
cons_show("Leave conversation (/gone) : %d minutes", gone_time);
}
}
void