about summary refs log tree commit diff stats
path: root/src/event
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-05 09:33:10 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-05 09:49:50 +0200
commit13675fbf06a0d0fbae2b974596a0fb513ba22340 (patch)
tree9194b150f3db163e5086d747a06f2f0f09cd72a7 /src/event
parent06f5e94dd7792bba568af69822d57f8e699277b1 (diff)
downloadprofani-tty-13675fbf06a0d0fbae2b974596a0fb513ba22340.tar.gz
Only print room history for new messages upon reconnect
If re-establish a connection don't print the room history again.
In case there there happened nothing at all since we got the room
history on the last connection.
And in case there were no new messages during the time we have been
disconnected.

Instead of printing the room history again we now print 'Re-established
Connection'.

This adds a bit of overhead since we save the timestamp upon every MUC
message.

See: https://github.com/profanity-im/profanity/issues/704
Diffstat (limited to 'src/event')
-rw-r--r--src/event/server_events.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index b76f7cfa..b496e3e2 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -66,6 +66,9 @@
 
 #include "ui/ui.h"
 
+gint _success_connections_counter = 0;
+GDateTime *_last_muc_message;
+
 void
 sv_ev_login_account_success(char *account_name, gboolean secured)
 {
@@ -102,6 +105,15 @@ sv_ev_login_account_success(char *account_name, gboolean secured)
 
     log_info("%s logged in successfully", account->jid);
 
+    // if we have been connected before
+    if (_success_connections_counter > 0)
+    {
+        cons_show("Connection re-established.");
+        wins_reestablished_connection();
+    }
+
+    _success_connections_counter++;
+
     if (account->startscript) {
         scripts_exec(account->startscript);
     }
@@ -261,7 +273,19 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
     GDateTime *timestamp, const char *const message)
 {
     ProfMucWin *mucwin = wins_get_muc(room_jid);
-    if (mucwin) {
+
+    // if this is the first successful connection
+    if (_success_connections_counter == 1) {
+        // save timestamp of last received muc message
+        // so we dont display, if there was no activity in channel, once we reconnect
+        if (_last_muc_message) {
+            g_date_time_unref(_last_muc_message);
+        }
+        _last_muc_message  = g_date_time_new_now_local();
+    }
+
+    gboolean younger = g_date_time_compare(_last_muc_message, timestamp) < 0 ? TRUE : FALSE;
+    if (mucwin && (_success_connections_counter == 1 || younger )) {
         mucwin_history(mucwin, nick, timestamp, message);
     }
 }
@@ -338,6 +362,12 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
         }
     }
 
+    // save timestamp of last received muc message
+    if (_last_muc_message) {
+        g_date_time_unref(_last_muc_message);
+    }
+    _last_muc_message  = g_date_time_new_now_local();
+
     if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, nick, new_message, mention, triggers != NULL)) {
         Jid *jidp = jid_create(mucwin->roomjid);
         notify_room_message(nick, jidp->localpart, num, new_message);