1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Have ability to scroll through history even without MAM

This commit is contained in:
MarcoPolo-PasTonMolo 2022-07-10 10:44:06 +03:00
parent 47b3e528e2
commit 85aaf40432
4 changed files with 13 additions and 10 deletions

View File

@ -233,9 +233,11 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
return msg; return msg;
} }
// Query previous chat // Query previous chats, constraints start_time and end_time. If end_time is
// null the current time is used. from_start gets first few messages if true
// otherwise the last ones. Flip flips the order of the results
GSList* GSList*
log_database_get_previous_chat(const gchar* const contact_barejid, char* start_time, char* end_time, gboolean flip) log_database_get_previous_chat(const gchar* const contact_barejid, char* start_time, char* end_time, gboolean from_start, gboolean flip)
{ {
sqlite3_stmt* stmt = NULL; sqlite3_stmt* stmt = NULL;
gchar* query; gchar* query;
@ -245,10 +247,11 @@ log_database_get_previous_chat(const gchar* const contact_barejid, char* start_t
return NULL; return NULL;
// Flip order when querying older pages // Flip order when querying older pages
gchar* sort = !flip ? "ASC" : "DESC"; gchar* sort1 = from_start ? "ASC" : "DESC";
gchar* sort2 = !flip ? "ASC" : "DESC";
GDateTime* now = g_date_time_new_now_local(); GDateTime* now = g_date_time_new_now_local();
gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now); gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(now);
query = sqlite3_mprintf("SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE ((`from_jid` = '%q' AND `to_jid` = '%q') OR (`from_jid` = '%q' AND `to_jid` = '%q')) AND `timestamp` < '%q' AND (%Q IS NULL OR `timestamp` > %Q) ORDER BY `timestamp` %s LIMIT %d) ORDER BY `timestamp` %s;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_time, start_time, sort, MESSAGES_TO_RETRIEVE, sort); query = sqlite3_mprintf("SELECT * FROM (SELECT `message`, `timestamp`, `from_jid`, `type` from `ChatLogs` WHERE ((`from_jid` = '%q' AND `to_jid` = '%q') OR (`from_jid` = '%q' AND `to_jid` = '%q')) AND `timestamp` < '%q' AND (%Q IS NULL OR `timestamp` > %Q) ORDER BY `timestamp` %s LIMIT %d) ORDER BY `timestamp` %s;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_time, start_time, sort1, MESSAGES_TO_RETRIEVE, sort2);
g_date_time_unref(now); g_date_time_unref(now);
g_free(end_date_fmt); g_free(end_date_fmt);

View File

@ -47,7 +47,7 @@ void log_database_add_incoming(ProfMessage* message);
void log_database_add_outgoing_chat(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc); void log_database_add_outgoing_chat(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc);
void log_database_add_outgoing_muc(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc); void log_database_add_outgoing_muc(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc);
void log_database_add_outgoing_muc_pm(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc); void log_database_add_outgoing_muc_pm(const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc);
GSList* log_database_get_previous_chat(const gchar* const contact_barejid, char* start_time, char* end_time, gboolean flip); GSList* log_database_get_previous_chat(const gchar* const contact_barejid, char* start_time, char* end_time, gboolean from_start, gboolean flip);
ProfMessage* log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_last); ProfMessage* log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_last);
void log_database_close(void); void log_database_close(void);

View File

@ -519,7 +519,7 @@ static void
_chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid) _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
{ {
if (!chatwin->history_shown) { if (!chatwin->history_shown) {
GSList* history = log_database_get_previous_chat(contact_barejid, NULL, NULL, FALSE); GSList* history = log_database_get_previous_chat(contact_barejid, NULL, NULL, FALSE, FALSE);
GSList* curr = history; GSList* curr = history;
while (curr) { while (curr) {
@ -547,7 +547,7 @@ chatwin_db_history(ProfChatWin* chatwin, char* start_time, char* end_time, gbool
end_time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : g_date_time_format_iso8601(buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->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); GSList* history = log_database_get_previous_chat(chatwin->barejid, start_time, end_time, !flip, flip);
gboolean has_items = g_slist_length(history) != 0; gboolean has_items = g_slist_length(history) != 0;
GSList* curr = history; GSList* curr = history;

View File

@ -601,13 +601,13 @@ win_page_up(ProfWin* window)
*page_start -= page_space; *page_start -= page_space;
if (*page_start == -page_space && prefs_get_boolean(PREF_MAM) && window->type == WIN_CHAT) { if (*page_start == -page_space && window->type == WIN_CHAT) {
ProfChatWin* chatwin = (ProfChatWin*) window; ProfChatWin* chatwin = (ProfChatWin*) window;
ProfBuffEntry* first_entry = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0) : NULL; ProfBuffEntry* first_entry = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0) : NULL;
// Don't do anything if still fetching mam messages // 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 (first_entry && !(first_entry->theme_item == THEME_ROOMINFO && g_strcmp0(first_entry->message, LOADING_MESSAGE) == 0)) {
if (!chatwin_db_history(chatwin, NULL, NULL, TRUE)) { if (!chatwin_db_history(chatwin, NULL, NULL, TRUE) && prefs_get_boolean(PREF_MAM)) {
win_print_loading_history(window); win_print_loading_history(window);
iq_mam_request_older(chatwin); iq_mam_request_older(chatwin);
} }
@ -638,7 +638,7 @@ win_page_down(ProfWin* window)
*page_start += page_space; *page_start += page_space;
// Scrolled down after reaching the bottom of the page // 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) { if ((*page_start == y || (*page_start == page_space && *page_start >= y)) && window->type == WIN_CHAT) {
int bf_size = buffer_size(window->layout->buffer); int bf_size = buffer_size(window->layout->buffer);
if (bf_size > 0) { if (bf_size > 0) {
char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time); char* start = g_date_time_format_iso8601(buffer_get_entry(window->layout->buffer, bf_size - 1)->time);