mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 18:43:10 -06:00
More tweaks around getting events
This commit is contained in:
parent
e47ad14a18
commit
9a27511b24
|
|
@ -60,21 +60,13 @@ func allowedToSeeEvent(
|
|||
rsAPI api.FederationRoomserverAPI,
|
||||
eventID string,
|
||||
) *util.JSONResponse {
|
||||
var authResponse api.QueryServerAllowedToSeeEventResponse
|
||||
err := rsAPI.QueryServerAllowedToSeeEvent(
|
||||
ctx,
|
||||
&api.QueryServerAllowedToSeeEventRequest{
|
||||
EventID: eventID,
|
||||
ServerName: origin,
|
||||
},
|
||||
&authResponse,
|
||||
)
|
||||
allowed, err := rsAPI.QueryServerAllowedToSeeEvent(ctx, origin, eventID)
|
||||
if err != nil {
|
||||
resErr := util.ErrorResponse(err)
|
||||
return &resErr
|
||||
}
|
||||
|
||||
if !authResponse.AllowedToSeeEvent {
|
||||
if !allowed {
|
||||
resErr := util.MessageResponse(http.StatusForbidden, "server not allowed to see event")
|
||||
return &resErr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ type FederationRoomserverAPI interface {
|
|||
// Query missing events for a room from roomserver
|
||||
QueryMissingEvents(ctx context.Context, req *QueryMissingEventsRequest, res *QueryMissingEventsResponse) error
|
||||
// Query whether a server is allowed to see an event
|
||||
QueryServerAllowedToSeeEvent(ctx context.Context, req *QueryServerAllowedToSeeEventRequest, res *QueryServerAllowedToSeeEventResponse) error
|
||||
QueryServerAllowedToSeeEvent(ctx context.Context, serverName gomatrixserverlib.ServerName, eventID string) (allowed bool, err error)
|
||||
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
||||
QueryRestrictedJoinAllowed(ctx context.Context, req *QueryRestrictedJoinAllowedRequest, res *QueryRestrictedJoinAllowedResponse) error
|
||||
PerformInboundPeek(ctx context.Context, req *PerformInboundPeekRequest, res *PerformInboundPeekResponse) error
|
||||
|
|
|
|||
|
|
@ -631,6 +631,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||
|
||||
_, redactedEvent, err := db.MaybeRedactEvent(ctx, roomInfo, eventNID, ev.Unwrap(), true)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to redact event")
|
||||
continue
|
||||
}
|
||||
// If storing this event results in it being redacted, then do so.
|
||||
|
|
|
|||
|
|
@ -433,39 +433,39 @@ func (r *Queryer) QueryServerJoinedToRoom(
|
|||
// QueryServerAllowedToSeeEvent implements api.RoomserverInternalAPI
|
||||
func (r *Queryer) QueryServerAllowedToSeeEvent(
|
||||
ctx context.Context,
|
||||
request *api.QueryServerAllowedToSeeEventRequest,
|
||||
response *api.QueryServerAllowedToSeeEventResponse,
|
||||
) (err error) {
|
||||
events, err := r.DB.EventsFromIDs(ctx, nil, []string{request.EventID})
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
eventID string,
|
||||
) (allowed bool, err error) {
|
||||
events, err := r.DB.EventNIDs(ctx, []string{eventID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(events) == 0 {
|
||||
response.AllowedToSeeEvent = false // event doesn't exist so not allowed to see
|
||||
return
|
||||
return allowed, nil
|
||||
}
|
||||
roomID := events[0].RoomID()
|
||||
|
||||
inRoomReq := &api.QueryServerJoinedToRoomRequest{
|
||||
RoomID: roomID,
|
||||
ServerName: request.ServerName,
|
||||
}
|
||||
inRoomRes := &api.QueryServerJoinedToRoomResponse{}
|
||||
if err = r.QueryServerJoinedToRoom(ctx, inRoomReq, inRoomRes); err != nil {
|
||||
return fmt.Errorf("r.Queryer.QueryServerJoinedToRoom: %w", err)
|
||||
}
|
||||
|
||||
info, err := r.DB.RoomInfo(ctx, roomID)
|
||||
info, err := r.DB.RoomInfoByNID(ctx, events[eventID].RoomNID)
|
||||
if err != nil {
|
||||
return err
|
||||
return allowed, err
|
||||
}
|
||||
if info == nil || info.IsStub() {
|
||||
return nil
|
||||
return allowed, nil
|
||||
}
|
||||
response.AllowedToSeeEvent, err = helpers.CheckServerAllowedToSeeEvent(
|
||||
ctx, r.DB, info, request.EventID, request.ServerName, inRoomRes.IsInRoom,
|
||||
var isInRoom bool
|
||||
if r.IsLocalServerName(serverName) || serverName == "" {
|
||||
isInRoom, err = r.DB.GetLocalServerInRoom(ctx, info.RoomNID)
|
||||
if err != nil {
|
||||
return allowed, fmt.Errorf("r.DB.GetLocalServerInRoom: %w", err)
|
||||
}
|
||||
} else {
|
||||
isInRoom, err = r.DB.GetServerInRoom(ctx, info.RoomNID, serverName)
|
||||
if err != nil {
|
||||
return allowed, fmt.Errorf("r.DB.GetServerInRoom: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return helpers.CheckServerAllowedToSeeEvent(
|
||||
ctx, r.DB, info, eventID, serverName, isInRoom,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// QueryMissingEvents implements api.RoomserverInternalAPI
|
||||
|
|
@ -487,19 +487,22 @@ func (r *Queryer) QueryMissingEvents(
|
|||
eventsToFilter[id] = true
|
||||
}
|
||||
}
|
||||
events, err := r.DB.EventsFromIDs(ctx, nil, front)
|
||||
if len(front) == 0 {
|
||||
return nil // no events to query, give up.
|
||||
}
|
||||
events, err := r.DB.EventNIDs(ctx, []string{front[0]})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(events) == 0 {
|
||||
return nil // we are missing the events being asked to search from, give up.
|
||||
}
|
||||
info, err := r.DB.RoomInfo(ctx, events[0].RoomID())
|
||||
info, err := r.DB.RoomInfoByNID(ctx, events[front[0]].RoomNID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info == nil || info.IsStub() {
|
||||
return fmt.Errorf("missing RoomInfo for room %s", events[0].RoomID())
|
||||
return fmt.Errorf("missing RoomInfo for room %d", events[front[0]].RoomNID)
|
||||
}
|
||||
|
||||
resultNIDs, redactEventIDs, err := helpers.ScanEventTree(ctx, r.DB, info, front, visited, request.Limit, request.ServerName)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/version"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/tidwall/gjson"
|
||||
|
|
@ -553,9 +552,8 @@ func (d *EventDatabase) Events(ctx context.Context, roomInfo *types.RoomInfo, ev
|
|||
func (d *EventDatabase) events(
|
||||
ctx context.Context, txn *sql.Tx, roomInfo *types.RoomInfo, inputEventNIDs types.EventNIDs,
|
||||
) ([]types.Event, error) {
|
||||
if roomInfo == nil {
|
||||
|
||||
roomInfo = &types.RoomInfo{RoomVersion: version.DefaultRoomVersion()}
|
||||
if roomInfo == nil { // this should never happen
|
||||
return nil, fmt.Errorf("unable to parse events without roomInfo")
|
||||
}
|
||||
|
||||
sort.Sort(inputEventNIDs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue