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

View file

@ -123,6 +123,14 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
sender = ParserRecomposeCommonID(*id); sender = ParserRecomposeCommonID(*id);
room = RoomLock(db, roomId); 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)) if (RoomContainsUser(room, sender))
{ {
err = "User is already in the room."; err = "User is already in the room.";
@ -151,6 +159,7 @@ ROUTE_IMPL(RouteJoinRoom, path, argp)
finish: finish:
UserIdFree(id); UserIdFree(id);
JsonFree(request);
if (sender) if (sender)
{ {
Free(sender); Free(sender);

View file

@ -37,6 +37,9 @@ ROUTE_IMPL(RouteVersions, path, argp)
(void) argp; (void) argp;
#define DECLARE_SPEC_VERSION(x) ArrayAdd(versions, JsonValueString(x)) #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.2");
DECLARE_SPEC_VERSION("v1.3"); DECLARE_SPEC_VERSION("v1.3");
DECLARE_SPEC_VERSION("v1.4"); DECLARE_SPEC_VERSION("v1.4");