1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

Added notification setting for typing in current window

This commit is contained in:
James Booth 2014-05-24 21:13:33 +01:00
parent eb0f0dd96b
commit b25b3f3180
7 changed files with 57 additions and 16 deletions

View File

@ -486,6 +486,8 @@ static struct cmd_t command_defs[] =
" : use 0 to disable.",
"typing : Notifications when contacts are typing.",
" : on|off",
"typing current : Whether typing notifications are triggerd for the current window.",
" : on|off",
"invite : Notifications for chat room invites.",
" : on|off",
"sub : Notifications for subscription requests.",
@ -884,6 +886,7 @@ static Autocomplete help_ac;
static Autocomplete notify_ac;
static Autocomplete notify_room_ac;
static Autocomplete notify_message_ac;
static Autocomplete notify_typing_ac;
static Autocomplete prefs_ac;
static Autocomplete sub_ac;
static Autocomplete log_ac;
@ -991,6 +994,11 @@ cmd_init(void)
autocomplete_add(notify_room_ac, "mention");
autocomplete_add(notify_room_ac, "current");
notify_typing_ac = autocomplete_new();
autocomplete_add(notify_typing_ac, "on");
autocomplete_add(notify_typing_ac, "off");
autocomplete_add(notify_typing_ac, "current");
sub_ac = autocomplete_new();
autocomplete_add(sub_ac, "request");
autocomplete_add(sub_ac, "allow");
@ -1167,6 +1175,7 @@ cmd_uninit(void)
autocomplete_free(notify_ac);
autocomplete_free(notify_message_ac);
autocomplete_free(notify_room_ac);
autocomplete_free(notify_typing_ac);
autocomplete_free(sub_ac);
autocomplete_free(titlebar_ac);
autocomplete_free(log_ac);
@ -1281,6 +1290,7 @@ cmd_reset_autocomplete()
autocomplete_reset(notify_ac);
autocomplete_reset(notify_message_ac);
autocomplete_reset(notify_room_ac);
autocomplete_reset(notify_typing_ac);
autocomplete_reset(sub_ac);
if (ui_current_win_type() == WIN_MUC) {
@ -1806,6 +1816,11 @@ _notify_autocomplete(char *input, int *size)
return result;
}
result = autocomplete_param_with_func(input, size, "/notify typing current", prefs_autocomplete_boolean_choice);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/notify room", notify_room_ac);
if (result != NULL) {
return result;
@ -1816,7 +1831,12 @@ _notify_autocomplete(char *input, int *size)
return result;
}
gchar *boolean_choices[] = { "/notify typing", "/notify invite", "/notify sub" };
result = autocomplete_param_with_ac(input, size, "/notify typing", notify_typing_ac);
if (result != NULL) {
return result;
}
gchar *boolean_choices[] = { "/notify invite", "/notify sub" };
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, size, boolean_choices[i],
prefs_autocomplete_boolean_choice);

View File

@ -2212,10 +2212,10 @@ cmd_notify(gchar **args, struct cmd_help_t help)
prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE);
} else if (strcmp(args[1], "current") == 0) {
if (g_strcmp0(args[2], "on") == 0) {
cons_show("Current window messages notifications enabled.");
cons_show("Current window message notifications enabled.");
prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, TRUE);
} else if (g_strcmp0(args[2], "off") == 0) {
cons_show("Current window messages notifications disabled.");
cons_show("Current window message notifications disabled.");
prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, FALSE);
} else {
cons_show("Usage: /notify message current on|off");
@ -2233,14 +2233,14 @@ cmd_notify(gchar **args, struct cmd_help_t help)
cons_show("Chat room notifications disabled.");
prefs_set_string(PREF_NOTIFY_ROOM, "off");
} else if (strcmp(args[1], "mention") == 0) {
cons_show("Chat room notifications enable on mention.");
cons_show("Chat room notifications enabled on mention.");
prefs_set_string(PREF_NOTIFY_ROOM, "mention");
} else if (strcmp(args[1], "current") == 0) {
if (g_strcmp0(args[2], "on") == 0) {
cons_show("Current window chat room messages notifications enabled.");
cons_show("Current window chat room message notifications enabled.");
prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, TRUE);
} else if (g_strcmp0(args[2], "off") == 0) {
cons_show("Current window chat room messages notifications disabled.");
cons_show("Current window chat room message notifications disabled.");
prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, FALSE);
} else {
cons_show("Usage: /notify room current on|off");
@ -2257,6 +2257,16 @@ cmd_notify(gchar **args, struct cmd_help_t help)
} else if (strcmp(args[1], "off") == 0) {
cons_show("Typing notifications disabled.");
prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE);
} else if (strcmp(args[1], "current") == 0) {
if (g_strcmp0(args[2], "on") == 0) {
cons_show("Current window typing notifications enabled.");
prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, TRUE);
} else if (g_strcmp0(args[2], "off") == 0) {
cons_show("Current window typing notifications disabled.");
prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, FALSE);
} else {
cons_show("Usage: /notify typing current on|off");
}
} else {
cons_show("Usage: /notify typing on|off");
}

