mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Bugfixes and line up where we'll dump history visibility code
This commit is contained in:
parent
493e2ca389
commit
c8dd962505
5 changed files with 60 additions and 21 deletions
29
syncapi/internal/history_visibility.go
Normal file
29
syncapi/internal/history_visibility.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// ApplyHistoryVisibilityChecks removes items from the input slice if the user is not allowed
|
||||
// to see these events.
|
||||
func ApplyHistoryVisibilityChecks(
|
||||
ctx context.Context, userID string, events []gomatrixserverlib.HeaderedEvent,
|
||||
) []gomatrixserverlib.HeaderedEvent {
|
||||
return events
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue