Repository: profanity-im/profanity (c)

Issue:
Wrong error about server not supporting MAM.
<!--- Provide a general summary of the issue in the Title above -->
On startup profanity shows the error `Server doesn't support MAM (urn:xmpp:mam:2).` although the server supports MAM. 

<!--- More than 50 issues open? Please don't file any new feature requests -->
<!--- Help us reduce the work first :-) -->

## Expected Behavior

It should only show that error if the server really doesn't support MAM.

## Current Behavior
On startup profanity shows the error `Server doesn't support MAM (urn:xmpp:mam:2).` although the server supports MAM. 


## Steps to Reproduce (for bugs)
<!--- Describe, in detail, what needs to happen to reproduce this bug -->
<!--- Give us a screenshot (if it's helpful for this particular bug) -->
1. Start profanity and check messages in console window. (Don't know if this only happens in my set up or in general)


## Environment
* Debian Testing (trixie)


```
profanity --version
Profanity, version 0.14.0dev.master.0e66cbe4
Copyright (C) 2012 - 2019 James Booth <boothj5web@gmail.com>.
Copyright (C) 2019 - 2023 Michael Vetter <jubalh@iodoru.org>.
License GPLv3+: GNU GPL version 3 or later <https://www.gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Build information:
XMPP library: libstrophe
Desktop notification support: Enabled
OTR support: Disabled
PGP support: Enabled (libgpgme 1.18.0)
OMEMO support: Enabled
C plugins: Enabled
Python plugins: Disabled
GTK icons/clipboard: Disabled
GDK Pixbuf: Enabled
```




Discussion:
Did you try the patch I shared?
Does it happen for you on first connect as well or only on reconnect?
Going to open a PR with it when I have the time, maybe still today.
Yes, the patch worked. Just created the issue to assure it's not getting forgotten.


Patch:
diff --git a/src/event/server_events.c b/src/event/server_events.c
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -58,6 +58,7 @@
 #include "ui/window.h"
 #include "tools/bookmark_ignore.h"
 #include "xmpp/xmpp.h"
+#include "xmpp/iq.h"
 #include "xmpp/muc.h"
 #include "xmpp/chat_session.h"
 #include "xmpp/roster_list.h"
@@ -196,6 +197,7 @@ sv_ev_roster_received(void)
 void
 sv_ev_connection_features_received(void)
 {
+    iq_feature_retrieval_complete_handler();
 #ifdef HAVE_OMEMO
     omemo_publish_crypto_materials();
 #endif
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -2539,7 +2539,6 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
     if (g_strcmp0(id, "discoitemsreq") == 0) {
         cons_show_disco_items(items, from);
     } else if (g_strcmp0(id, "discoitemsreq_onconnect") == 0) {
-        received_disco_items = TRUE;
         connection_set_disco_items(items);
 
         while (late_delivery_windows) {
@@ -2554,6 +2553,12 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
     g_slist_free_full(items, (GDestroyNotify)_item_destroy);
 }
 
+void
+iq_feature_retrieval_complete_handler(void)
+{
+    received_disco_items = TRUE;
+}
+
 void
 iq_send_stanza(xmpp_stanza_t* const stanza)
 {
diff --git a/src/xmpp/iq.h b/src/xmpp/iq.h
--- a/src/xmpp/iq.h
+++ b/src/xmpp/iq.h
@@ -40,6 +40,7 @@ typedef int (*ProfIqCallback)(xmpp_stanza_t* const stanza, void* const userdata)
 typedef void (*ProfIqFreeCallback)(void* userdata);
 
 void iq_handlers_init(void);
+void iq_feature_retrieval_complete_handler(void);
 void iq_send_stanza(xmpp_stanza_t* const stanza);
 void iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata);
 void iq_disco_info_request_onconnect(const char* jid);


Test patch:
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -450,6 +450,11 @@ iq_mam_request(ProfChatWin* win, GDateTime* enddate)
 {
 }
 
+void
+iq_feature_retrieval_complete_handler(void)
+{
+}
+
 void
 publish_user_mood(const char* const mood, const char* const text)
 {