From 88b4fdd50ee162d8734843f965d657a522a6fc62 Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:29:51 +0100 Subject: [PATCH] Add database borders check Stop fetching message from DB when profanity reached start or end of the history with the user. This allows to save resources on page up/down when ceiling or bottom accordingly are reached. --- src/ui/window.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ui/window.c b/src/ui/window.c index 730859d2..808c26bc 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -75,6 +75,9 @@ static void _win_print_internal(ProfWin* window, const char* show_char, int pad_ int flags, theme_item_t theme_item, const char* const from, const char* const message, DeliveryReceipt* receipt); static void _win_print_wrapped(WINDOW* win, const char* const message, size_t indent, int pad_indent); +static gboolean _reached_top_of_database = FALSE; +static gboolean _reached_bottom_of_database = FALSE; + int win_roster_cols(void) { @@ -622,6 +625,7 @@ win_free(ProfWin* window) void win_page_up(ProfWin* window) { + _reached_bottom_of_database = FALSE; int rows = getmaxy(stdscr); int y = getcury(window->layout->win); int page_space = rows - 4; @@ -635,7 +639,11 @@ win_page_up(ProfWin* window) // Don't do anything if still fetching mam messages if (first_entry && !(first_entry->theme_item == THEME_ROOMINFO && g_strcmp0(first_entry->message, LOADING_MESSAGE) == 0)) { - if (!chatwin_db_history(chatwin, NULL, NULL, TRUE) && prefs_get_boolean(PREF_MAM)) { + if (!_reached_top_of_database) { + _reached_top_of_database = !chatwin_db_history(chatwin, NULL, NULL, TRUE); + } + + if (_reached_top_of_database && prefs_get_boolean(PREF_MAM)) { win_print_loading_history(window); iq_mam_request_older(chatwin); } @@ -658,6 +666,7 @@ win_page_up(ProfWin* window) void win_page_down(ProfWin* window) { + _reached_top_of_database = FALSE; int rows = getmaxy(stdscr); int y = getcury(window->layout->win); int page_space = rows - 4; @@ -673,7 +682,9 @@ win_page_down(ProfWin* window) GDateTime* now = g_date_time_new_now_local(); gchar* end = g_date_time_format_iso8601(now); // end is free'd inside - chatwin_db_history((ProfChatWin*)window, start, end, FALSE); + if (!_reached_bottom_of_database && !chatwin_db_history((ProfChatWin*)window, start, end, FALSE)) { + _reached_bottom_of_database = TRUE; + } g_date_time_unref(now); }