1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Add 'Loading messages' message when scrolling up

This commit is contained in:
MarcoPolo-PasTonMolo 2022-07-04 12:39:59 +03:00
parent 97a610e915
commit e9da694265
4 changed files with 24 additions and 5 deletions

View File

@ -153,6 +153,14 @@ buffer_remove_entry_by_id(ProfBuff buffer, const char* const id)
}
}
void
buffer_remove_entry(ProfBuff buffer, int entry)
{
GSList* node = g_slist_nth(buffer->entries, entry);
_free_entry(node->data);
buffer->entries = g_slist_delete_link(buffer->entries, node);
}
gboolean
buffer_mark_received(ProfBuff buffer, const char* const id)
{

View File

@ -72,6 +72,7 @@ void buffer_free(ProfBuff buffer);
void buffer_append(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id);
void buffer_prepend(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id);
void buffer_remove_entry_by_id(ProfBuff buffer, const char* const id);
void buffer_remove_entry(ProfBuff buffer, int entry);
int buffer_size(ProfBuff buffer);
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char* const id);

View File

@ -602,11 +602,19 @@ win_page_up(ProfWin* window)
if (*page_start == -page_space && prefs_get_boolean(PREF_MAM) && window->type == WIN_CHAT) {
ProfChatWin* chatwin = (ProfChatWin*) window;
if (!chatwin_old_history(chatwin)) {
cons_show("Fetched mam");
iq_mam_request_older(chatwin);
} else {
cons_show("Showed history");
ProfBuffEntry* first_entry = buffer_size(window->layout->buffer) != 0 ? buffer_get_entry(window->layout->buffer, 0) : NULL;
char* loading_text = "Loading older 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_text) == 0)) {
if (!chatwin_old_history(chatwin)) {
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);
iq_mam_request_older(chatwin);
} else {
cons_show("Showed history");
}
}
}

View File

@ -2580,6 +2580,8 @@ _mam_buffer_commit_handler(xmpp_stanza_t* const stanza, void* const userdata)
{
ProfChatWin* chatwin = (ProfChatWin*)userdata;
cons_show("Comitted history");
// Remove the "Loading messages ..." message
buffer_remove_entry(((ProfWin*)chatwin)->layout->buffer, 0);
chatwin_old_history(chatwin);
return 0;
}