From bb3d15f2c95ef4cb328c296871e5823e50299a25 Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 8 Jun 2024 18:37:54 +0200 Subject: [PATCH] [MOD/FIX] Update user list at the lowest level I'll need to start defining a `diffs' system for sync. I have a decent idea on how that could go(with 1 level of batching), but I'll need to consider it some. --- src/Room.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Room.c b/src/Room.c index 7a5358d..34a4029 100644 --- a/src/Room.c +++ b/src/Room.c @@ -279,7 +279,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s) for (i = 0; i < ArraySize(req->invite); i++) { char *user_id = ArrayGet(req->invite, i); - + if (!user_id || !ValidCommonID(user_id, '@')) { /* TODO: Raise error. */ @@ -1815,6 +1815,33 @@ RoomAddEventV1(Room *room, PduV1 pdu) /* TODO: Store DAG relationships, somehow. * Also keep track of PDU depth. */ + if (StrEquals(pdu.type, "m.room.member")) + { + CommonID *id = UserIdParse(pdu.state_key, NULL); + User *user = UserLock(room->db, id->local); + char *membership = JsonValueAsString( + HashMapGet(pdu.content, "membership") + ); + + if (StrEquals(membership, "join") && user) + { + UserAddJoin(user, room->id); + } + else if (StrEquals(membership, "invite") && user) + { + UserAddInvite(user, room->id); + } + else if ((StrEquals(membership, "leave") && user) || + StrEquals(membership, "ban")) + { + UserRemoveInvite(user, room->id); + UserRemoveJoin(user, room->id); + } + + UserIdFree(id); + UserUnlock(user); + } + return true; } HashMap * @@ -2015,6 +2042,7 @@ RoomSendInvite(User *sender, bool direct, char *user, Room *room) } ConfigLock(room->db, &conf); senderID = UserIdParse(UserGetName(sender), conf.serverName); + senderID->sigil = '@'; senderStr = ParserRecomposeCommonID(*senderID); UserIdFree(senderID);