Implement archived rooms (include_leave filter on /sync)

Fix https://github.com/matrix-org/dendrite/issues/1323
This commit is contained in:
Eric Eastwood 2020-12-22 22:31:01 -06:00
parent e3ce6a924f
commit 82afb32464
6 changed files with 24 additions and 7 deletions

View file

@ -65,6 +65,7 @@ type filterResponse struct {
FilterID string `json:"filter_id"` FilterID string `json:"filter_id"`
} }
// TODO: asdf
//PutFilter implements POST /_matrix/client/r0/user/{userId}/filter //PutFilter implements POST /_matrix/client/r0/user/{userId}/filter
func PutFilter( func PutFilter(
req *http.Request, device *api.Device, syncDB storage.Database, userID string, req *http.Request, device *api.Device, syncDB storage.Database, userID string,

View file

@ -42,6 +42,7 @@ func Setup(
r0mux := csMux.PathPrefix("/r0").Subrouter() r0mux := csMux.PathPrefix("/r0").Subrouter()
// TODO: Add AS support for all handlers below. // TODO: Add AS support for all handlers below.
// asdf
r0mux.Handle("/sync", httputil.MakeAuthAPI("sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { r0mux.Handle("/sync", httputil.MakeAuthAPI("sync", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
return srp.OnIncomingSyncRequest(req, device) return srp.OnIncomingSyncRequest(req, device)
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)

View file

@ -762,6 +762,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
ctx context.Context, res *types.Response, ctx context.Context, res *types.Response,
userID string, device userapi.Device, userID string, device userapi.Device,
numRecentEventsPerRoom int, numRecentEventsPerRoom int,
includeLeave bool,
) ( ) (
toPos types.StreamingToken, toPos types.StreamingToken,
joinedRoomIDs []string, joinedRoomIDs []string,
@ -811,6 +812,9 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
if err != nil { if err != nil {
return return
} }
// TODO: Add "leave" rooms.
res.Rooms.Join[roomID] = *jr res.Rooms.Join[roomID] = *jr
} }

View file

@ -30,10 +30,12 @@ import (
) )
const defaultSyncTimeout = time.Duration(0) const defaultSyncTimeout = time.Duration(0)
const defaultIncludeLeave = false
const DefaultTimelineLimit = 20 const DefaultTimelineLimit = 20
type filter struct { type filter struct {
Room struct { Room struct {
IncludeLeave *bool `json:"include_leave"`
Timeline struct { Timeline struct {
Limit *int `json:"limit"` Limit *int `json:"limit"`
} `json:"timeline"` } `json:"timeline"`
@ -45,6 +47,7 @@ type syncRequest struct {
ctx context.Context ctx context.Context
device userapi.Device device userapi.Device
limit int limit int
includeLeave bool
timeout time.Duration timeout time.Duration
since types.StreamingToken // nil means that no since token was supplied since types.StreamingToken // nil means that no since token was supplied
wantFullState bool wantFullState bool
@ -64,6 +67,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
} }
} }
timelineLimit := DefaultTimelineLimit timelineLimit := DefaultTimelineLimit
includeLeave := defaultIncludeLeave
// TODO: read from stored filters too // TODO: read from stored filters too
filterQuery := req.URL.Query().Get("filter") filterQuery := req.URL.Query().Get("filter")
if filterQuery != "" { if filterQuery != "" {
@ -74,6 +78,9 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
if err == nil && f.Room.Timeline.Limit != nil { if err == nil && f.Room.Timeline.Limit != nil {
timelineLimit = *f.Room.Timeline.Limit timelineLimit = *f.Room.Timeline.Limit
} }
if err == nil && f.Room.IncludeLeave != nil {
includeLeave = *f.Room.IncludeLeave
}
} else { } else {
// attempt to load the filter ID // attempt to load the filter ID
localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID) localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID)
@ -84,6 +91,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
f, err := syncDB.GetFilter(req.Context(), localpart, filterQuery) f, err := syncDB.GetFilter(req.Context(), localpart, filterQuery)
if err == nil { if err == nil {
timelineLimit = f.Room.Timeline.Limit timelineLimit = f.Room.Timeline.Limit
includeLeave = f.Room.IncludeLeave
} }
} }
} }
@ -95,6 +103,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
since: since, since: since,
wantFullState: wantFullState, wantFullState: wantFullState,
limit: timelineLimit, limit: timelineLimit,
includeLeave: includeLeave,
log: util.GetLogger(req.Context()), log: util.GetLogger(req.Context()),
}, nil }, nil
} }

View file

@ -145,6 +145,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
"since": syncReq.since, "since": syncReq.since,
"timeout": syncReq.timeout, "timeout": syncReq.timeout,
"limit": syncReq.limit, "limit": syncReq.limit,
"include_leave": syncReq.includeLeave,
}) })
activeSyncRequests.Inc() activeSyncRequests.Inc()
@ -285,7 +286,7 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea
// TODO: handle ignored users // TODO: handle ignored users
if req.since.IsEmpty() { if req.since.IsEmpty() {
res, err = rp.db.CompleteSync(req.ctx, res, req.device, req.limit) res, err = rp.db.CompleteSync(req.ctx, res, req.device, req.limit, req.includeLeave)
if err != nil { if err != nil {
return res, fmt.Errorf("rp.db.CompleteSync: %w", err) return res, fmt.Errorf("rp.db.CompleteSync: %w", err)
} }

View file

@ -123,6 +123,7 @@ We should see our own leave event when rejecting an invite, even if history_visi
Newly left rooms appear in the leave section of gapped sync Newly left rooms appear in the leave section of gapped sync
Previously left rooms don't appear in the leave section of sync Previously left rooms don't appear in the leave section of sync
Left rooms appear in the leave section of full state sync Left rooms appear in the leave section of full state sync
Archived rooms only contain history from before the user left
Newly banned rooms appear in the leave section of incremental sync Newly banned rooms appear in the leave section of incremental sync
Newly banned rooms appear in the leave section of incremental sync Newly banned rooms appear in the leave section of incremental sync
local user can join room with version 1 local user can join room with version 1