mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:25:11 +00:00
82 lines
1.6 KiB
C
82 lines
1.6 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>
|
|
|
|
Array *
|
|
ASGetRelations(const ParseeConfig *c, size_t n, char *room, char *event, char *type)
|
|
{
|
|
HttpClientContext *ctx = NULL;
|
|
Array *ret, *chunk;
|
|
HashMap *json = NULL;
|
|
char *path;
|
|
char *user;
|
|
size_t i;
|
|
if (!c || !n || !room || !event)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
user = StrConcat(4, "@", c->sender_localpart, ":", c->server_base);
|
|
if (type)
|
|
{
|
|
path = StrConcat(8,
|
|
"/_matrix/client/v1/rooms/", room,
|
|
"/relations/", event, "/", type,
|
|
"?user_id=", user
|
|
);
|
|
}
|
|
else
|
|
{
|
|
path = StrConcat(6,
|
|
"/_matrix/client/v1/rooms/", room,
|
|
"/relations/", event,
|
|
"?user_id=", user
|
|
);
|
|
}
|
|
Free(user);
|
|
|
|
ctx = ParseeCreateRequest(c, HTTP_GET, path);
|
|
Free(path);
|
|
ASAuthenticateRequest(c, ctx);
|
|
HttpRequestSendHeaders(ctx);
|
|
HttpRequestSend(ctx);
|
|
|
|
|
|
json = JsonDecode(HttpClientStream(ctx));
|
|
ret = ArrayCreate();
|
|
chunk = GrabArray(json, 1, "chunk");
|
|
for (i = 0; i < ArraySize(chunk); i++)
|
|
{
|
|
HashMap *obj = JsonValueAsObject(ArrayGet(chunk, i));
|
|
ArrayAdd(ret, JsonDuplicate(obj));
|
|
}
|
|
|
|
HttpClientContextFree(ctx);
|
|
JsonFree(json);
|
|
return ret;
|
|
}
|
|
|
|
void
|
|
ASFreeRelations(Array *relations)
|
|
{
|
|
size_t i;
|
|
if (!relations)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < ArraySize(relations); i++)
|
|
{
|
|
JsonFree(ArrayGet(relations, i));
|
|
}
|
|
|
|
ArrayFree(relations);
|
|
}
|