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 00:06:04 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-07-05 00:06:04 +0300
commit6429698f18b8b1fe3f8252402104c9701e62b620 (patch)
treefa9f8733fa8fb2d29a8aa7ccf703673c376466f7 /src/ui
parente9da69426527c242c72f88e74f82724c0ea20c39 (diff)
downloadprofani-tty-6429698f18b8b1fe3f8252402104c9701e62b620.tar.gz
Fix initial MAM not displaying
Did this by waiting for a batch of MAM messages to arrive before
prepending them to the buffer. Also limited the number of messages
to fetch to 10 so that the user gets more frequent updates.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/chatwin.c15
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c13
3 files changed, 16 insertions, 14 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index 02068837..82df1e80 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -66,8 +66,11 @@ chatwin_new(const char* const barejid)
     ProfWin* window = wins_new_chat(barejid);
     ProfChatWin* chatwin = (ProfChatWin*)window;
 
-    if (prefs_get_boolean(PREF_MAM) || (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY))) {
+    if (!prefs_get_boolean(PREF_MAM) || (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY))) {
+        if (0) {
+            
         _chatwin_history(chatwin, barejid);
+        }
     }
 
     // if the contact is offline, show a message
@@ -307,7 +310,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
         // MUCPMs also get printed here. In their case we don't save any logs (because nick owners can change) and thus we shouldn't read logs
         // (and if we do we need to check the resourcepart)
         if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY) && message->type == PROF_MSG_TYPE_CHAT) {
-            _chatwin_history(chatwin, chatwin->barejid);
+            /* _chatwin_history(chatwin, chatwin->barejid); */
         }
 
         // show users status first, when receiving message via delayed delivery
@@ -518,7 +521,7 @@ static void
 _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
 {
     if (!chatwin->history_shown) {
-        GSList* history = log_database_get_previous_chat(contact_barejid, NULL, FALSE);
+        GSList* history = log_database_get_previous_chat(contact_barejid, NULL, NULL, FALSE);
         GSList* curr = history;
 
         while (curr) {
@@ -538,11 +541,11 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
 }
 
 gboolean
-chatwin_old_history(ProfChatWin* chatwin)
+chatwin_old_history(ProfChatWin* chatwin, char* start_time)
 {
     // TODO: not correct location but check whether notifications get screwed
-    GDateTime* time = buffer_size(((ProfWin*)chatwin)->layout->buffer) == 0 ? NULL : buffer_get_entry(((ProfWin*)chatwin)->layout->buffer, 0)->time;
-    GSList* history = log_database_get_previous_chat(chatwin->barejid, time, TRUE);
+    char* 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, TRUE);
     gboolean has_items = g_slist_length(history) != 0;
     GSList* curr = history;
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 264ce38b..1b87783a 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -145,7 +145,7 @@ void chatwin_set_incoming_char(ProfChatWin* chatwin, const char* const ch);
 void chatwin_unset_incoming_char(ProfChatWin* chatwin);
 void chatwin_set_outgoing_char(ProfChatWin* chatwin, const char* const ch);
 void chatwin_unset_outgoing_char(ProfChatWin* chatwin);
-gboolean chatwin_old_history(ProfChatWin* chatwin);
+gboolean chatwin_old_history(ProfChatWin* chatwin, char* start_date);
 
 // MUC window
 ProfMucWin* mucwin_new(const char* const barejid);
diff --git a/src/ui/window.c b/src/ui/window.c
index 1dedb1d8..391aec21 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -61,6 +61,7 @@
 #include "xmpp/xmpp.h"
 #include "xmpp/roster_list.h"
 #include "xmpp/connection.h"
+#include "database.h"
 
 #define CONS_WIN_TITLE "Profanity. Type /help for help information."
 #define XML_WIN_TITLE  "XML Console"
@@ -607,7 +608,7 @@ win_page_up(ProfWin* window)
 
         // 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)) {
+            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);
@@ -1211,8 +1212,8 @@ win_print_incoming(ProfWin* window, const char* const display_name_from, ProfMes
         if (prefs_get_boolean(PREF_CORRECTION_ALLOW) && message->replace_id) {
             _win_correct(window, message->plain, message->id, message->replace_id, message->from_jid->barejid);
         } else {
-            // Prevent duplicate messages when current client is sending a message
-            if (g_strcmp0(message->from_jid->fulljid, connection_get_fulljid()) != 0) {
+            // Prevent duplicate messages when current client is sending a message or if it's mam
+            if (g_strcmp0(message->from_jid->fulljid, connection_get_fulljid()) != 0 && !message->is_mam) {
                 _win_printf(window, enc_char, 0, message->timestamp, flags, THEME_TEXT_THEM, display_name_from, message->from_jid->barejid, message->id, "%s", message->plain);
             }
         }
@@ -1550,10 +1551,8 @@ _win_printf(ProfWin* window, const char* show_char, int pad_indent, GDateTime* t
     GString* fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    if (buffer_size(window->layout->buffer) == 0 || g_date_time_compare(buffer_get_entry(window->layout->buffer, 0)->time, timestamp) != 1) {
-        buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, display_from, from_jid, fmt_msg->str, NULL, message_id);
-        _win_print_internal(window, show_char, pad_indent, timestamp, flags, theme_item, display_from, fmt_msg->str, NULL);
-    }
+    buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, display_from, from_jid, fmt_msg->str, NULL, message_id);
+    _win_print_internal(window, show_char, pad_indent, timestamp, flags, theme_item, display_from, fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
     g_date_time_unref(timestamp);