mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
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
This commit is contained in:
parent
06f5e94dd7
commit
13675fbf06
@ -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);
|
||||
|
@ -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