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

Add support for offline MUC notifications

This commit is contained in:
Stefan Ott 2022-04-14 04:25:30 +02:00
parent 652d30bb7f
commit 8044c82614
9 changed files with 63 additions and 1 deletions

View File

@ -35,6 +35,7 @@ typing=true
typing.current=false
message.text=true
room.text=true
room.offline=true
[alias]
colour=/color

View File

@ -146,6 +146,7 @@ static Autocomplete notify_chat_ac;
static Autocomplete notify_room_ac;
static Autocomplete notify_typing_ac;
static Autocomplete notify_mention_ac;
static Autocomplete notify_offline_ac;
static Autocomplete notify_trigger_ac;
static Autocomplete prefs_ac;
static Autocomplete sub_ac;
@ -344,6 +345,7 @@ cmd_ac_init(void)
autocomplete_add(notify_room_ac, "on");
autocomplete_add(notify_room_ac, "off");
autocomplete_add(notify_room_ac, "mention");
autocomplete_add(notify_room_ac, "offline");
autocomplete_add(notify_room_ac, "current");
autocomplete_add(notify_room_ac, "text");
autocomplete_add(notify_room_ac, "trigger");
@ -361,6 +363,10 @@ cmd_ac_init(void)
autocomplete_add(notify_mention_ac, "word_whole");
autocomplete_add(notify_mention_ac, "word_part");
notify_offline_ac = autocomplete_new();
autocomplete_add(notify_offline_ac, "on");
autocomplete_add(notify_offline_ac, "off");
notify_trigger_ac = autocomplete_new();
autocomplete_add(notify_trigger_ac, "add");
autocomplete_add(notify_trigger_ac, "remove");
@ -2338,6 +2344,11 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous
return result;
}
result = autocomplete_param_with_ac(input, "/notify room offline", notify_offline_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE, previous);
if (result) {
return result;

View File

@ -1436,6 +1436,7 @@ static struct cmd_t command_defs[] = {
"/notify room mention on|off",
"/notify room mention case_sensitive|case_insensitive",
"/notify room mention word_whole|word_part",
"/notify room offline on|off",
"/notify room current on|off",
"/notify room text on|off",
"/notify room trigger add <text>",
@ -1464,6 +1465,7 @@ static struct cmd_t command_defs[] = {
{ "room mention case_insensitive", "Set room mention notifications as case insensitive." },
{ "room mention word_whole", "Set room mention notifications only on whole word match, i.e. when nickname is not part of a larger word." },
{ "room mention word_part", "Set room mention notifications on partial word match, i.e. nickname may be part of a larger word." },
{ "room offline on|off", "Notifications for chat room messages that were sent while you were offline." },
{ "room current on|off", "Whether to show all chat room messages notifications when the window is focused." },
{ "room text on|off", "Show message text in chat room message notifications." },
{ "room trigger add <text>", "Notify when specified text included in all chat room messages." },
@ -1483,6 +1485,7 @@ static struct cmd_t command_defs[] = {
"/notify chat on",
"/notify chat text on",
"/notify room mention on",
"/notify room offline on",
"/notify room trigger add beer",
"/notify room trigger on",
"/notify room current off",

View File

@ -5775,6 +5775,16 @@ cmd_notify(ProfWin* window, const char* const command, gchar** args)
} else {
cons_show("Usage: /notify room mention on|off");
}
} else if (g_strcmp0(args[1], "offline") == 0) {
if (g_strcmp0(args[2], "on") == 0) {
cons_show("Room notifications for offline messages enabled.");
prefs_set_boolean(PREF_NOTIFY_ROOM_OFFLINE, TRUE);
} else if (g_strcmp0(args[2], "off") == 0) {
cons_show("Room notifications for offline messages disabled.");
prefs_set_boolean(PREF_NOTIFY_ROOM_OFFLINE, FALSE);
} else {
cons_show("Usage: /notify room offline on|off");
}
} else if (g_strcmp0(args[1], "current") == 0) {
if (g_strcmp0(args[2], "on") == 0) {
cons_show("Current window chat room message notifications enabled.");

View File

@ -1828,6 +1828,7 @@ _get_group(preference_t pref)
case PREF_NOTIFY_CHAT_TEXT:
case PREF_NOTIFY_ROOM:
case PREF_NOTIFY_ROOM_MENTION:
case PREF_NOTIFY_ROOM_OFFLINE:
case PREF_NOTIFY_ROOM_TRIGGER:
case PREF_NOTIFY_ROOM_CURRENT:
case PREF_NOTIFY_ROOM_TEXT:
@ -1964,6 +1965,8 @@ _get_key(preference_t pref)
return "room.trigger";
case PREF_NOTIFY_ROOM_MENTION:
return "room.mention";
case PREF_NOTIFY_ROOM_OFFLINE:
return "room.offline";
case PREF_NOTIFY_ROOM_CURRENT:
return "room.current";
case PREF_NOTIFY_ROOM_TEXT:

View File

@ -176,6 +176,7 @@ typedef enum {
PREF_URL_SAVE_CMD,
PREF_COMPOSE_EDITOR,
PREF_SILENCE_NON_ROSTER,
PREF_NOTIFY_ROOM_OFFLINE,
} preference_t;
typedef struct prof_alias_t

View File

@ -50,6 +50,7 @@
#include "config/cafile.h"
#include "config/scripts.h"
#include "event/client_events.h"
#include "event/server_events.h"
#include "event/common.h"
#include "plugins/plugins.h"
#include "ui/window_list.h"
@ -272,6 +273,33 @@ sv_ev_room_subject(const char* const room, const char* const nick, const char* c
void
sv_ev_room_history(ProfMessage* message)
{
if (prefs_get_boolean(PREF_NOTIFY_ROOM_OFFLINE)) {
// check if this message was sent while we were offline.
// if so, treat it as a new message rather than a history event.
char* account_name = session_get_account_name();
char* last_activity = accounts_get_last_activity(account_name);
int msg_is_new = 0;
if (last_activity) {
GTimeVal lasttv;
if (g_time_val_from_iso8601(last_activity, &lasttv)) {
GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv);
GDateTime* msgdt = message->timestamp;
GTimeSpan time_diff = g_date_time_difference(msgdt, lastdt);
msg_is_new = (time_diff > 0);
g_date_time_unref(lastdt);
}
g_free(last_activity);
if (msg_is_new) {
sv_ev_room_message(message);
return;
}
}
}
ProfMucWin* mucwin = wins_get_muc(message->from_jid->barejid);
if (mucwin) {
// if this is the first successful connection

View File

@ -55,7 +55,7 @@ void sv_ev_delayed_private_message(ProfMessage* message);
void sv_ev_typing(char* barejid, char* resource);
void sv_ev_paused(char* barejid, char* resource);
void sv_ev_inactive(char* barejid, char* resource);
void sv_ev_activity(char* barejid, char* resource, gboolean send_states);
void sv_ev_activity(const char* barejid, const char* resource, gboolean send_states);
void sv_ev_gone(const char* const barejid, const char* const resource);
void sv_ev_subscription(const char* from, jabber_subscr_t type);
void sv_ev_message_receipt(const char* const barejid, const char* const id);

View File

@ -1717,6 +1717,11 @@ cons_notify_setting(void)
else
cons_show("Room mention (/notify room) : OFF");
if (prefs_get_boolean(PREF_NOTIFY_ROOM_OFFLINE))
cons_show("Room offline messages (/notify room): ON");
else
cons_show("Room offline messages (/notify room): OFF");
if (prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE))
cons_show("Room mention case (/notify room) : Case sensitive");
else