Compare commits
3 Commits
playground
...
fix/connec
| Author | SHA1 | Date | |
|---|---|---|---|
|
88b48000f8
|
|||
|
20af44196b
|
|||
|
84d6253561
|
@@ -139,8 +139,9 @@ static const struct cmd_t command_defs[] = {
|
||||
"Show version and license information.")
|
||||
},
|
||||
|
||||
// Max args: account + server <s> + port <p> + tls <t> + auth <a> = 9
|
||||
{ CMD_PREAMBLE("/connect",
|
||||
parse_args, 0, 7, NULL)
|
||||
parse_args, 0, 9, NULL)
|
||||
CMD_MAINFUNC(cmd_connect)
|
||||
CMD_TAGS(
|
||||
CMD_TAG_CONNECTION)
|
||||
|
||||
@@ -5356,6 +5356,8 @@ cmd_time(ProfWin* window, const char* const command, gchar** args)
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
}
|
||||
if (!set_all)
|
||||
break;
|
||||
}
|
||||
if (!set_all && n == ARRAY_SIZE(time_prefs)) {
|
||||
cons_bad_cmd_usage(command);
|
||||
|
||||
@@ -268,11 +268,7 @@ _show_scrolled(ProfWin* current)
|
||||
wattroff(win, bracket_attrs);
|
||||
|
||||
wattron(win, scrolled_attrs);
|
||||
if (current->layout->unread_msg == 0) {
|
||||
wprintw(win, "SCROLLED");
|
||||
} else {
|
||||
wprintw(win, "SCROLLED, NEW MESSAGES");
|
||||
}
|
||||
wprintw(win, "SCROLLED");
|
||||
wattroff(win, scrolled_attrs);
|
||||
|
||||
wattron(win, bracket_attrs);
|
||||
|
||||
@@ -120,7 +120,6 @@ typedef struct prof_layout_t
|
||||
ProfBuff buffer;
|
||||
int y_pos;
|
||||
int paged;
|
||||
int unread_msg;
|
||||
} ProfLayout;
|
||||
|
||||
typedef struct prof_layout_simple_t
|
||||
|
||||
@@ -103,7 +103,6 @@ _win_create_simple_layout(void)
|
||||
layout->base.buffer = buffer_create();
|
||||
layout->base.y_pos = 0;
|
||||
layout->base.paged = 0;
|
||||
layout->base.unread_msg = 0;
|
||||
scrollok(layout->base.win, TRUE);
|
||||
|
||||
return &layout->base;
|
||||
@@ -121,7 +120,6 @@ _win_create_split_layout(void)
|
||||
layout->base.buffer = buffer_create();
|
||||
layout->base.y_pos = 0;
|
||||
layout->base.paged = 0;
|
||||
layout->base.unread_msg = 0;
|
||||
scrollok(layout->base.win, TRUE);
|
||||
layout->subwin = NULL;
|
||||
layout->sub_y_pos = 0;
|
||||
@@ -199,7 +197,6 @@ win_create_muc(const char* const roomjid)
|
||||
layout->base.buffer = buffer_create();
|
||||
layout->base.y_pos = 0;
|
||||
layout->base.paged = 0;
|
||||
layout->base.unread_msg = 0;
|
||||
scrollok(layout->base.win, TRUE);
|
||||
new_win->window.layout = (ProfLayout*)layout;
|
||||
|
||||
@@ -701,11 +698,9 @@ void
|
||||
win_page_down(ProfWin* window, int scroll_size)
|
||||
{
|
||||
int total_rows = getcury(window->layout->win);
|
||||
int total_rows_with_unread = total_rows + window->layout->unread_msg;
|
||||
int* page_start = &(window->layout->y_pos);
|
||||
int page_space = getmaxy(stdscr) - 4;
|
||||
int page_start_initial = *page_start;
|
||||
|
||||
if (scroll_size == 0)
|
||||
scroll_size = page_space;
|
||||
win_scroll_state_t* scroll_state = &window->scroll_state;
|
||||
@@ -714,11 +709,7 @@ win_page_down(ProfWin* window, int scroll_size)
|
||||
*page_start += scroll_size;
|
||||
|
||||
// Scrolled down after reaching the bottom of the page
|
||||
gboolean past_bottom = *page_start > total_rows_with_unread - page_space;
|
||||
gboolean at_page_space_and_past_unread = (*page_start == page_space && *page_start >= total_rows_with_unread);
|
||||
gboolean is_chat = window->type == WIN_CHAT;
|
||||
|
||||
if ((past_bottom || at_page_space_and_past_unread) && is_chat) {
|
||||
if ((*page_start > total_rows - page_space || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) {
|
||||
int bf_size = buffer_size(window->layout->buffer);
|
||||
if (bf_size > 0 && *scroll_state != WIN_SCROLL_REACHED_BOTTOM) {
|
||||
// How many lines are left until end of the screen
|
||||
@@ -752,16 +743,13 @@ win_page_down(ProfWin* window, int scroll_size)
|
||||
window->layout->paged = 1;
|
||||
|
||||
// update only if position has changed
|
||||
if ((page_start_initial != *page_start) || window->layout->unread_msg) {
|
||||
if (page_start_initial != *page_start) {
|
||||
win_update_virtual(window);
|
||||
}
|
||||
|
||||
/* Switch off page if no messages left to read.
|
||||
* TODO: update buffer end handling to check messages just after last entry.
|
||||
*/
|
||||
if (*scroll_state == WIN_SCROLL_REACHED_BOTTOM) {
|
||||
// switch off page if last line and space line visible
|
||||
if (total_rows - *page_start == page_space) {
|
||||
window->layout->paged = 0;
|
||||
window->layout->unread_msg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,7 +810,6 @@ win_clear(ProfWin* window)
|
||||
int* page_start = &(window->layout->y_pos);
|
||||
*page_start = y;
|
||||
window->layout->paged = 1;
|
||||
window->layout->unread_msg = 0;
|
||||
win_update_virtual(window);
|
||||
}
|
||||
|
||||
@@ -927,7 +914,6 @@ void
|
||||
win_move_to_end(ProfWin* window)
|
||||
{
|
||||
window->layout->paged = 0;
|
||||
window->layout->unread_msg = 0;
|
||||
|
||||
int rows = getmaxy(stdscr);
|
||||
int y = getcury(window->layout->win);
|
||||
@@ -1710,13 +1696,6 @@ win_newline(ProfWin* window)
|
||||
static void
|
||||
_win_printf(ProfWin* window, const char* show_char, int pad_indent, GDateTime* timestamp, int flags, theme_item_t theme_item, const char* const display_from, const char* const from_jid, const char* const message_id, const char* const message, ...)
|
||||
{
|
||||
|
||||
/* Prevent printing and buffer update when user is viewing message history [SCROLLING]*/
|
||||
if (window->layout->paged && wins_is_current(window)) {
|
||||
window->layout->unread_msg++;
|
||||
return;
|
||||
}
|
||||
|
||||
if (timestamp == NULL) {
|
||||
timestamp = g_date_time_new_now_local();
|
||||
} else {
|
||||
|
||||
@@ -312,6 +312,7 @@ iq_reg2_cb(xmpp_conn_t* xmpp_conn, xmpp_stanza_t* stanza, void* userdata)
|
||||
goto quit;
|
||||
|
||||
quit:
|
||||
log_debug("[CONNDBG] iq_reg2_cb: disconnecting after registration completion");
|
||||
xmpp_disconnect(xmpp_conn);
|
||||
|
||||
return 0;
|
||||
@@ -550,6 +551,7 @@ connection_disconnect(void)
|
||||
// don't disconnect already disconnected connection,
|
||||
// or we get infinite loop otherwise
|
||||
if (conn.conn_last_event == XMPP_CONN_CONNECT) {
|
||||
log_debug("[CONNDBG] connection_disconnect: user-initiated disconnect (status=%d)", (int)conn.conn_status);
|
||||
conn.conn_status = JABBER_DISCONNECTING;
|
||||
xmpp_disconnect(conn.xmpp_conn);
|
||||
|
||||
@@ -557,6 +559,7 @@ connection_disconnect(void)
|
||||
session_process_events();
|
||||
}
|
||||
} else {
|
||||
log_debug("[CONNDBG] connection_disconnect: already disconnected (last_event=%d)", (int)conn.conn_last_event);
|
||||
conn.conn_status = JABBER_DISCONNECTED;
|
||||
}
|
||||
|
||||
@@ -1019,6 +1022,9 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
|
||||
// disconnected
|
||||
case XMPP_CONN_DISCONNECT:
|
||||
log_debug("Connection handler: XMPP_CONN_DISCONNECT");
|
||||
log_debug("[CONNDBG] disconnect: previous_status=%d error=%d has_stream_error=%s",
|
||||
(int)conn.conn_status, error,
|
||||
(stream_error && stream_error->stanza) ? "yes" : "no");
|
||||
|
||||
// lost connection for unknown reason
|
||||
if (conn.conn_status == JABBER_CONNECTED || conn.conn_status == JABBER_DISCONNECTING) {
|
||||
|
||||
@@ -218,6 +218,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
|
||||
void
|
||||
session_autoping_fail(void)
|
||||
{
|
||||
log_debug("[CONNDBG] session_autoping_fail: autoping timeout, triggering lost connection");
|
||||
session_lost_connection();
|
||||
}
|
||||
|
||||
@@ -264,11 +265,14 @@ session_process_events(void)
|
||||
if ((reconnect_sec != 0) && reconnect_timer) {
|
||||
int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
|
||||
if (elapsed_sec > reconnect_sec) {
|
||||
log_debug("[CONNDBG] session_process_events: auto-reconnect triggered after %d seconds (threshold=%d)",
|
||||
elapsed_sec, reconnect_sec);
|
||||
session_reconnect_now();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case JABBER_RECONNECT:
|
||||
log_debug("[CONNDBG] session_process_events: JABBER_RECONNECT state, calling session_reconnect_now");
|
||||
session_reconnect_now();
|
||||
break;
|
||||
default:
|
||||
@@ -327,12 +331,12 @@ session_login_success(gboolean secured)
|
||||
|
||||
// logged in with account
|
||||
if (saved_account.name) {
|
||||
log_debug("Connection handler: logged in with account name: %s", saved_account.name);
|
||||
log_debug("[CONNDBG] Connection handler: logged in with account name: %s", saved_account.name);
|
||||
sv_ev_login_account_success(saved_account.name, secured);
|
||||
|
||||
// logged in without account, use details to create new account
|
||||
} else {
|
||||
log_debug("Connection handler: logged in with jid: %s", saved_details.name);
|
||||
log_debug("[CONNDBG] Connection handler: logged in with jid: %s", saved_details.name);
|
||||
accounts_add(saved_details.name, saved_details.altdomain, saved_details.port, saved_details.tls_policy, saved_details.auth_policy);
|
||||
accounts_set_jid(saved_details.name, saved_details.jid);
|
||||
|
||||
@@ -371,11 +375,11 @@ void
|
||||
session_login_failed(void)
|
||||
{
|
||||
if (reconnect_timer == NULL) {
|
||||
log_debug("Connection handler: No reconnect timer");
|
||||
log_debug("[CONNDBG] Connection handler: No reconnect timer");
|
||||
sv_ev_failed_login();
|
||||
_session_free_internals();
|
||||
} else {
|
||||
log_debug("Connection handler: Restarting reconnect timer");
|
||||
log_debug("[CONNDBG] Connection handler: Restarting reconnect timer");
|
||||
if (prefs_get_reconnect() != 0) {
|
||||
g_timer_start(reconnect_timer);
|
||||
}
|
||||
@@ -389,12 +393,16 @@ session_login_failed(void)
|
||||
void
|
||||
session_lost_connection(void)
|
||||
{
|
||||
log_debug("[CONNDBG] session_lost_connection: connection lost, reconnect_interval=%d",
|
||||
prefs_get_reconnect());
|
||||
/* this callback also clears all cached data */
|
||||
sv_ev_lost_connection();
|
||||
if (prefs_get_reconnect() != 0) {
|
||||
assert(reconnect_timer == NULL);
|
||||
reconnect_timer = g_timer_new();
|
||||
log_debug("[CONNDBG] session_lost_connection: reconnect timer started");
|
||||
} else {
|
||||
log_debug("[CONNDBG] session_lost_connection: auto-reconnect disabled, cleaning up");
|
||||
_session_free_internals();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user