From 47823ba56b2422749971275f9221c204584aa74f Mon Sep 17 00:00:00 2001 From: LDA Date: Sun, 7 Jul 2024 23:59:13 +0200 Subject: [PATCH] [MOD] Actually redact --- src/AS.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++- src/XMPPThread.c | 7 +------ src/include/AS.h | 3 +++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/AS.c b/src/AS.c index c49b8dc..8415148 100644 --- a/src/AS.c +++ b/src/AS.c @@ -858,7 +858,6 @@ ASGetUserConfig(const ParseeConfig *c, char *user, char *key) void ASSetUserConfig(const ParseeConfig *c, char *user, char *key, HashMap *map) { - HttpClientContext *ctx = NULL; char *path; if (!c || !key || !map) @@ -898,3 +897,52 @@ ASSetUserConfig(const ParseeConfig *c, char *user, char *key, HashMap *map) return; } +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->homeserver_host + ); + 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; +} diff --git a/src/XMPPThread.c b/src/XMPPThread.c index 0ed5421..410ea38 100644 --- a/src/XMPPThread.c +++ b/src/XMPPThread.c @@ -621,13 +621,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr) } else if (retracted) { - /* TODO: Use an actual redact. Not doing it now because it's not - * fun to do at the moment... */ event_id = ParseeGetEventFromID(args, stanza, retracted); - Free(ASSend( - args->config, mroom_id, encoded, "m.room.message", - MatrixCreateReplace(event_id, "[Retracted]") - )); + ASRedact(args->config, mroom_id, encoded, event_id); ParseePushAllStanza(args, stanza, event_id); pthread_mutex_unlock(&thr->info->chk_lock); diff --git a/src/include/AS.h b/src/include/AS.h index f029f9c..4000c9a 100644 --- a/src/include/AS.h +++ b/src/include/AS.h @@ -43,6 +43,9 @@ extern char * ASSend(const ParseeConfig *, char *, char *, char *, HashMap *); extern void ASType(const ParseeConfig *, char *, char *, bool); extern void ASPresence(const ParseeConfig *, char *, char *, char *); +/* Redacts an event from a room with a specific user */ +extern void ASRedact(const ParseeConfig *, char *room, char *user, char *e_id); + /* Sets a state event with a specific type and body */ extern void ASSetState(const ParseeConfig *conf, char *id, char *type, char *key, char *mask, HashMap *event);