From 13675fbf06a0d0fbae2b974596a0fb513ba22340 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 5 Jun 2019 09:33:10 +0200 Subject: 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 --- src/event/server_events.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/event') 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); -- cgit 1.4.1-2-gfad0 From d53c477e4e2589e15267fe2b3de4bc59fe32aa3e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 5 Jun 2019 09:56:00 +0200 Subject: Reduce timestamp call when saving last muc message Let's test for mucwin earlier. --- src/event/server_events.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/event') diff --git a/src/event/server_events.c b/src/event/server_events.c index b496e3e2..85c0e6ca 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -273,20 +273,21 @@ 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 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); + 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(); } - _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); + gboolean younger = g_date_time_compare(_last_muc_message, timestamp) < 0 ? TRUE : FALSE; + if (_success_connections_counter == 1 || younger ) { + mucwin_history(mucwin, nick, timestamp, message); + } } } -- cgit 1.4.1-2-gfad0 From ce5a4ed77cb8e9912747a5450b43093fb2df65f5 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 5 Jun 2019 10:03:44 +0200 Subject: Only show MUC subject on first connect For #704 we don't show the room history upon reconnect. Now we also don't show the room subject in the channel upon re-established connection. --- src/event/server_events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/event') diff --git a/src/event/server_events.c b/src/event/server_events.c index 85c0e6ca..9c89a019 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -263,7 +263,7 @@ sv_ev_room_subject(const char *const room, const char *const nick, const char *c { muc_set_subject(room, subject); ProfMucWin *mucwin = wins_get_muc(room); - if (mucwin && muc_roster_complete(room)) { + if (mucwin && muc_roster_complete(room) && _success_connections_counter == 1) { mucwin_subject(mucwin, nick, subject); } } -- cgit 1.4.1-2-gfad0 From 47e55cc1127a80397ed139bd70443cc7c277d006 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 11 Jun 2019 06:35:03 +0200 Subject: 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. --- src/event/server_events.c | 15 +++++++-------- src/ui/mucwin.c | 2 ++ src/ui/win_types.h | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/event') 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; -- cgit 1.4.1-2-gfad0