forked from Telodendria/Telodendria
[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
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:
parent
9dcaab0819
commit
c22d628c86
1 changed files with 39 additions and 4 deletions
43
src/Room.c
43
src/Room.c
|
@ -35,6 +35,7 @@
|
|||
#include <Cytoplasm/Base64.h>
|
||||
#include <Cytoplasm/Util.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Db.h>
|
||||
|
||||
#include <Schema/RoomCreateRequest.h>
|
||||
|
@ -76,7 +77,6 @@ GenerateRoomId(ServerPart s)
|
|||
string = ParserRecomposeCommonID(cid);
|
||||
Free(cid.local);
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
static void
|
||||
|
@ -84,7 +84,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
|
|||
{
|
||||
CommonID sender;
|
||||
char *sender_str, *key, *version;
|
||||
HashMap *content, *event, *override;
|
||||
HashMap *content, *event, *override, *pl_content;
|
||||
Array *initial_states;
|
||||
JsonValue *val;
|
||||
size_t i;
|
||||
|
@ -92,7 +92,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
|
|||
char *join_rules_preset = NULL;
|
||||
char *history_visibility_preset = NULL;
|
||||
char *guest_access_preset = NULL;
|
||||
/* TODO: Manage trusted private chat */
|
||||
bool trusted_room = false;
|
||||
|
||||
sender.sigil = '@';
|
||||
sender.local = UserGetName(user);
|
||||
|
@ -150,6 +150,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
|
|||
}
|
||||
HashMapSet(content, key, JsonValueDuplicate(val));
|
||||
}
|
||||
pl_content = JsonDuplicate(content);
|
||||
event = RoomEventCreate(sender_str, "m.room.power_levels", "", content);
|
||||
JsonFree(RoomEventSend(room, event));
|
||||
JsonFree(event);
|
||||
|
@ -163,7 +164,7 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
|
|||
guest_access_preset = "forbidden";
|
||||
break;
|
||||
case ROOM_CREATE_TRUSTED:
|
||||
/* TODO */
|
||||
trusted_room = true;
|
||||
/* Fallthrough */
|
||||
case ROOM_CREATE_PRIVATE:
|
||||
join_rules_preset = "invite";
|
||||
|
@ -272,6 +273,40 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
|
|||
Free(fullStr);
|
||||
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
|
||||
* POST /createRoom, and error management. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue