mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Add loading history message on initial MAM request
This prevents scrolling to top and initiating another MAM request while still fetching the initial one. Also free timestamp object in database.c
This commit is contained in:
parent
6429698f18
commit
4d6e95d691
@ -246,7 +246,8 @@ log_database_get_previous_chat(const gchar* const contact_barejid, char* start_t
|
||||
|
||||
// Flip order when querying older pages
|
||||
gchar* sort = !flip ? "ASC" : "DESC";
|
||||
gchar* end_date_fmt = end_time ? end_time : g_date_time_format_iso8601(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* start_date_fmt = start_time ? start_time : NULL;
|
||||
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` DESC LIMIT %d) ORDER BY `timestamp` %s;", contact_barejid, myjid->barejid, myjid->barejid, contact_barejid, end_date_fmt, start_date_fmt, start_date_fmt, MESSAGES_TO_RETRIEVE, sort);
|
||||
if (!query) {
|
||||
@ -254,6 +255,7 @@ log_database_get_previous_chat(const gchar* const contact_barejid, char* start_t
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_date_time_unref(now);
|
||||
g_free(end_date_fmt);
|
||||
|
||||
jid_destroy(myjid);
|
||||
|
@ -102,6 +102,7 @@ chatwin_new(const char* const barejid)
|
||||
|
||||
if (prefs_get_boolean(PREF_MAM)) {
|
||||
iq_mam_request(chatwin);
|
||||
win_print_loading_history(window);
|
||||
}
|
||||
|
||||
return chatwin;
|
||||
|
@ -610,8 +610,7 @@ win_page_up(ProfWin* window)
|
||||
if (first_entry && !(first_entry->theme_item == THEME_ROOMINFO && g_strcmp0(first_entry->message, loading_text) == 0)) {
|
||||
if (!chatwin_old_history(chatwin, NULL)) {
|
||||
cons_show("Fetched mam");
|
||||
buffer_prepend(window->layout->buffer, "-", 0, first_entry->time, NO_DATE, THEME_ROOMINFO, NULL, NULL, loading_text, NULL, NULL);
|
||||
win_redraw(window);
|
||||
win_print_loading_history(window);
|
||||
iq_mam_request_older(chatwin);
|
||||
} else {
|
||||
cons_show("Showed history");
|
||||
@ -1855,6 +1854,15 @@ win_redraw(ProfWin* window)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
win_print_loading_history(ProfWin* window)
|
||||
{
|
||||
char* loading_text = "Loading older messages ...";
|
||||
GDateTime* timestamp = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0)->time : g_date_time_new_now_local();
|
||||
buffer_prepend(window->layout->buffer, "-", 0, timestamp, NO_DATE, THEME_ROOMINFO, NULL, NULL, loading_text, NULL, NULL);
|
||||
win_redraw(window);
|
||||
}
|
||||
|
||||
gboolean
|
||||
win_has_active_subwin(ProfWin* window)
|
||||
{
|
||||
|
@ -77,6 +77,7 @@ void win_print_http_transfer(ProfWin* window, const char* const message, char* u
|
||||
|
||||
void win_newline(ProfWin* window);
|
||||
void win_redraw(ProfWin* window);
|
||||
void win_print_loading_history(ProfWin* window);
|
||||
int win_roster_cols(void);
|
||||
int win_occpuants_cols(void);
|
||||
void win_sub_print(WINDOW* win, char* msg, gboolean newline, gboolean wrap, int indent);
|
||||
|
@ -67,6 +67,7 @@
|
||||
#include "xmpp/roster.h"
|
||||
#include "xmpp/muc.h"
|
||||
#include "src/database.h"
|
||||
#include "ui/window.h"
|
||||
|
||||
#ifdef HAVE_OMEMO
|
||||
#include "omemo/omemo.h"
|
||||
@ -2681,7 +2682,9 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
if (fin) {
|
||||
gboolean is_complete = g_strcmp0(xmpp_stanza_get_attribute(fin, "complete"), "true") == 0;
|
||||
MamRsmUserdata* data = (MamRsmUserdata*)userdata;
|
||||
ProfWin* window = (ProfWin*)data->win;
|
||||
|
||||
buffer_remove_entry(window->layout->buffer, 0);
|
||||
if (is_complete || data->end_datestr) {
|
||||
chatwin_old_history(data->win, is_complete ? NULL : data->start_datestr);
|
||||
return 0;
|
||||
@ -2690,6 +2693,8 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
||||
|
||||
xmpp_stanza_t* set = xmpp_stanza_get_child_by_name_and_ns(fin, STANZA_TYPE_SET, STANZA_NS_RSM);
|
||||
if (set) {
|
||||
win_print_loading_history(window);
|
||||
|
||||
char* firstid = NULL;
|
||||
xmpp_stanza_t* first = xmpp_stanza_get_child_by_name(set, STANZA_NAME_FIRST);
|
||||
firstid = xmpp_stanza_get_text(first);
|
||||
|
Loading…
Reference in New Issue
Block a user