mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-28 11:46:20 +00:00
Added desktop notification option for subscription requests
closes #166
This commit is contained in:
@@ -522,6 +522,9 @@ static struct cmd_t setting_commands[] =
|
|||||||
"invite : Notifications for chat room invites.",
|
"invite : Notifications for chat room invites.",
|
||||||
" : on|off",
|
" : on|off",
|
||||||
"",
|
"",
|
||||||
|
"sub : Notifications for subscription requests.",
|
||||||
|
" : 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)",
|
||||||
@@ -807,6 +810,7 @@ cmd_init(void)
|
|||||||
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("invite"));
|
||||||
|
autocomplete_add(notify_ac, strdup("sub"));
|
||||||
autocomplete_add(notify_ac, strdup("status"));
|
autocomplete_add(notify_ac, strdup("status"));
|
||||||
|
|
||||||
sub_ac = autocomplete_new();
|
sub_ac = autocomplete_new();
|
||||||
@@ -2513,7 +2517,8 @@ _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, "invite") != 0)) {
|
(strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) &&
|
||||||
|
(strcmp(kind, "sub") != 0)) {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
|
|
||||||
// set message setting
|
// set message setting
|
||||||
@@ -2552,6 +2557,18 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
|
|||||||
cons_show("Usage: /notify invite on|off");
|
cons_show("Usage: /notify invite on|off");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set subscription setting
|
||||||
|
} else if (strcmp(kind, "sub") == 0) {
|
||||||
|
if (strcmp(value, "on") == 0) {
|
||||||
|
cons_show("Subscription notifications enabled.");
|
||||||
|
prefs_set_boolean(PREF_NOTIFY_SUB, TRUE);
|
||||||
|
} else if (strcmp(value, "off") == 0) {
|
||||||
|
cons_show("Subscription notifications disabled.");
|
||||||
|
prefs_set_boolean(PREF_NOTIFY_SUB, FALSE);
|
||||||
|
} else {
|
||||||
|
cons_show("Usage: /notify sub 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);
|
||||||
@@ -3008,6 +3025,34 @@ _notify_autocomplete(char *input, int *size)
|
|||||||
free(auto_msg);
|
free(auto_msg);
|
||||||
free(found);
|
free(found);
|
||||||
}
|
}
|
||||||
|
} else if ((strncmp(input, "/notify invite ", 15) == 0) && (*size > 15)) {
|
||||||
|
for(i = 15; i < *size; i++) {
|
||||||
|
inp_cpy[i-15] = input[i];
|
||||||
|
}
|
||||||
|
inp_cpy[(*size) - 15] = '\0';
|
||||||
|
found = prefs_autocomplete_boolean_choice(inp_cpy);
|
||||||
|
if (found != NULL) {
|
||||||
|
auto_msg = (char *) malloc((15 + (strlen(found) + 1)) * sizeof(char));
|
||||||
|
strcpy(auto_msg, "/notify invite ");
|
||||||
|
strcat(auto_msg, found);
|
||||||
|
inp_replace_input(input, auto_msg, size);
|
||||||
|
free(auto_msg);
|
||||||
|
free(found);
|
||||||
|
}
|
||||||
|
} else if ((strncmp(input, "/notify sub ", 12) == 0) && (*size > 12)) {
|
||||||
|
for(i = 12; i < *size; i++) {
|
||||||
|
inp_cpy[i-12] = input[i];
|
||||||
|
}
|
||||||
|
inp_cpy[(*size) - 12] = '\0';
|
||||||
|
found = prefs_autocomplete_boolean_choice(inp_cpy);
|
||||||
|
if (found != NULL) {
|
||||||
|
auto_msg = (char *) malloc((12 + (strlen(found) + 1)) * sizeof(char));
|
||||||
|
strcpy(auto_msg, "/notify sub ");
|
||||||
|
strcat(auto_msg, found);
|
||||||
|
inp_replace_input(input, auto_msg, size);
|
||||||
|
free(auto_msg);
|
||||||
|
free(found);
|
||||||
|
}
|
||||||
} else if ((strncmp(input, "/notify ", 8) == 0) && (*size > 8)) {
|
} else if ((strncmp(input, "/notify ", 8) == 0) && (*size > 8)) {
|
||||||
_parameter_autocomplete_with_ac(input, size, "/notify", notify_ac);
|
_parameter_autocomplete_with_ac(input, size, "/notify", notify_ac);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,6 +300,7 @@ _get_group(preference_t pref)
|
|||||||
case PREF_NOTIFY_TYPING:
|
case PREF_NOTIFY_TYPING:
|
||||||
case PREF_NOTIFY_MESSAGE:
|
case PREF_NOTIFY_MESSAGE:
|
||||||
case PREF_NOTIFY_INVITE:
|
case PREF_NOTIFY_INVITE:
|
||||||
|
case PREF_NOTIFY_SUB:
|
||||||
return "notifications";
|
return "notifications";
|
||||||
case PREF_CHLOG:
|
case PREF_CHLOG:
|
||||||
return "logging";
|
return "logging";
|
||||||
@@ -347,6 +348,8 @@ _get_key(preference_t pref)
|
|||||||
return "message";
|
return "message";
|
||||||
case PREF_NOTIFY_INVITE:
|
case PREF_NOTIFY_INVITE:
|
||||||
return "invite";
|
return "invite";
|
||||||
|
case PREF_NOTIFY_SUB:
|
||||||
|
return "sub";
|
||||||
case PREF_CHLOG:
|
case PREF_CHLOG:
|
||||||
return "chlog";
|
return "chlog";
|
||||||
case PREF_AUTOAWAY_CHECK:
|
case PREF_AUTOAWAY_CHECK:
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ typedef enum {
|
|||||||
PREF_NOTIFY_TYPING,
|
PREF_NOTIFY_TYPING,
|
||||||
PREF_NOTIFY_MESSAGE,
|
PREF_NOTIFY_MESSAGE,
|
||||||
PREF_NOTIFY_INVITE,
|
PREF_NOTIFY_INVITE,
|
||||||
|
PREF_NOTIFY_SUB,
|
||||||
PREF_CHLOG,
|
PREF_CHLOG,
|
||||||
PREF_AUTOAWAY_CHECK,
|
PREF_AUTOAWAY_CHECK,
|
||||||
PREF_AUTOAWAY_MODE,
|
PREF_AUTOAWAY_MODE,
|
||||||
|
|||||||
@@ -169,6 +169,9 @@ prof_handle_subscription(const char *from, jabber_subscr_t type)
|
|||||||
log_info("Received authorization request from %s", from);
|
log_info("Received authorization request from %s", from);
|
||||||
ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject");
|
ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject");
|
||||||
ui_current_page_off();
|
ui_current_page_off();
|
||||||
|
if (prefs_get_boolean(PREF_NOTIFY_SUB)) {
|
||||||
|
notify_subscription(from);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case PRESENCE_SUBSCRIBED:
|
case PRESENCE_SUBSCRIBED:
|
||||||
cons_show("Subscription received from %s", from);
|
cons_show("Subscription received from %s", from);
|
||||||
|
|||||||
@@ -92,6 +92,15 @@ notify_message(const char * const short_from)
|
|||||||
_notify(message, 10000, "Incoming message");
|
_notify(message, 10000, "Incoming message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_subscription(const char * const from)
|
||||||
|
{
|
||||||
|
GString *message = g_string_new("Subscription request: \n");
|
||||||
|
g_string_append(message, from);
|
||||||
|
_notify(message->str, 10000, "Incomming message");
|
||||||
|
g_string_free(message, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
notify_remind(void)
|
notify_remind(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,3 +28,4 @@ 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,
|
void notify_invite(const char * const from, const char * const room,
|
||||||
const char * const reason);
|
const char * const reason);
|
||||||
|
void notify_subscription(const char * const from);
|
||||||
|
|||||||
Reference in New Issue
Block a user