diff options
author | MarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com> | 2022-07-03 21:30:02 +0300 |
---|---|---|
committer | MarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com> | 2022-07-03 21:30:02 +0300 |
commit | 97a610e915d178ff136d3c93bdb3c7c6f97666ff (patch) | |
tree | 33a9f610a97f2b202ec4e470737deec2f92ca7c0 /src/xmpp/iq.c | |
parent | ea83165a35370c9ebcf10da9dd6d1c53f6517008 (diff) | |
download | profani-tty-97a610e915d178ff136d3c93bdb3c7c6f97666ff.tar.gz |
Fech data from mam when all history gets displayed
Fetch from mam without displaying when all mam messages get received display new messages from db. Unstable, initial mam doesn't get displayed unless we start scrolling.
Diffstat (limited to 'src/xmpp/iq.c')
-rw-r--r-- | src/xmpp/iq.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index dd28b358..d51560be 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -2575,6 +2575,49 @@ _iq_free_affiliation_list(ProfAffiliationList* affiliation_list) } } +static int +_mam_buffer_commit_handler(xmpp_stanza_t* const stanza, void* const userdata) +{ + ProfChatWin* chatwin = (ProfChatWin*)userdata; + cons_show("Comitted history"); + chatwin_old_history(chatwin); + return 0; +} + +void +iq_mam_request_older(ProfChatWin* win) +{ + if (connection_supports(XMPP_FEATURE_MAM2) == FALSE) { + log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_MAM2); + cons_show_error("Server doesn't support MAM (%s).", XMPP_FEATURE_MAM2); + return; + } + + ProfMessage* first_msg = log_database_get_limits_info(win->barejid, FALSE); + char* firstid = NULL; + char* enddate = NULL; + + // If first message found + if (first_msg->timestamp) { + firstid = first_msg->stanzaid; + enddate = g_date_time_format(first_msg->timestamp, "%FT%T.%f%:z"); + } else { + return; + } + + xmpp_ctx_t* const ctx = connection_get_ctx(); + xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, NULL, enddate, firstid, NULL); + iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_buffer_commit_handler, NULL, win); + + g_free(enddate); + message_free(first_msg); + + iq_send_stanza(iq); + xmpp_stanza_release(iq); + + return; +} + void iq_mam_request(ProfChatWin* win) { |