View File

@ -400,6 +400,7 @@ _get_group(preference_t pref)
case PREF_OUTTYPE:
return PREF_GROUP_CHATSTATES;
case PREF_NOTIFY_TYPING:
case PREF_NOTIFY_TYPING_CURRENT:
case PREF_NOTIFY_MESSAGE:
case PREF_NOTIFY_MESSAGE_CURRENT:
case PREF_NOTIFY_ROOM:
@ -464,6 +465,8 @@ _get_key(preference_t pref)
return "outtype";
case PREF_NOTIFY_TYPING:
return "typing";
case PREF_NOTIFY_TYPING_CURRENT:
return "typing.current";
case PREF_NOTIFY_MESSAGE:
return "message";
case PREF_NOTIFY_MESSAGE_CURRENT:
@ -515,6 +518,7 @@ _get_default_boolean(preference_t pref)
case PREF_LOG_SHARED:
case PREF_NOTIFY_MESSAGE_CURRENT:
case PREF_NOTIFY_ROOM_CURRENT:
case PREF_NOTIFY_TYPING_CURRENT:
return TRUE;
default:
return FALSE;

View File

@ -52,6 +52,7 @@ typedef enum {
PREF_STATES,
PREF_OUTTYPE,
PREF_NOTIFY_TYPING,
PREF_NOTIFY_TYPING_CURRENT,
PREF_NOTIFY_MESSAGE,
PREF_NOTIFY_MESSAGE_CURRENT,
PREF_NOTIFY_ROOM,

View File

@ -1181,6 +1181,11 @@ _cons_notify_setting(void)
else
cons_show("Composing (/notify typing) : OFF");
if (prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT))
cons_show("Composing current (/notify typing) : ON");
else
cons_show("Composing current (/notify typing) : OFF");
if (prefs_get_boolean(PREF_NOTIFY_INVITE))
cons_show("Room invites (/notify invite) : ON");
else

View File

@ -277,14 +277,17 @@ _ui_contact_typing(const char * const barejid)
}
if (prefs_get_boolean(PREF_NOTIFY_TYPING)) {
PContact contact = roster_get_contact(barejid);
char const *display_usr = NULL;
if (p_contact_name(contact) != NULL) {
display_usr = p_contact_name(contact);
} else {
display_usr = barejid;
gboolean is_current = wins_is_current(window);
if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) ) {
PContact contact = roster_get_contact(barejid);
char const *display_usr = NULL;
if (p_contact_name(contact) != NULL) {
display_usr = p_contact_name(contact);
} else {
display_usr = barejid;
}
notify_typing(display_usr);
}
notify_typing(display_usr);
}
}

View File

@ -476,9 +476,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// deal with chat states if recipient supports them
if (recipient_supports && (!delayed)) {
if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
if (prefs_get_boolean(PREF_NOTIFY_TYPING) || prefs_get_boolean(PREF_INTYPE)) {
handle_typing(jid->barejid);
}
handle_typing(jid->barejid);
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
handle_gone(jid->barejid);
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {