diff options
author | Stefan Ott <stefan@ott.net> | 2022-04-14 04:25:30 +0200 |
---|---|---|
committer | Stefan Ott <stefan@ott.net> | 2022-04-23 02:42:23 +0200 |
commit | 8044c82614ad63b60cc0805b0335150eaccb50aa (patch) | |
tree | 50a6f61ab49f2a6e38f82cf4c2177bbde5164be0 /src/event | |
parent | 652d30bb7f7ce4dc89eebcbb4b796f10249a8be1 (diff) | |
download | profani-tty-8044c82614ad63b60cc0805b0335150eaccb50aa.tar.gz |
Add support for offline MUC notifications
Diffstat (limited to 'src/event')
-rw-r--r-- | src/event/server_events.c | 28 | ||||
-rw-r--r-- | src/event/server_events.h | 2 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c index 4a35302f..620a8b2d 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -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 diff --git a/src/event/server_events.h b/src/event/server_events.h index 55818642..53bb27f0 100644 --- a/src/event/server_events.h +++ b/src/event/server_events.h @@ -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); |