mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge pull request #1110 from profanity-im/feature/704-ui-behaviour-reconnect
Feature/704 ui behaviour reconnect
This commit is contained in:
commit
5dd6ba73f4
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -845,6 +845,27 @@ wins_lost_connection(void)
|
||||
g_list_free(values);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user