about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-11 06:35:03 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-11 06:35:03 +0200
commit47e55cc1127a80397ed139bd70443cc7c277d006 (patch)
tree47faf6a58df95db380c6c6f25fcdd9ad496bd206 /src
parentce5a4ed77cb8e9912747a5450b43093fb2df65f5 (diff)
downloadprofani-tty-47e55cc1127a80397ed139bd70443cc7c277d006.tar.gz
Safe last MUC message timestamp per MUC
After pasis review of my code he thinks it's better to safe the
timestamp per MUC so we can account for some problems that could occur
with timing.
Diffstat (limited to 'src')
-rw-r--r--src/event/server_events.c15
-rw-r--r--src/ui/mucwin.c2
-rw-r--r--src/ui/win_types.h1
3 files changed, 10 insertions, 8 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 9c89a019..bb31f9c6 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -67,7 +67,6 @@
 #include "ui/ui.h"
 
 gint _success_connections_counter = 0;
-GDateTime *_last_muc_message;
 
 void
 sv_ev_login_account_success(char *account_name, gboolean secured)
@@ -278,13 +277,13 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
         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);
+            if (mucwin->last_msg_timestamp) {
+                g_date_time_unref(mucwin->last_msg_timestamp);
             }
-            _last_muc_message  = g_date_time_new_now_local();
+            mucwin->last_msg_timestamp  = g_date_time_new_now_local();
         }
 
-        gboolean younger = g_date_time_compare(_last_muc_message, timestamp) < 0 ? TRUE : FALSE;
+        gboolean younger = g_date_time_compare(mucwin->last_msg_timestamp, timestamp) < 0 ? TRUE : FALSE;
         if (_success_connections_counter == 1 || younger ) {
             mucwin_history(mucwin, nick, timestamp, message);
         }
@@ -364,10 +363,10 @@ 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);
+    if (mucwin->last_msg_timestamp) {
+        g_date_time_unref(mucwin->last_msg_timestamp);
     }
-    _last_muc_message  = g_date_time_new_now_local();
+    mucwin->last_msg_timestamp  = 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);
diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c
index b56cd994..18fd13f4 100644
--- a/src/ui/mucwin.c
+++ b/src/ui/mucwin.c
@@ -54,6 +54,8 @@ mucwin_new(const char *const barejid)
     ProfWin *window = wins_new_muc(barejid);
     ProfMucWin *mucwin = (ProfMucWin *)window;
 
+    mucwin->last_msg_timestamp = NULL;
+
 #ifdef HAVE_OMEMO
     if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS && omemo_automatic_start(barejid)) {
         omemo_start_muc_sessions(barejid);
diff --git a/src/ui/win_types.h b/src/ui/win_types.h
index e1e64bf9..bf5a181c 100644
--- a/src/ui/win_types.h
+++ b/src/ui/win_types.h
@@ -173,6 +173,7 @@ typedef struct prof_muc_win_t {
     char *enctext;
     char *message_char;
     GHashTable *sent_messages;
+    GDateTime *last_msg_timestamp;
 } ProfMucWin;
 
 typedef struct prof_conf_win_t ProfConfWin;