Bugfixes and line up where we'll dump history visibility code

This commit is contained in:
Kegan Dougal 2020-09-11 16:55:22 +01:00
parent 493e2ca389
commit c8dd962505
5 changed files with 60 additions and 21 deletions

View file

@ -24,8 +24,10 @@ import (
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/syncapi/internal"
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@ -44,6 +46,7 @@ type messagesReq struct {
wasToProvided bool
limit int
backwardOrdering bool
requester string // user ID
}
type messagesResp struct {
@ -58,7 +61,7 @@ const defaultMessagesLimit = 10
// client-server API.
// See: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages
func OnIncomingMessagesRequest(
req *http.Request, db storage.Database, roomID string,
req *http.Request, device *userapi.Device, db storage.Database, roomID string,
federation *gomatrixserverlib.FederationClient,
rsAPI api.RoomserverInternalAPI,
cfg *config.SyncAPI,
@ -151,6 +154,7 @@ func OnIncomingMessagesRequest(
wasToProvided: wasToProvided,
limit: limit,
backwardOrdering: backwardOrdering,
requester: device.UserID,
}
clientEvents, start, end, err := mReq.retrieveEvents()
@ -239,6 +243,8 @@ func (r *messagesReq) retrieveEvents() (
events = reversed(events)
}
events = internal.ApplyHistoryVisibilityChecks(r.ctx, r.requester, events)
// Convert all of the events into client events.
clientEvents = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatAll)
// Get the position of the first and the last event in the room's topology.

View file

@ -51,7 +51,7 @@ func Setup(
if err != nil {
return util.ErrorResponse(err)
}
return OnIncomingMessagesRequest(req, syncDB, vars["roomID"], federation, rsAPI, cfg)
return OnIncomingMessagesRequest(req, device, syncDB, vars["roomID"], federation, rsAPI, cfg)
})).Methods(http.MethodGet, http.MethodOptions)
r0mux.Handle("/user/{userId}/filter",