1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added desktop notifications for chat room invites

Use "/notify invite on|off"
This commit is contained in:
James Booth 2013-04-22 23:48:23 +01:00
parent 9373f41fa4
commit f099bf9a7c
6 changed files with 45 additions and 1 deletions

View File

@ -499,11 +499,14 @@ static struct cmd_t setting_commands[] =
" : use 0 to disable.", " : use 0 to disable.",
"typing : Notifications when contacts are typing.", "typing : Notifications when contacts are typing.",
" : on|off", " : on|off",
"invite : Notifications for chat room invites.",
" : on|off",
"", "",
"Example : /notify message on (enable message notifications)", "Example : /notify message on (enable message notifications)",
"Example : /notify remind 10 (remind every 10 seconds)", "Example : /notify remind 10 (remind every 10 seconds)",
"Example : /notify remind 0 (switch off reminders)", "Example : /notify remind 0 (switch off reminders)",
"Example : /notify typing on (enable typing notifications)", "Example : /notify typing on (enable typing notifications)",
"Example : /notify invite on (enable chat room invite notifications)",
NULL } } }, NULL } } },
{ "/flash", { "/flash",
@ -783,6 +786,7 @@ cmd_init(void)
autocomplete_add(notify_ac, strdup("message")); autocomplete_add(notify_ac, strdup("message"));
autocomplete_add(notify_ac, strdup("typing")); autocomplete_add(notify_ac, strdup("typing"));
autocomplete_add(notify_ac, strdup("remind")); autocomplete_add(notify_ac, strdup("remind"));
autocomplete_add(notify_ac, strdup("invite"));
autocomplete_add(notify_ac, strdup("status")); autocomplete_add(notify_ac, strdup("status"));
sub_ac = autocomplete_new(); sub_ac = autocomplete_new();
@ -2487,7 +2491,7 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
// bad kind // bad kind
if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) &&
(strcmp(kind, "remind") != 0)) { (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0)) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
// set message setting // set message setting
@ -2514,6 +2518,18 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
cons_show("Usage: /notify typing on|off"); cons_show("Usage: /notify typing on|off");
} }
// set invite setting
} else if (strcmp(kind, "invite") == 0) {
if (strcmp(value, "on") == 0) {
cons_show("Chat room invite notifications enabled.");
prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE);
} else if (strcmp(value, "off") == 0) {
cons_show("Chat room invite notifications disabled.");
prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE);
} else {
cons_show("Usage: /notify invite on|off");
}
// set remind setting // set remind setting
} else if (strcmp(kind, "remind") == 0) { } else if (strcmp(kind, "remind") == 0) {
gint period = atoi(value); gint period = atoi(value);

View File

@ -299,6 +299,7 @@ _get_group(preference_t pref)
return "chatstates"; return "chatstates";
case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING:
case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE:
case PREF_NOTIFY_INVITE:
return "notifications"; return "notifications";
case PREF_CHLOG: case PREF_CHLOG:
return "logging"; return "logging";
@ -344,6 +345,8 @@ _get_key(preference_t pref)
return "typing"; return "typing";
case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE:
return "message"; return "message";
case PREF_NOTIFY_INVITE:
return "invite";
case PREF_CHLOG: case PREF_CHLOG:
return "chlog"; return "chlog";
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:

View File

@ -50,6 +50,7 @@ typedef enum {
PREF_OUTTYPE, PREF_OUTTYPE,
PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING,
PREF_NOTIFY_MESSAGE, PREF_NOTIFY_MESSAGE,
PREF_NOTIFY_INVITE,
PREF_CHLOG, PREF_CHLOG,
PREF_AUTOAWAY_CHECK, PREF_AUTOAWAY_CHECK,
PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MODE,

View File

@ -34,6 +34,7 @@
#include "config/preferences.h" #include "config/preferences.h"
#include "contact_list.h" #include "contact_list.h"
#include "config/theme.h" #include "config/theme.h"
#include "ui/notifier.h"
#include "ui/window.h" #include "ui/window.h"
#include "ui/ui.h" #include "ui/ui.h"
@ -675,6 +676,10 @@ cons_show_room_invite(const char * const invitor, const char * const room,
cons_show("Type \"/join %s\" to accept the invitation", display_room); cons_show("Type \"/join %s\" to accept the invitation", display_room);
if (prefs_get_boolean(PREF_NOTIFY_INVITE)) {
notify_invite(invitor, room);
}
jid_destroy(room_jid); jid_destroy(room_jid);
g_string_free(default_service, TRUE); g_string_free(default_service, TRUE);
@ -897,6 +902,11 @@ cons_show_desktop_prefs(void)
else else
cons_show("Composing (/notify typing) : OFF"); cons_show("Composing (/notify typing) : OFF");
if (prefs_get_boolean(PREF_NOTIFY_INVITE))
cons_show("Room invites (/notify invite) : ON");
else
cons_show("Room invites (/notify invite) : OFF");
gint remind_period = prefs_get_notify_remind(); gint remind_period = prefs_get_notify_remind();
if (remind_period == 0) { if (remind_period == 0) {
cons_show("Reminder period (/notify remind) : OFF"); cons_show("Reminder period (/notify remind) : OFF");

View File

@ -65,6 +65,19 @@ notify_typing(const char * const from)
_notify(message, 10000, "Incoming message"); _notify(message, 10000, "Incoming message");
} }
void
notify_invite(const char * const from, const char * const room)
{
GString *message = g_string_new("Room invite\nfrom: ");
g_string_append(message, from);
g_string_append(message, "\nto: ");
g_string_append(message, room);
_notify(message->str, 10000, "Incoming message");
g_string_free(message, FALSE);
}
void void
notify_message(const char * const short_from) notify_message(const char * const short_from)
{ {

View File

@ -26,3 +26,4 @@ void notifier_uninit(void);
void notify_typing(const char * const from); void notify_typing(const char * const from);
void notify_message(const char * const short_from); void notify_message(const char * const short_from);
void notify_remind(void); void notify_remind(void);
void notify_invite(const char * const from, const char * const room);