mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-11 22:33:40 +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
|
@ -94,8 +94,8 @@ func HistoryVisibilityForRoom(hisVisEvent *gomatrixserverlib.Event) (string, err
|
||||||
return visibility, nil
|
return visibility, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, authEvents []gomatrixserverlib.Event, wantMembership string) bool {
|
func IsAnyUserOnServerWithMembership(serverName gomatrixserverlib.ServerName, membershipEvents []gomatrixserverlib.Event, wantMembership string) bool {
|
||||||
for _, ev := range authEvents {
|
for _, ev := range membershipEvents {
|
||||||
membership, err := ev.Membership()
|
membership, err := ev.Membership()
|
||||||
if err != nil || membership != wantMembership {
|
if err != nil || membership != wantMembership {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -491,24 +491,28 @@ func joinEventsFromHistoryVisibility(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if historyVisibilityNID == 0 {
|
|
||||||
return nil, fmt.Errorf("no history visibility event for room %s", roomID)
|
// by default visibility is shared if there is no history visibility event
|
||||||
}
|
visibility := "shared"
|
||||||
stateEvents, err := db.Events(ctx, []types.EventNID{historyVisibilityNID})
|
if historyVisibilityNID != 0 {
|
||||||
if err != nil {
|
// load the event and check it
|
||||||
return nil, err
|
stateEvents, err := db.Events(ctx, []types.EventNID{historyVisibilityNID})
|
||||||
}
|
if err != nil {
|
||||||
if len(stateEvents) != 1 {
|
return nil, err
|
||||||
return nil, fmt.Errorf("failed to load history visibility event nid %d", historyVisibilityNID)
|
}
|
||||||
}
|
if len(stateEvents) != 1 {
|
||||||
var hisVisEvent *gomatrixserverlib.Event
|
return nil, fmt.Errorf("failed to load history visibility event nid %d", historyVisibilityNID)
|
||||||
if stateEvents[0].Type() == gomatrixserverlib.MRoomHistoryVisibility && stateEvents[0].StateKeyEquals("") {
|
}
|
||||||
hisVisEvent = &stateEvents[0].Event
|
var hisVisEvent *gomatrixserverlib.Event
|
||||||
}
|
if stateEvents[0].Type() == gomatrixserverlib.MRoomHistoryVisibility && stateEvents[0].StateKeyEquals("") {
|
||||||
visibility, err := auth.HistoryVisibilityForRoom(hisVisEvent)
|
hisVisEvent = &stateEvents[0].Event
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
visibility, err = auth.HistoryVisibilityForRoom(hisVisEvent)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if visibility != "shared" {
|
if visibility != "shared" {
|
||||||
logrus.Infof("ServersAtEvent history visibility not shared: %s", visibility)
|
logrus.Infof("ServersAtEvent history visibility not shared: %s", visibility)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
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/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/config"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"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/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -44,6 +46,7 @@ type messagesReq struct {
|
||||||
wasToProvided bool
|
wasToProvided bool
|
||||||
limit int
|
limit int
|
||||||
backwardOrdering bool
|
backwardOrdering bool
|
||||||
|
requester string // user ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type messagesResp struct {
|
type messagesResp struct {
|
||||||
|
@ -58,7 +61,7 @@ const defaultMessagesLimit = 10
|
||||||
// client-server API.
|
// client-server API.
|
||||||
// See: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages
|
// See: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages
|
||||||
func OnIncomingMessagesRequest(
|
func OnIncomingMessagesRequest(
|
||||||
req *http.Request, db storage.Database, roomID string,
|
req *http.Request, device *userapi.Device, db storage.Database, roomID string,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
rsAPI api.RoomserverInternalAPI,
|
rsAPI api.RoomserverInternalAPI,
|
||||||
cfg *config.SyncAPI,
|
cfg *config.SyncAPI,
|
||||||
|
@ -151,6 +154,7 @@ func OnIncomingMessagesRequest(
|
||||||
wasToProvided: wasToProvided,
|
wasToProvided: wasToProvided,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
backwardOrdering: backwardOrdering,
|
backwardOrdering: backwardOrdering,
|
||||||
|
requester: device.UserID,
|
||||||
}
|
}
|
||||||
|
|
||||||
clientEvents, start, end, err := mReq.retrieveEvents()
|
clientEvents, start, end, err := mReq.retrieveEvents()
|
||||||
|
@ -239,6 +243,8 @@ func (r *messagesReq) retrieveEvents() (
|
||||||
events = reversed(events)
|
events = reversed(events)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events = internal.ApplyHistoryVisibilityChecks(r.ctx, r.requester, events)
|
||||||
|
|
||||||
// Convert all of the events into client events.
|
// Convert all of the events into client events.
|
||||||
clientEvents = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatAll)
|
clientEvents = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatAll)
|
||||||
// Get the position of the first and the last event in the room's topology.
|
// Get the position of the first and the last event in the room's topology.
|
||||||
|
|
|
@ -51,7 +51,7 @@ func Setup(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
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)
|
})).Methods(http.MethodGet, http.MethodOptions)
|
||||||
|
|
||||||
r0mux.Handle("/user/{userId}/filter",
|
r0mux.Handle("/user/{userId}/filter",
|
||||||
|
|
Loading…
Reference in a new issue