Parsee/src/AS/Events.c

93 lines
1.8 KiB
C

#include <AS.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Uri.h>
#include <string.h>
#include <stdlib.h>
#include <Matrix.h>
HashMap *
ASFind(const ParseeConfig *c, char *room, char *event)
{
HttpClientContext *ctx = NULL;
HashMap *json;
char *path, *user;
if (!c || !room || !event)
{
return NULL;
}
user = StrConcat(4, "@", c->sender_localpart, ":", c->server_base);
path = StrConcat(7,
"/_matrix/client/v3/rooms/",
room, "/event/", event, "?",
"user_id=", user
);
ctx = ParseeCreateRequest(c, HTTP_GET, path);
Free(path);
ASAuthenticateRequest(c, ctx);
HttpRequestSendHeaders(ctx);
HttpRequestSend(ctx);
json = JsonDecode(HttpClientStream(ctx));
HttpClientContextFree(ctx);
Free(user);
return json;
}
void
ASRedact(const ParseeConfig *c, char *room, char *user, char *e_id)
{
HttpClientContext *ctx = NULL;
HashMap *request;
char *path, *txn;
if (!c || !room || !e_id)
{
return;
}
if (!user)
{
char *raw = StrConcat(4,
"@", c->sender_localpart,
":", c->server_base
);
user = HttpUrlEncode(raw);
Free(raw);
}
else
{
user = HttpUrlEncode(user);
}
room = HttpUrlEncode(room);
e_id = HttpUrlEncode(e_id);
txn = StrRandom(16);
path = StrConcat(9,
"/_matrix/client/v3/rooms/",
room, "/redact/", e_id, "/", txn,
"?", "user_id=", user
);
request = HashMapCreate();
ctx = ParseeCreateRequest(c, HTTP_PUT, path);
Free(path);
ASAuthenticateRequest(c, ctx);
ParseeSetRequestJSON(ctx, request);
JsonFree(request);
HttpClientContextFree(ctx);
Free(user);
Free(room);
Free(e_id);
Free(txn);
return;
}