diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-10-28 15:57:53 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2021-01-28 14:44:53 +0100 |
commit | db65255a5a3c39dd7ad70b45c3610ec4fb02aac8 (patch) | |
tree | fb322a37c22054f0ea5acc665c214751c436e7fd | |
parent | 69e35e86b206e8c887907c84da4e32a01cedab04 (diff) | |
download | profani-tty-db65255a5a3c39dd7ad70b45c3610ec4fb02aac8.tar.gz |
wip: add rsm after we get the first couple of mam messages
-rw-r--r-- | src/xmpp/iq.c | 21 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 27 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 3 |
3 files changed, 46 insertions, 5 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 4e7aec4a..f1665616 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -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); } } } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index fbbbfc9c..06615aa9 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -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); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index f57a6d22..e35b4bcc 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -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 |