diff options
author | Michael Vetter <jubalh@iodoru.org> | 2019-06-11 07:00:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 07:00:34 +0200 |
commit | 5dd6ba73f43e8540872cb01ea3549c7d6e972101 (patch) | |
tree | bbcb42a421fa6f25613addf4be45d3a13c592eaa | |
parent | da54eaf42b88be62bfebbb84dd11cb9bdd4cd9bd (diff) | |
parent | 47e55cc1127a80397ed139bd70443cc7c277d006 (diff) | |
download | profani-tty-5dd6ba73f43e8540872cb01ea3549c7d6e972101.tar.gz |
Merge pull request #1110 from profanity-im/feature/704-ui-behaviour-reconnect
Feature/704 ui behaviour reconnect
-rw-r--r-- | src/event/server_events.c | 34 | ||||
-rw-r--r-- | src/ui/mucwin.c | 2 | ||||
-rw-r--r-- | src/ui/win_types.h | 1 | ||||
-rw-r--r-- | src/ui/window_list.c | 21 | ||||
-rw-r--r-- | src/ui/window_list.h | 1 |
5 files changed, 57 insertions, 2 deletions
diff --git a/src/event/server_events.c b/src/event/server_events.c index 7b57ef4b..269de51b 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -66,6 +66,8 @@ #include "ui/ui.h" +gint _success_connections_counter = 0; + void sv_ev_login_account_success(char *account_name, gboolean secured) { @@ -100,6 +102,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); } @@ -249,7 +260,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); } } @@ -260,7 +271,20 @@ sv_ev_room_history(const char *const room_jid, const char *const nick, { ProfMucWin *mucwin = wins_get_muc(room_jid); if (mucwin) { - mucwin_history(mucwin, nick, timestamp, message); + // 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 (mucwin->last_msg_timestamp) { + g_date_time_unref(mucwin->last_msg_timestamp); + } + mucwin->last_msg_timestamp = g_date_time_new_now_local(); + } + + 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); + } } } @@ -336,6 +360,12 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha } } + // save timestamp of last received muc message + if (mucwin->last_msg_timestamp) { + g_date_time_unref(mucwin->last_msg_timestamp); + } + 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); notify_room_message(nick, jidp->localpart, num, new_message); 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; 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); |