aboutsummaryrefslogtreecommitdiff
path: root/roomserver/internal/query
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-09-13 12:52:09 +0100
committerGitHub <noreply@github.com>2022-09-13 12:52:09 +0100
commitb05e028f7d8befc045dcb62e87d09ad462bb277c (patch)
treeac402b3a283cfacc59c1af67da87581d812fab56 /roomserver/internal/query
parent3e55856254f6bc918f5075d7adb85d53da92c7c8 (diff)
Tweak `LoadMembershipAtEvent` behaviour when state not known (#2716)
Previously `LoadMembershipAtEvent` would fail if the state before one of the events was not known, i.e. because it was an outlier. This modifies it so that it gracefully handles not knowing the state and returns no memberships instead, so that history visibility doesn't freak out and kill `/sync` requests dead.
Diffstat (limited to 'roomserver/internal/query')
-rw-r--r--roomserver/internal/query/query.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go
index d08c5c49..b41a92e9 100644
--- a/roomserver/internal/query/query.go
+++ b/roomserver/internal/query/query.go
@@ -208,6 +208,9 @@ func (r *Queryer) QueryMembershipForUser(
return err
}
+// QueryMembershipAtEvent returns the known memberships at a given event.
+// If the state before an event is not known, an empty list will be returned
+// for that event instead.
func (r *Queryer) QueryMembershipAtEvent(
ctx context.Context,
request *api.QueryMembershipAtEventRequest,
@@ -237,7 +240,11 @@ func (r *Queryer) QueryMembershipAtEvent(
}
for _, eventID := range request.EventIDs {
- stateEntry := stateEntries[eventID]
+ stateEntry, ok := stateEntries[eventID]
+ if !ok {
+ response.Memberships[eventID] = []*gomatrixserverlib.HeaderedEvent{}
+ continue
+ }
memberships, err := helpers.GetMembershipsAtState(ctx, r.DB, stateEntry, false)
if err != nil {
return fmt.Errorf("unable to get memberships at state: %w", err)