1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

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.
This commit is contained in:
MarcoPolo-PasTonMolo 2022-07-03 21:30:02 +03:00
parent ea83165a35
commit 97a610e915
3 changed files with 52 additions and 1 deletions

View File

@ -602,8 +602,14 @@ win_page_up(ProfWin* window)
if (*page_start == -page_space && prefs_get_boolean(PREF_MAM) && window->type == WIN_CHAT) {
ProfChatWin* chatwin = (ProfChatWin*) window;
chatwin_old_history(chatwin);
if (!chatwin_old_history(chatwin)) {
cons_show("Fetched mam");
iq_mam_request_older(chatwin);
} else {
cons_show("Showed history");
}
}
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;

View File

@ -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)
{

View File

@ -64,6 +64,7 @@
#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify"
#define XMPP_FEATURE_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
#define XMPP_FEATURE_MAM2 "urn:xmpp:mam:2"
#define XMPP_FEATURE_MAM2_EXTENDED "urn:xmpp:mam:2#extended"
#define XMPP_FEATURE_SPAM_REPORTING "urn:xmpp:reporting:1"
typedef enum {
@ -261,6 +262,7 @@ void iq_http_upload_request(HTTPUpload* upload);
void iq_command_list(const char* const target);
void iq_command_exec(const char* const target, const char* const command);
void iq_mam_request(ProfChatWin* win);
void iq_mam_request_older(ProfChatWin* win);
void iq_register_change_password(const char* const user, const char* const password);
void iq_muc_register_nick(const char* const roomjid);