about summary refs log tree commit diff stats
path: root/src
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
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')
-rw-r--r--src/event/server_events.c32
-rw-r--r--src/ui/window_list.c21
-rw-r--r--src/ui/window_list.h1
3 files changed, 53 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);
diff --git a/src/ui/window_list.c b/src/ui/window_list.c
index 43230b57..6e2f82dd 100644
--- a/src/ui/window_list.c
+++ b/src/ui/window_list.c
@@ -846,6 +846,27 @@ wins_lost_connection(void)
 }
 
 void
+wins_reestablished_connection(void)
+{
+    GList *values = g_hash_table_get_values(windows);
+    GList *curr = values;
+
+    while (curr) {
+        ProfWin *window = curr->data;
+        if (window->type != WIN_CONSOLE) {
+            win_println(window, THEME_TEXT, '-', "Connection re-established.");
+
+            // if current win, set current_win_dirty
+            if (wins_is_current(window)) {
+                win_update_virtual(window);
+            }
+        }
+        curr = g_list_next(curr);
+    }
+    g_list_free(values);
+}
+
+void
 wins_swap(int source_win, int target_win)
 {
     ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
diff --git a/src/ui/window_list.h b/src/ui/window_list.h
index 6045d349..c79e9dd7 100644
--- a/src/ui/window_list.h
+++ b/src/ui/window_list.h
@@ -83,6 +83,7 @@ void wins_resize_all(void);
 GSList* wins_get_chat_recipients(void);
 GSList* wins_get_prune_wins(void);
 void wins_lost_connection(void);
+void wins_reestablished_connection(void);
 gboolean wins_tidy(void);
 GSList* wins_create_summary(gboolean unread);
 void wins_destroy(void);