about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-07-04 12:39:59 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-07-04 12:39:59 +0300
commite9da69426527c242c72f88e74f82724c0ea20c39 (patch)
tree00bdd8b0827400113f5dcf443011b66a988df30f /src
parent97a610e915d178ff136d3c93bdb3c7c6f97666ff (diff)
downloadprofani-tty-e9da69426527c242c72f88e74f82724c0ea20c39.tar.gz
Add 'Loading messages' message when scrolling up
Diffstat (limited to 'src')
-rw-r--r--src/ui/buffer.c8
-rw-r--r--src/ui/buffer.h1
-rw-r--r--src/ui/window.c18
-rw-r--r--src/xmpp/iq.c2
4 files changed, 24 insertions, 5 deletions
diff --git a/src/ui/buffer.c b/src/ui/buffer.c
index 0203c35c..553dc325 100644
--- a/src/ui/buffer.c
+++ b/src/ui/buffer.c
@@ -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)
 {
diff --git a/src/ui/buffer.h b/src/ui/buffer.h
index e3e79655..535df882 100644
--- a/src/ui/buffer.h
+++ b/src/ui/buffer.h
@@ -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);
diff --git a/src/ui/window.c b/src/ui/window.c
index 4794e5c0..1dedb1d8 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -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");
+            }
         }
     }
 
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index d51560be..d2ae7de2 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -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;
 }