[ADD/WIP] Start processing event relations

This commit is contained in:
LDA 2024-09-28 12:31:12 +02:00
parent 0e2d652b8a
commit f279ead4d7
2 changed files with 51 additions and 0 deletions

19
Schema/Relation.json Normal file
View file

@ -0,0 +1,19 @@
{
"guard": "TELODENDRIA_SCHEMA_RELATION_H",
"header": "Schema/Relation.h",
"types": {
"Relation": {
"type": "struct",
"fields": {
"event_id": {
"type": "string",
"required": true
},
"rel_type": {
"type": "string",
"required": true
}
}
}
}
}

View file

@ -1,5 +1,6 @@
#include "Room/internal.h"
#include <Schema/Relation.h>
#include <Schema/PduV1.h>
#include <Parser.h>
@ -312,6 +313,9 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status)
* notified about. */
if (status == PDUV1_STATUS_ACCEPTED)
{
HashMap *relates_to =
JsonValueAsObject(HashMapGet(pdu.content, "m.relates_to"));
Relation rel = { 0 };
State *state;
char *type, *state_key, *event_id;
@ -319,6 +323,34 @@ RoomAddEventV1(Room *room, PduV1 pdu, PduV1Status status)
/* If we have a membership change, then add it to the
* proper table. */
if (RelationFromJson(relates_to, &rel, NULL))
{
DbRef *relate = DbLock(
room->db,
4, "rooms", room->id, "events", rel.event_id
);
HashMap *relObj = DbJson(relate);
if (relObj)
{
Array *relList = JsonValueAsArray(HashMapGet(
relObj, "relations"
));
if (!relList)
{
relList = ArrayCreate();
JsonValueFree(HashMapSet(
relObj, "relations", JsonValueArray(relList)
));
}
/* TODO: We may want to treat the relation as 'special'
* if the specification asks us to bundle it. */
ArrayAdd(relList, JsonValueString(pdu.event_id));
}
RelationFree(&rel);
DbUnlock(room->db, relate);
}
if (StrEquals(pdu.type, "m.room.member"))
{
CommonID *id = UserIdParse(pdu.state_key, NULL);