diff options
author | MarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com> | 2022-07-05 13:09:16 +0300 |
---|---|---|
committer | MarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com> | 2022-07-10 11:17:35 +0300 |
commit | 47b3e528e2c13a63316fa7ad2c02d9b702741dea (patch) | |
tree | 5de884d97e4d54412c81004e5455e228d118fee8 /src/ui | |
parent | b03c3bda980056f65cd696fd65883a1c351ac8d7 (diff) | |
download | profani-tty-47b3e528e2c13a63316fa7ad2c02d9b702741dea.tar.gz |
Handle scrolling down when buffer fills up
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/chatwin.c | 18 | ||||
-rw-r--r-- | src/ui/ui.h | 2 | ||||
-rw-r--r-- | src/ui/window.c | 16 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index ec7f3f7a..0b2724d3 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -538,12 +538,16 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid) } } +// Print history starting from start_time to end_time if end_time is null the +// first entrie's timestamp in the buffer is used. Flip true to prepend to buffer. gboolean -chatwin_old_history(ProfChatWin* chatwin, char* start_time) +chatwin_db_history(ProfChatWin* chatwin, char* start_time, char* end_time, gboolean flip) { - // TODO: not correct location but check whether notifications get screwed - char* end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time); - GSList* history = log_database_get_previous_chat(chatwin->barejid, start_time, end_time, TRUE); + if (!end_time) { + end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time); + } + + GSList* history = log_database_get_previous_chat(chatwin->barejid, start_time, end_time, flip); gboolean has_items = g_slist_length(history) != 0; GSList* curr = history; @@ -554,7 +558,11 @@ chatwin_old_history(ProfChatWin* chatwin, char* start_time) // This is dirty workaround for memory leak. We reassign msg->plain above so have to free previous object // TODO: Make a better solution, for example, pass msg object to the function and it will replace msg->plain properly if needed. free(msg_plain); - win_print_old_history((ProfWin*)chatwin, msg); + if (flip) { + win_print_old_history((ProfWin*)chatwin, msg); + } else { + win_print_history((ProfWin*)chatwin, msg); + } curr = g_slist_next(curr); } diff --git a/src/ui/ui.h b/src/ui/ui.h index 1b87783a..e396b18a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -145,7 +145,7 @@ void chatwin_set_incoming_char(ProfChatWin* chatwin, const char* const ch); void chatwin_unset_incoming_char(ProfChatWin* chatwin); void chatwin_set_outgoing_char(ProfChatWin* chatwin, const char* const ch); void chatwin_unset_outgoing_char(ProfChatWin* chatwin); -gboolean chatwin_old_history(ProfChatWin* chatwin, char* start_date); +gboolean chatwin_db_history(ProfChatWin* chatwin, char* start_time, char* end_time, gboolean flip); // MUC window ProfMucWin* mucwin_new(const char* const barejid); diff --git a/src/ui/window.c b/src/ui/window.c index 3bbdad01..e56b14fa 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -607,7 +607,7 @@ 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_old_history(chatwin, NULL)) { + if (!chatwin_db_history(chatwin, NULL, NULL, TRUE)) { win_print_loading_history(window); iq_mam_request_older(chatwin); } @@ -637,6 +637,20 @@ win_page_down(ProfWin* window) *page_start += page_space; + // Scrolled down after reaching the bottom of the page + if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && prefs_get_boolean(PREF_MAM) && window->type == WIN_CHAT) { + int bf_size = buffer_size(window->layout->buffer); + if (bf_size > 0) { + char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time); + GDateTime* now = g_date_time_new_now_local(); + char* end = g_date_time_format_iso8601(now); + chatwin_db_history((ProfChatWin*)window, start, end, FALSE); + + g_free(start); + g_date_time_unref(now); + } + } + // only got half a screen, show full screen if ((y - (*page_start)) < page_space) *page_start = y - page_space; |