mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 00:35:11 +00:00
[MOD/ADD] Separate AS code, XMPP reactions removal
This commit is contained in:
parent
1b62072a3a
commit
fb511b4df0
16 changed files with 1183 additions and 1029 deletions
81
src/AS/Relations.c
Normal file
81
src/AS/Relations.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#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 (event)
|
||||
{
|
||||
path = StrConcat(6,
|
||||
"/_matrix/client/v1/rooms/", room,
|
||||
"/relations/", event,
|
||||
"?user_id=", user
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = StrConcat(4,
|
||||
"/_matrix/client/v1/rooms/", room,
|
||||
"/relations?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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue