[FIX] Store redactor outside the PDU itself

This commit is contained in:
LDA 2024-09-28 10:47:35 +02:00
parent 78dbe5ca81
commit 0e2d652b8a
2 changed files with 22 additions and 19 deletions

View file

@ -271,9 +271,9 @@ CreateSafeID(char *unsafe_id)
HashMap * HashMap *
RoomEventFetch(Room *room, char *id) RoomEventFetch(Room *room, char *id)
{ {
char *safe_id, *redactor;
HashMap *ret, *unsign; HashMap *ret, *unsign;
DbRef *event_ref; DbRef *event_ref;
char *safe_id;
uint64_t ts; uint64_t ts;
if (!room || !id) if (!room || !id)
@ -312,6 +312,13 @@ RoomEventFetch(Room *room, char *id)
JsonValueInteger(UtilTsMillis() - ts) JsonValueInteger(UtilTsMillis() - ts)
)); ));
redactor = JsonValueAsString(HashMapGet(DbJson(event_ref), "redacted_by"));
JsonValueFree(HashMapSet(
unsign,
"redacted_because",
JsonValueObject(RoomEventFetch(room, redactor))
));
DbUnlock(room->db, event_ref); DbUnlock(room->db, event_ref);
finish: finish:
Free(safe_id); Free(safe_id);
@ -690,6 +697,10 @@ RoomRedact(Room *room, User *user, char *eventID, char *reason, char **errp)
pdu = RoomEventSend(room, event, errp); pdu = RoomEventSend(room, event, errp);
ret = StrDuplicate(JsonValueAsString(HashMapGet(pdu, "event_id"))); ret = StrDuplicate(JsonValueAsString(HashMapGet(pdu, "event_id")));
if (errp && !*errp && !ret)
{
*errp = "Unknown error when redacting.";
}
end: end:
UserIdFree(userId); UserIdFree(userId);
JsonFree(event); JsonFree(event);

View file

@ -103,10 +103,10 @@ RoomGetEventStatusV1(Room *room, PduV1 *pdu, State *prev, bool client, char **er
} }
static void static void
RedactPDU1(HashMap *obj, HashMap *redactor) RedactPDU1(HashMap *obj)
{ {
Array *keys; Array *keys;
HashMap *content, *_unsigned; HashMap *content;
char *type = JsonValueAsString(HashMapGet(obj, "type")); char *type = JsonValueAsString(HashMapGet(obj, "type"));
size_t i; size_t i;
if (!obj) if (!obj)
@ -133,20 +133,9 @@ RedactPDU1(HashMap *obj, HashMap *redactor)
} }
ArrayFree(keys); ArrayFree(keys);
_unsigned = JsonValueAsObject(HashMapGet(obj, "unsigned")); JsonValueFree(HashMapSet(
keys = HashMapKeys(_unsigned); obj,
for (i = 0; i < ArraySize(keys); i++) "unsigned", JsonValueObject(HashMapCreate())
{
char *key = ArrayGet(keys, i);
if (!StrEquals(key, "next_events") && !StrEquals(key, "pdu_status"))
{
JsonValueFree(HashMapDelete(_unsigned, key));
continue;
}
}
ArrayFree(keys);
JsonValueFree(HashMapSet(_unsigned,
"redacted_because", JsonValueObject(JsonDuplicate(redactor))
)); ));
content = JsonValueAsObject(HashMapGet(obj, "content")); content = JsonValueAsObject(HashMapGet(obj, "content"));
@ -367,9 +356,12 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status)
); );
RedactPDU1( RedactPDU1(
JsonValueAsObject(HashMapGet(DbJson(eventRef), "pdu")), JsonValueAsObject(HashMapGet(DbJson(eventRef), "pdu"))
pdu_json
); );
JsonValueFree(HashMapSet(
DbJson(eventRef),
"redacted_by", JsonValueString(pdu.redacts)
));
DbUnlock(room->db, eventRef); DbUnlock(room->db, eventRef);
} }