[FIX/WIP] Fix join rules
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 still need to notify users that they're *in* the room, instead of
just poking at the state.

But this should allow users to send events to the same room.
This commit is contained in:
LDA 2024-06-08 11:03:54 +02:00
parent 250d28b958
commit 9600d2ffb5
3 changed files with 22 additions and 10 deletions

View file

@ -189,26 +189,26 @@ RoomPopulate(Room *room, User *user, RoomCreateRequest *req, ServerPart s)
}
/* Write out presets */
#define SetIfExistent(pset) do { \
if (pset##_preset) \
#define SetIfExistent(p,a) do { \
if (p##_preset) \
{ \
content = HashMapCreate(); \
JsonSet( \
content, \
JsonValueString(join_rules_preset) \
, 1, #pset); \
, 1, a); \
event = RoomEventCreate( \
sender_str, \
"m.room." #pset, "", content); \
"m.room." #p, "", content); \
JsonFree(RoomEventSend(room, event)); \
JsonFree(event); \
} \
} \
while (0)
SetIfExistent(join_rules);
SetIfExistent(history_visibility);
SetIfExistent(guest_access);
SetIfExistent(join_rules, "join_rule");
SetIfExistent(history_visibility, "history_visibility");
SetIfExistent(guest_access, "guest_access");
#undef SetIfExistent
/* User-provided initial states */
@ -501,7 +501,7 @@ RoomIsJoinRule(Room * room, HashMap *state, char *jr)
PrepareState(room, state, "m.room.join_rules", "", joinrule);
ret = StrEquals(
JsonValueAsString(JsonGet(joinrule, 1, "join_rule")),
JsonValueAsString(JsonGet(joinrule, 2, "content", "join_rule")),
jr);
finish:
FinishState(joinrule);
@ -1629,7 +1629,7 @@ RoomEventSendV1(Room * room, HashMap * event)
{
/* Reject this event as the current state does not allow it.
* TODO: Make the auth check function return a string showing the
* error status to the user. */
* errorr status to the user. */
goto finish;
}
RoomAddEventV1(room, pdu);
@ -2080,7 +2080,7 @@ RoomCanJoin(Room *room, char *user)
room,
StateGet(state, "m.room.join_rules", "")
);
joinRuleV = JsonValueAsString(HashMapGet(joinRule, "join_rule"));
joinRuleV = JsonValueAsString(JsonGet(joinRule, 2, "content", "join_rule"));
if (StrEquals(joinRuleV, "public"))
{

View file

@ -123,6 +123,14 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
sender = ParserRecomposeCommonID(*id);
room = RoomLock(db, roomId);
if (!room)
{
err = "Room ID does not exist.";
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNKNOWN, err);
goto finish;
}
if (RoomContainsUser(room, sender))
{
err = "User is already in the room.";
@ -151,6 +159,7 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
finish:
UserIdFree(id);
JsonFree(request);
if (sender)
{
Free(sender);

View file

@ -37,6 +37,9 @@ ROUTE_IMPL(RouteVersions, path, argp)
(void) argp;
#define DECLARE_SPEC_VERSION(x) ArrayAdd(versions, JsonValueString(x))
DECLARE_SPEC_VERSION("v1.0");
DECLARE_SPEC_VERSION("v1.1");
DECLARE_SPEC_VERSION("v1.2");
DECLARE_SPEC_VERSION("v1.3");
DECLARE_SPEC_VERSION("v1.4");