[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 *
RoomEventFetch(Room *room, char *id)
{
char *safe_id, *redactor;
HashMap *ret, *unsign;
DbRef *event_ref;
char *safe_id;
uint64_t ts;
if (!room || !id)
@ -312,6 +312,13 @@ RoomEventFetch(Room *room, char *id)
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);
finish:
Free(safe_id);
@ -690,6 +697,10 @@ RoomRedact(Room *room, User *user, char *eventID, char *reason, char **errp)
pdu = RoomEventSend(room, event, errp);
ret = StrDuplicate(JsonValueAsString(HashMapGet(pdu, "event_id")));
if (errp && !*errp && !ret)
{
*errp = "Unknown error when redacting.";
}
end:
UserIdFree(userId);
JsonFree(event);

View file

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