mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Add Resident flag to QueryRestrictedJoinAllowedResponse
This commit is contained in:
parent
919d9942b6
commit
41b6bf56e5
|
|
@ -354,7 +354,8 @@ type QueryRestrictedJoinAllowedRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryRestrictedJoinAllowedResponse struct {
|
type QueryRestrictedJoinAllowedResponse struct {
|
||||||
Allowed bool `json:"allowed"`
|
Resident bool `json:"resident"` // Is our homeserver in the relevant rooms?
|
||||||
|
Allowed bool `json:"allowed"` // Is the join allowed by the rules?
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON stringifies the room ID and StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
// MarshalJSON stringifies the room ID and StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
||||||
|
|
|
||||||
|
|
@ -790,6 +790,10 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
|
||||||
if joinRules.JoinRule != gomatrixserverlib.Restricted {
|
if joinRules.JoinRule != gomatrixserverlib.Restricted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Start off by populating the "resident" flag in the response. If we
|
||||||
|
// come across any rooms in the request that are missing, we will unset
|
||||||
|
// the flag.
|
||||||
|
res.Resident = true
|
||||||
// Step through the join rules and see if the user matches any of them.
|
// Step through the join rules and see if the user matches any of them.
|
||||||
for _, rule := range joinRules.Allow {
|
for _, rule := range joinRules.Allow {
|
||||||
// We only understand "m.room_membership" rules at this point in
|
// We only understand "m.room_membership" rules at this point in
|
||||||
|
|
@ -800,21 +804,17 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
|
||||||
// See if the room exists. If it doesn't exist or if it's a stub
|
// See if the room exists. If it doesn't exist or if it's a stub
|
||||||
// room entry then we can't check memberships.
|
// room entry then we can't check memberships.
|
||||||
targetRoomInfo, err := r.DB.RoomInfo(ctx, rule.RoomID)
|
targetRoomInfo, err := r.DB.RoomInfo(ctx, rule.RoomID)
|
||||||
if err != nil {
|
if err != nil || targetRoomInfo == nil || targetRoomInfo.IsStub {
|
||||||
continue
|
res.Resident = false
|
||||||
}
|
|
||||||
if targetRoomInfo == nil || targetRoomInfo.IsStub {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// First of all work out if *we* are still in the room, otherwise
|
// First of all work out if *we* are still in the room, otherwise
|
||||||
// it's possible that the memberships will be out of date.
|
// it's possible that the memberships will be out of date.
|
||||||
isIn, err := r.DB.GetLocalServerInRoom(ctx, targetRoomInfo.RoomNID)
|
isIn, err := r.DB.GetLocalServerInRoom(ctx, targetRoomInfo.RoomNID)
|
||||||
if err != nil {
|
if err != nil || !isIn {
|
||||||
continue
|
// If we aren't in the room, we can no longer tell if the room
|
||||||
}
|
|
||||||
if !isIn {
|
|
||||||
// We aren't in the room, so we can no longer tell if the room
|
|
||||||
// memberships are up-to-date.
|
// memberships are up-to-date.
|
||||||
|
res.Resident = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// At this point we're happy that we are in the room, so now let's
|
// At this point we're happy that we are in the room, so now let's
|
||||||
|
|
@ -825,6 +825,7 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
|
||||||
}
|
}
|
||||||
// If the user is in the room then we will allow the membership.
|
// If the user is in the room then we will allow the membership.
|
||||||
if isIn {
|
if isIn {
|
||||||
|
res.Resident = true
|
||||||
res.Allowed = true
|
res.Allowed = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue