[ADD/WIP] Start implementing invites.
Some checks are pending
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Waiting to run

I'll need to add the direct flag somewhere in the room leaves.
Also, it seems like there's a giant bottleneck in my code...
This commit is contained in:
lda 2024-05-20 16:37:41 +02:00
parent 9dcaab0819
commit c22d628c86

View file

@ -35,6 +35,7 @@
#include <Cytoplasm/Base64.h> #include <Cytoplasm/Base64.h>
#include <Cytoplasm/Util.h> #include <Cytoplasm/Util.h>
#include <Cytoplasm/Str.h> #include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Db.h> #include <Cytoplasm/Db.h>
#include <Schema/RoomCreateRequest.h> #include <Schema/RoomCreateRequest.h>
@ -76,7 +77,6 @@ GenerateRoomId(ServerPart s)
string = ParserRecomposeCommonID(cid); string = ParserRecomposeCommonID(cid);
Free(cid.local); Free(cid.local);
return string; return string;
} }
static void static void
@ -84,7 +84,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
{ {
CommonID sender; CommonID sender;
char *sender_str, *key, *version; char *sender_str, *key, *version;
HashMap *content, *event, *override; HashMap *content, *event, *override, *pl_content;
Array *initial_states; Array *initial_states;
JsonValue *val; JsonValue *val;
size_t i; size_t i;
@ -92,7 +92,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
char *join_rules_preset = NULL; char *join_rules_preset = NULL;
char *history_visibility_preset = NULL; char *history_visibility_preset = NULL;
char *guest_access_preset = NULL; char *guest_access_preset = NULL;
/* TODO: Manage trusted private chat */ bool trusted_room = false;
sender.sigil = '@'; sender.sigil = '@';
sender.local = UserGetName(user); sender.local = UserGetName(user);
@ -150,6 +150,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
} }
HashMapSet(content, key, JsonValueDuplicate(val)); HashMapSet(content, key, JsonValueDuplicate(val));
} }
pl_content = JsonDuplicate(content);
event = RoomEventCreate(sender_str, "m.room.power_levels", "", content); event = RoomEventCreate(sender_str, "m.room.power_levels", "", content);
JsonFree(RoomEventSend(room, event)); JsonFree(RoomEventSend(room, event));
JsonFree(event); JsonFree(event);
@ -163,7 +164,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
guest_access_preset = "forbidden"; guest_access_preset = "forbidden";
break; break;
case ROOM_CREATE_TRUSTED: case ROOM_CREATE_TRUSTED:
/* TODO */ trusted_room = true;
/* Fallthrough */ /* Fallthrough */
case ROOM_CREATE_PRIVATE: case ROOM_CREATE_PRIVATE:
join_rules_preset = "invite"; join_rules_preset = "invite";
@ -272,6 +273,40 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
Free(fullStr); Free(fullStr);
Free(serverStr); Free(serverStr);
} }
/* Invites */
for (i = 0; i < ArraySize(req->invite); i++)
{
char *user_id = ArrayGet(req->invite, i);
if (!user_id || !ValidCommonID(user_id, '@'))
{
/* TODO: Raise error. */
break;
}
content = HashMapCreate();
if (req->is_direct)
{
JsonSet(content, JsonValueBoolean(true), 1, "is_direct");
}
JsonSet(content, JsonValueString("invite"), 1, "membership");
event = RoomEventCreate(sender_str, "m.room.member", user_id, content);
JsonFree(RoomEventSend(room, event));
JsonFree(event);
if (trusted_room)
{
JsonValue *own = JsonGet(pl_content, 2, "users", sender_str);
JsonValueFree(JsonSet(
pl_content, JsonValueDuplicate(own),
2, "users", user_id));
}
}
event = RoomEventCreate(sender_str, "m.room.power_levels", "", pl_content);
JsonFree(RoomEventSend(room, event));
JsonFree(event);
/* TODO: The rest of the events mandated by the specification on /* TODO: The rest of the events mandated by the specification on
* POST /createRoom, and error management. */ * POST /createRoom, and error management. */