about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-07-05 11:12:29 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-07-05 11:12:29 +0300
commit4d6e95d6911eab8fc9f6ddc0706c7b2ac5a25437 (patch)
tree2ff208c64cfdfb01df37672014b6676369621997 /src/ui
parent6429698f18b8b1fe3f8252402104c9701e62b620 (diff)
downloadprofani-tty-4d6e95d6911eab8fc9f6ddc0706c7b2ac5a25437.tar.gz
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
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/chatwin.c1
-rw-r--r--src/ui/window.c12
-rw-r--r--src/ui/window.h1
3 files changed, 12 insertions, 2 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 82df1e80..a89e4626 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -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;
diff --git a/src/ui/window.c b/src/ui/window.c
index 391aec21..e168b70c 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -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)
 {
diff --git a/src/ui/window.h b/src/ui/window.h
index 174785b1..822f12b0 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -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);