mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
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.
This commit is contained in:
parent
ea39657b0a
commit
88b4fdd50e
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user