From e9bee83b039505ced97fbff7315c9e60b811c1a9 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 10 Nov 2021 11:55:58 +0000 Subject: [PATCH] Tweak join rule unmarshalling --- federationapi/routing/join.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 2273f7383..999bf4c1f 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -144,17 +144,22 @@ func MakeJoin( provider := gomatrixserverlib.NewAuthEvents(stateEvents) // Check the join rules. If it's a restricted join then there are special rules. - var joinRuleEvent *gomatrixserverlib.Event - var joinRules gomatrixserverlib.JoinRuleContent - if joinRuleEvent, err = provider.JoinRules(); err != nil { + joinRules := gomatrixserverlib.JoinRuleContent{ + JoinRule: gomatrixserverlib.Public, // Default join rule if not specified. + } + joinRuleEvent, err := provider.JoinRules() + if err != nil { return util.JSONResponse{ Code: http.StatusNotFound, - JSON: jsonerror.NotFound("Room join rules do not exist"), + JSON: jsonerror.NotFound("Failed to retrieve join rules"), } - } else if err = json.Unmarshal(joinRuleEvent.Content(), &joinRules); err != nil { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: jsonerror.Unknown("Failed to unmarshal room join rules"), + } + if joinRuleEvent != nil { + if err = json.Unmarshal(joinRuleEvent.Content(), &joinRules); err != nil { + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.Unknown("Failed to unmarshal room join rules"), + } } }