mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-02-28 13:53:00 +00:00
Implement archived rooms (include_leave filter on /sync)
Fix https://github.com/matrix-org/dendrite/issues/1323
This commit is contained in:
parent
e3ce6a924f
commit
82afb32464
6 changed files with 24 additions and 7 deletions
|
@ -65,6 +65,7 @@ type filterResponse struct {
|
|||
FilterID string `json:"filter_id"`
|
||||
}
|
||||
|
||||
// TODO: asdf
|
||||
//PutFilter implements POST /_matrix/client/r0/user/{userId}/filter
|
||||
func PutFilter(
|
||||
req *http.Request, device *api.Device, syncDB storage.Database, userID string,
|
||||
|
|
|
@ -42,6 +42,7 @@ func Setup(
|
|||
r0mux := csMux.PathPrefix("/r0").Subrouter()
|
||||
|
||||
// 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 {
|
||||
return srp.OnIncomingSyncRequest(req, device)
|
||||
})).Methods(http.MethodGet, http.MethodOptions)
|
||||
|
|
|
@ -762,6 +762,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
|||
ctx context.Context, res *types.Response,
|
||||
userID string, device userapi.Device,
|
||||
numRecentEventsPerRoom int,
|
||||
includeLeave bool,
|
||||
) (
|
||||
toPos types.StreamingToken,
|
||||
joinedRoomIDs []string,
|
||||
|
@ -811,6 +812,9 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Add "leave" rooms.
|
||||
|
||||
res.Rooms.Join[roomID] = *jr
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,12 @@ import (
|
|||
)
|
||||
|
||||
const defaultSyncTimeout = time.Duration(0)
|
||||
const defaultIncludeLeave = false
|
||||
const DefaultTimelineLimit = 20
|
||||
|
||||
type filter struct {
|
||||
Room struct {
|
||||
IncludeLeave *bool `json:"include_leave"`
|
||||
Timeline struct {
|
||||
Limit *int `json:"limit"`
|
||||
} `json:"timeline"`
|
||||
|
@ -45,6 +47,7 @@ type syncRequest struct {
|
|||
ctx context.Context
|
||||
device userapi.Device
|
||||
limit int
|
||||
includeLeave bool
|
||||
timeout time.Duration
|
||||
since types.StreamingToken // nil means that no since token was supplied
|
||||
wantFullState bool
|
||||
|
@ -64,6 +67,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
|
|||
}
|
||||
}
|
||||
timelineLimit := DefaultTimelineLimit
|
||||
includeLeave := defaultIncludeLeave
|
||||
// TODO: read from stored filters too
|
||||
filterQuery := req.URL.Query().Get("filter")
|
||||
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 {
|
||||
timelineLimit = *f.Room.Timeline.Limit
|
||||
}
|
||||
if err == nil && f.Room.IncludeLeave != nil {
|
||||
includeLeave = *f.Room.IncludeLeave
|
||||
}
|
||||
} else {
|
||||
// attempt to load the filter ID
|
||||
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)
|
||||
if err == nil {
|
||||
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,
|
||||
wantFullState: wantFullState,
|
||||
limit: timelineLimit,
|
||||
includeLeave: includeLeave,
|
||||
log: util.GetLogger(req.Context()),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -145,6 +145,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
|
|||
"since": syncReq.since,
|
||||
"timeout": syncReq.timeout,
|
||||
"limit": syncReq.limit,
|
||||
"include_leave": syncReq.includeLeave,
|
||||
})
|
||||
|
||||
activeSyncRequests.Inc()
|
||||
|
@ -285,7 +286,7 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea
|
|||
|
||||
// TODO: handle ignored users
|
||||
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 {
|
||||
return res, fmt.Errorf("rp.db.CompleteSync: %w", err)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Previously left rooms don't appear in the leave section of 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
|
||||
local user can join room with version 1
|
||||
|
|
Loading…
Reference in a new issue