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

wip: add rsm after we get the first couple of mam messages

This commit is contained in:
Michael Vetter 2020-10-28 15:57:53 +01:00
parent 69e35e86b2
commit db65255a5a
3 changed files with 46 additions and 5 deletions

View File

@ -2556,11 +2556,12 @@ iq_mam_request(ProfChatWin* win)
g_date_time_unref(now);
gchar* datestr = g_date_time_format(timestamp, "%FT%TZ");
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, datestr);
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, g_strdup(datestr));
g_free(datestr);
g_date_time_unref(timestamp);
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, NULL);
iq_send_stanza(iq);
xmpp_stanza_release(iq);
@ -2573,7 +2574,12 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
const char* type = xmpp_stanza_get_type(stanza);
if (g_strcmp0(type, "error") == 0) {
//TODO
//char* error_message = stanza_get_error_message(stanza);
/*
char* error_message = stanza_get_error_message(stanza);
cons_show_error("Server error: %s", error_message);
log_debug("Error: %s", error_message);
free(error_message);
*/
} else if (g_strcmp0(type, "result") == 0) {
xmpp_stanza_t* fin = stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_FIN, STANZA_NS_MAM2);
if (fin) {
@ -2582,6 +2588,15 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
xmpp_stanza_t* last = xmpp_stanza_get_child_by_name(set, STANZA_NAME_LAST);
char* lastid = xmpp_stanza_get_text(last);
lastid = lastid;
// 4.3.2. send same stanza with set,max stanza
xmpp_ctx_t* const ctx = connection_get_ctx();
gchar *datestr = (gchar*)userdata;
//TODO give barejid or get from stanza
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, NULL, datestr, lastid);
iq_send_stanza(iq);
xmpp_stanza_release(iq);
}
}
}

View File

@ -2615,7 +2615,7 @@ stanza_attach_correction(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza, const char* con
}
xmpp_stanza_t*
stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate)
stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char *const lastid)
{
char* id = connection_create_stanza_id();
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
@ -2674,6 +2674,23 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s
xmpp_stanza_add_child(field_start, value_start);
// 4.3.2 set/rsm
xmpp_stanza_t *after, *after_text, *set;
if (lastid) {
set = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(set, STANZA_TYPE_SET);
xmpp_stanza_set_ns(set, STANZA_NS_RSM);
after = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(after, STANZA_NAME_AFTER);
after_text = xmpp_stanza_new(ctx);
xmpp_stanza_set_text(after_text, lastid);
xmpp_stanza_add_child(after, after_text);
xmpp_stanza_add_child(set, after);
}
// add and release
xmpp_stanza_add_child(iq, query);
xmpp_stanza_add_child(query, x);
@ -2681,6 +2698,14 @@ stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const s
xmpp_stanza_add_child(x, field_with);
xmpp_stanza_add_child(x, field_start);
if (lastid) {
xmpp_stanza_add_child(query, after);
xmpp_stanza_release(after_text);
xmpp_stanza_release(after);
xmpp_stanza_release(set);
}
xmpp_stanza_release(mam_text);
xmpp_stanza_release(with_text);
xmpp_stanza_release(date_text);

View File

@ -115,6 +115,7 @@
#define STANZA_NAME_MINIMIZE "minimize"
#define STANZA_NAME_FIN "fin"
#define STANZA_NAME_LAST "last"
#define STANZA_NAME_AFTER "after"
// error conditions
#define STANZA_NAME_BAD_REQUEST "bad-request"
@ -380,6 +381,6 @@ void stanza_free_caps(XMPPCaps* caps);
xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_id, const char* const item_id, const char* const jid);
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate);
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char *const lastid);
#endif