From ad9263520e8c3c151d48ba579bece5f705c2131e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 3 Jul 2019 09:19:24 +0200 Subject: Show MUC history on intentional reconnect Small bug caused by 13675fb and ce5a4ed. Fix https://github.com/profanity-im/profanity/issues/1142 --- src/event/client_events.c | 2 ++ src/event/common.c | 31 +++++++++++++++++++++++++++++++ src/event/common.h | 4 ++++ src/event/server_events.c | 12 +++++------- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/event/client_events.c b/src/event/client_events.c index 9368931b..c3037392 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -89,6 +89,8 @@ cl_ev_disconnect(void) ui_close_all_wins(); ev_disconnect_cleanup(); + // on intentional disconnect reset the counter + ev_reset_connection_counter(); } void diff --git a/src/event/common.c b/src/event/common.c index dd5ede98..f267778f 100644 --- a/src/event/common.c +++ b/src/event/common.c @@ -47,6 +47,8 @@ #include "omemo/omemo.h" #endif +static gint _success_connections_counter = 0; + void ev_disconnect_cleanup(void) { @@ -66,3 +68,32 @@ ev_disconnect_cleanup(void) #endif } +gboolean +ev_was_connected_already(void) +{ + if (_success_connections_counter > 0) + return TRUE; + else + return FALSE; +} + +gboolean +ev_is_first_connect(void) +{ + if (_success_connections_counter == 1) + return TRUE; + else + return FALSE; +} + +void +ev_inc_connection_counter(void) +{ + _success_connections_counter++; +} + +void +ev_reset_connection_counter(void) +{ + _success_connections_counter = 0; +} diff --git a/src/event/common.h b/src/event/common.h index 8af86933..c0b3803a 100644 --- a/src/event/common.h +++ b/src/event/common.h @@ -36,5 +36,9 @@ #define EVENT_COMMON_H void ev_disconnect_cleanup(void); +void ev_inc_connection_counter(void); +void ev_reset_connection_counter(void); +gboolean ev_was_connected_already(void); +gboolean ev_is_first_connect(void); #endif diff --git a/src/event/server_events.c b/src/event/server_events.c index 97dabb5f..86a9ae8d 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -67,8 +67,6 @@ #include "ui/ui.h" -gint _success_connections_counter = 0; - void sv_ev_login_account_success(char *account_name, gboolean secured) { @@ -104,13 +102,13 @@ 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) + if (ev_was_connected_already()) { cons_show("Connection re-established."); wins_reestablished_connection(); } - _success_connections_counter++; + ev_inc_connection_counter(); if (account->startscript) { scripts_exec(account->startscript); @@ -261,7 +259,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) && _success_connections_counter == 1) { + if (mucwin && muc_roster_complete(room) && ev_is_first_connect()) { mucwin_subject(mucwin, nick, subject); } } @@ -272,7 +270,7 @@ sv_ev_room_history(ProfMessage *message) ProfMucWin *mucwin = wins_get_muc(message->jid->barejid); if (mucwin) { // if this is the first successful connection - if (_success_connections_counter == 1) { + if (ev_is_first_connect()) { // save timestamp of last received muc message // so we dont display, if there was no activity in channel, once we reconnect if (mucwin->last_msg_timestamp) { @@ -282,7 +280,7 @@ sv_ev_room_history(ProfMessage *message) } gboolean younger = g_date_time_compare(mucwin->last_msg_timestamp, message->timestamp) < 0 ? TRUE : FALSE; - if (_success_connections_counter == 1 || younger ) { + if (ev_is_first_connect() || younger ) { mucwin_history(mucwin, message->jid->resourcepart, message->timestamp, message->plain); } } -- cgit 1.4.1-2-gfad0