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
93
src/AS/Events.c
Normal file
93
src/AS/Events.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue