[MOD] Timestamp Matrix messages

This commit is contained in:
LDA 2024-10-28 13:26:25 +01:00
commit 55ac682d26
9 changed files with 48 additions and 19 deletions

View file

@ -1,21 +1,38 @@
#include <AS.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Util.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Uri.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <Matrix.h>
static char *
TSToStr(uint64_t ts)
{
size_t len;
char *str;
len = snprintf(NULL, 0, "%"PRIu64, ts);
str = Malloc(len+1);
snprintf(str, len+1, "%"PRIu64, ts);
return str;
}
char *
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c, uint64_t ts)
{
HttpClientContext *ctx = NULL;
char *path;
char *txn, *ret;
char *ts_str;
HashMap *reply;
if (!conf || !id || !type || !user || !c)
{
@ -23,13 +40,20 @@ ASSend(const ParseeConfig *conf, char *id, char *user, char *type, HashMap *c)
return NULL;
}
if (!ts)
{
ts = UtilTsMillis();
}
ts_str = TSToStr(ts);
txn = StrRandom(16);
path = StrConcat(9,
path = StrConcat(11,
"/_matrix/client/v3/rooms/",
id, "/send/", type, "/", txn, "?",
"user_id=", user
"user_id=", user, "&ts=", ts_str
);
Free(txn);
Free(ts_str);
ctx = ParseeCreateRequest(conf, HTTP_PUT, path);
Free(path);