mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-21 19:21:39 +00:00
Remove gmsl.HeaderedEvent (#3068)
Replaced with types.HeaderedEvent _for now_. In reality we want to move them all to gmsl.Event and only use HeaderedEvent when we _need_ to bundle the version/event ID with the event (seriailsation boundaries, and even then only when we don't have the room version). Requires https://github.com/matrix-org/gomatrixserverlib/pull/373
This commit is contained in:
parent
2475cf4b61
commit
b189edf4f4
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
@ -104,7 +105,7 @@ func (s *OutputRoomEventConsumer) onMessage(
|
|||||||
ctx context.Context, state *appserviceState, msgs []*nats.Msg,
|
ctx context.Context, state *appserviceState, msgs []*nats.Msg,
|
||||||
) bool {
|
) bool {
|
||||||
log.WithField("appservice", state.ID).Tracef("Appservice worker received %d message(s) from roomserver", len(msgs))
|
log.WithField("appservice", state.ID).Tracef("Appservice worker received %d message(s) from roomserver", len(msgs))
|
||||||
events := make([]*gomatrixserverlib.HeaderedEvent, 0, len(msgs))
|
events := make([]*types.HeaderedEvent, 0, len(msgs))
|
||||||
for _, msg := range msgs {
|
for _, msg := range msgs {
|
||||||
// Only handle events we care about
|
// Only handle events we care about
|
||||||
receivedType := api.OutputType(msg.Header.Get(jetstream.RoomEventType))
|
receivedType := api.OutputType(msg.Header.Get(jetstream.RoomEventType))
|
||||||
@ -174,7 +175,7 @@ func (s *OutputRoomEventConsumer) onMessage(
|
|||||||
// endpoint. It will block for the backoff period if necessary.
|
// endpoint. It will block for the backoff period if necessary.
|
||||||
func (s *OutputRoomEventConsumer) sendEvents(
|
func (s *OutputRoomEventConsumer) sendEvents(
|
||||||
ctx context.Context, state *appserviceState,
|
ctx context.Context, state *appserviceState,
|
||||||
events []*gomatrixserverlib.HeaderedEvent,
|
events []*types.HeaderedEvent,
|
||||||
txnID string,
|
txnID string,
|
||||||
) error {
|
) error {
|
||||||
// Create the transaction body.
|
// Create the transaction body.
|
||||||
@ -231,7 +232,7 @@ func (s *appserviceState) backoffAndPause(err error) error {
|
|||||||
// event falls within one of a given application service's namespaces.
|
// event falls within one of a given application service's namespaces.
|
||||||
//
|
//
|
||||||
// TODO: This should be cached, see https://github.com/matrix-org/dendrite/issues/1682
|
// TODO: This should be cached, see https://github.com/matrix-org/dendrite/issues/1682
|
||||||
func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, appservice *config.ApplicationService) bool {
|
func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Context, event *types.HeaderedEvent, appservice *config.ApplicationService) bool {
|
||||||
switch {
|
switch {
|
||||||
case appservice.URL == "":
|
case appservice.URL == "":
|
||||||
return false
|
return false
|
||||||
@ -269,7 +270,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
|
|||||||
|
|
||||||
// appserviceJoinedAtEvent returns a boolean depending on whether a given
|
// appserviceJoinedAtEvent returns a boolean depending on whether a given
|
||||||
// appservice has membership at the time a given event was created.
|
// appservice has membership at the time a given event was created.
|
||||||
func (s *OutputRoomEventConsumer) appserviceJoinedAtEvent(ctx context.Context, event *gomatrixserverlib.HeaderedEvent, appservice *config.ApplicationService) bool {
|
func (s *OutputRoomEventConsumer) appserviceJoinedAtEvent(ctx context.Context, event *types.HeaderedEvent, appservice *config.ApplicationService) bool {
|
||||||
// TODO: This is only checking the current room state, not the state at
|
// TODO: This is only checking the current room state, not the state at
|
||||||
// the event in question. Pretty sure this is what Synapse does too, but
|
// the event in question. Pretty sure this is what Synapse does too, but
|
||||||
// until we have a lighter way of checking the state before the event that
|
// until we have a lighter way of checking the state before the event that
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
roomserverVersion "github.com/matrix-org/dendrite/roomserver/version"
|
roomserverVersion "github.com/matrix-org/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -431,7 +432,7 @@ func createRoom(
|
|||||||
// TODO: invite events
|
// TODO: invite events
|
||||||
// TODO: 3pid invite events
|
// TODO: 3pid invite events
|
||||||
|
|
||||||
var builtEvents []*gomatrixserverlib.HeaderedEvent
|
var builtEvents []*types.HeaderedEvent
|
||||||
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
for i, e := range eventsToMake {
|
for i, e := range eventsToMake {
|
||||||
depth := i + 1 // depth starts at 1
|
depth := i + 1 // depth starts at 1
|
||||||
@ -464,7 +465,7 @@ func createRoom(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the event to the list of auth events
|
// Add the event to the list of auth events
|
||||||
builtEvents = append(builtEvents, ev.Headered(roomVersion))
|
builtEvents = append(builtEvents, &types.HeaderedEvent{Event: ev})
|
||||||
err = authEvents.AddEvent(ev)
|
err = authEvents.AddEvent(ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("authEvents.AddEvent failed")
|
util.GetLogger(ctx).WithError(err).Error("authEvents.AddEvent failed")
|
||||||
@ -559,11 +560,11 @@ func createRoom(
|
|||||||
)
|
)
|
||||||
// Send the invite event to the roomserver.
|
// Send the invite event to the roomserver.
|
||||||
var inviteRes roomserverAPI.PerformInviteResponse
|
var inviteRes roomserverAPI.PerformInviteResponse
|
||||||
event := inviteEvent.Headered(roomVersion)
|
event := inviteEvent
|
||||||
if err := rsAPI.PerformInvite(ctx, &roomserverAPI.PerformInviteRequest{
|
if err := rsAPI.PerformInvite(ctx, &roomserverAPI.PerformInviteRequest{
|
||||||
Event: event,
|
Event: event,
|
||||||
InviteRoomState: inviteStrippedState,
|
InviteRoomState: inviteStrippedState,
|
||||||
RoomVersion: event.RoomVersion,
|
RoomVersion: event.Version(),
|
||||||
SendAsServer: string(userDomain),
|
SendAsServer: string(userDomain),
|
||||||
}, &inviteRes); err != nil {
|
}, &inviteRes); err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ func sendMembership(ctx context.Context, profileAPI userapi.ClientUserAPI, devic
|
|||||||
if err = roomserverAPI.SendEvents(
|
if err = roomserverAPI.SendEvents(
|
||||||
ctx, rsAPI,
|
ctx, rsAPI,
|
||||||
roomserverAPI.KindNew,
|
roomserverAPI.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{event},
|
[]*types.HeaderedEvent{event},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
serverName,
|
serverName,
|
||||||
serverName,
|
serverName,
|
||||||
@ -268,7 +269,7 @@ func sendInvite(
|
|||||||
if err := rsAPI.PerformInvite(ctx, &api.PerformInviteRequest{
|
if err := rsAPI.PerformInvite(ctx, &api.PerformInviteRequest{
|
||||||
Event: event,
|
Event: event,
|
||||||
InviteRoomState: nil, // ask the roomserver to draw up invite room state for us
|
InviteRoomState: nil, // ask the roomserver to draw up invite room state for us
|
||||||
RoomVersion: event.RoomVersion,
|
RoomVersion: event.Version(),
|
||||||
SendAsServer: string(device.UserDomain()),
|
SendAsServer: string(device.UserDomain()),
|
||||||
}, &inviteRes); err != nil {
|
}, &inviteRes); err != nil {
|
||||||
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
util.GetLogger(ctx).WithError(err).Error("PerformInvite failed")
|
||||||
@ -294,7 +295,7 @@ func buildMembershipEvent(
|
|||||||
membership, roomID string, isDirect bool,
|
membership, roomID string, isDirect bool,
|
||||||
cfg *config.ClientAPI, evTime time.Time,
|
cfg *config.ClientAPI, evTime time.Time,
|
||||||
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
|
rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*types.HeaderedEvent, error) {
|
||||||
profile, err := loadProfile(ctx, targetUserID, cfg, profileAPI, asAPI)
|
profile, err := loadProfile(ctx, targetUserID, cfg, profileAPI, asAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
|
|
||||||
@ -334,15 +335,10 @@ func buildMembershipEvents(
|
|||||||
roomIDs []string,
|
roomIDs []string,
|
||||||
newProfile authtypes.Profile, userID string, cfg *config.ClientAPI,
|
newProfile authtypes.Profile, userID string, cfg *config.ClientAPI,
|
||||||
evTime time.Time, rsAPI api.ClientRoomserverAPI,
|
evTime time.Time, rsAPI api.ClientRoomserverAPI,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*types.HeaderedEvent, error) {
|
||||||
evs := []*gomatrixserverlib.HeaderedEvent{}
|
evs := []*types.HeaderedEvent{}
|
||||||
|
|
||||||
for _, roomID := range roomIDs {
|
for _, roomID := range roomIDs {
|
||||||
roomVersion, err := rsAPI.QueryRoomVersionForRoom(ctx, roomID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder := gomatrixserverlib.EventBuilder{
|
builder := gomatrixserverlib.EventBuilder{
|
||||||
Sender: userID,
|
Sender: userID,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
@ -357,7 +353,7 @@ func buildMembershipEvents(
|
|||||||
content.DisplayName = newProfile.DisplayName
|
content.DisplayName = newProfile.DisplayName
|
||||||
content.AvatarURL = newProfile.AvatarURL
|
content.AvatarURL = newProfile.AvatarURL
|
||||||
|
|
||||||
if err = builder.SetContent(content); err != nil {
|
if err := builder.SetContent(content); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +367,7 @@ func buildMembershipEvents(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
evs = append(evs, event.Headered(roomVersion))
|
evs = append(evs, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
return evs, nil
|
return evs, nil
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/internal/transactions"
|
"github.com/matrix-org/dendrite/internal/transactions"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
)
|
)
|
||||||
@ -138,7 +139,7 @@ func SendRedaction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
domain := device.UserDomain()
|
domain := device.UserDomain()
|
||||||
if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*gomatrixserverlib.HeaderedEvent{e}, device.UserDomain(), domain, domain, nil, false); err != nil {
|
if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*types.HeaderedEvent{e}, device.UserDomain(), domain, domain, nil, false); err != nil {
|
||||||
util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents")
|
util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/internal/transactions"
|
"github.com/matrix-org/dendrite/internal/transactions"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
)
|
)
|
||||||
@ -183,8 +184,8 @@ func SendEvent(
|
|||||||
if err := api.SendEvents(
|
if err := api.SendEvents(
|
||||||
req.Context(), rsAPI,
|
req.Context(), rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
e.Headered(roomVersion),
|
&types.HeaderedEvent{Event: e},
|
||||||
},
|
},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
domain,
|
domain,
|
||||||
|
@ -22,12 +22,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/tokens"
|
"github.com/matrix-org/gomatrixserverlib/tokens"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/roomserver/version"
|
"github.com/matrix-org/dendrite/roomserver/version"
|
||||||
|
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
@ -227,8 +227,8 @@ func SendServerNotice(
|
|||||||
if err := api.SendEvents(
|
if err := api.SendEvents(
|
||||||
ctx, rsAPI,
|
ctx, rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
e.Headered(roomVersion),
|
&types.HeaderedEvent{Event: e},
|
||||||
},
|
},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
cfgClient.Matrix.ServerName,
|
cfgClient.Matrix.ServerName,
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -266,7 +267,7 @@ func OnIncomingStateTypeRequest(
|
|||||||
"state_at_event": !wantLatestState,
|
"state_at_event": !wantLatestState,
|
||||||
}).Info("Fetching state")
|
}).Info("Fetching state")
|
||||||
|
|
||||||
var event *gomatrixserverlib.HeaderedEvent
|
var event *types.HeaderedEvent
|
||||||
if wantLatestState {
|
if wantLatestState {
|
||||||
// If we are happy to use the latest state, either because the user is
|
// If we are happy to use the latest state, either because the user is
|
||||||
// still in the room, or because the room is world-readable, then just
|
// still in the room, or because the room is world-readable, then just
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -367,8 +368,8 @@ func emit3PIDInviteEvent(
|
|||||||
return api.SendEvents(
|
return api.SendEvents(
|
||||||
ctx, rsAPI,
|
ctx, rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
event.Headered(queryRes.RoomVersion),
|
event,
|
||||||
},
|
},
|
||||||
device.UserDomain(),
|
device.UserDomain(),
|
||||||
cfg.Matrix.ServerName,
|
cfg.Matrix.ServerName,
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/types"
|
"github.com/matrix-org/dendrite/federationapi/types"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FederationInternalAPI is used to query information from the federation sender.
|
// FederationInternalAPI is used to query information from the federation sender.
|
||||||
@ -189,13 +190,13 @@ type PerformLeaveResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PerformInviteRequest struct {
|
type PerformInviteRequest struct {
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *rstypes.HeaderedEvent `json:"event"`
|
||||||
InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
|
InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformInviteResponse struct {
|
type PerformInviteResponse struct {
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *rstypes.HeaderedEvent `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryJoinedHostServerNamesInRoomRequest is a request to QueryJoinedHostServerNames
|
// QueryJoinedHostServerNamesInRoomRequest is a request to QueryJoinedHostServerNames
|
||||||
|
@ -187,7 +187,12 @@ func (s *OutputRoomEventConsumer) processMessage(ore api.OutputNewRoomEvent, rew
|
|||||||
addsStateEvents = append(addsStateEvents, eventsRes.Events...)
|
addsStateEvents = append(addsStateEvents, eventsRes.Events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
addsJoinedHosts, err := JoinedHostsFromEvents(gomatrixserverlib.UnwrapEventHeaders(addsStateEvents))
|
evs := make([]*gomatrixserverlib.Event, len(addsStateEvents))
|
||||||
|
for i := range evs {
|
||||||
|
evs[i] = addsStateEvents[i].Event
|
||||||
|
}
|
||||||
|
|
||||||
|
addsJoinedHosts, err := JoinedHostsFromEvents(evs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/api"
|
"github.com/matrix-org/dendrite/federationapi/api"
|
||||||
"github.com/matrix-org/dendrite/federationapi/internal"
|
"github.com/matrix-org/dendrite/federationapi/internal"
|
||||||
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/dendrite/test/testrig"
|
"github.com/matrix-org/dendrite/test/testrig"
|
||||||
@ -137,10 +138,10 @@ func (f *fedClient) SendJoin(ctx context.Context, origin, s spec.ServerName, eve
|
|||||||
defer f.fedClientMutex.Unlock()
|
defer f.fedClientMutex.Unlock()
|
||||||
for _, r := range f.allowJoins {
|
for _, r := range f.allowJoins {
|
||||||
if r.ID == event.RoomID() {
|
if r.ID == event.RoomID() {
|
||||||
r.InsertEvent(f.t, event.Headered(r.Version))
|
r.InsertEvent(f.t, &types.HeaderedEvent{Event: event})
|
||||||
f.t.Logf("Join event: %v", event.EventID())
|
f.t.Logf("Join event: %v", event.EventID())
|
||||||
res.StateEvents = gomatrixserverlib.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
res.StateEvents = types.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
||||||
res.AuthEvents = gomatrixserverlib.NewEventJSONsFromHeaderedEvents(r.Events())
|
res.AuthEvents = types.NewEventJSONsFromHeaderedEvents(r.Events())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -327,8 +328,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to parse event: %s", err)
|
t.Errorf("failed to parse event: %s", err)
|
||||||
}
|
}
|
||||||
he := ev.Headered(tc.roomVer)
|
invReq, err := fclient.NewInviteV2Request(ev, nil)
|
||||||
invReq, err := fclient.NewInviteV2Request(he, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to create invite v2 request: %s", err)
|
t.Errorf("failed to create invite v2 request: %s", err)
|
||||||
continue
|
continue
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/consumers"
|
"github.com/matrix-org/dendrite/federationapi/consumers"
|
||||||
"github.com/matrix-org/dendrite/federationapi/statistics"
|
"github.com/matrix-org/dendrite/federationapi/statistics"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/roomserver/version"
|
"github.com/matrix-org/dendrite/roomserver/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -199,7 +200,7 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
|||||||
user.Domain(),
|
user.Domain(),
|
||||||
roomserverAPI.KindNew,
|
roomserverAPI.KindNew,
|
||||||
response.StateSnapshot,
|
response.StateSnapshot,
|
||||||
response.JoinEvent.Headered(response.JoinEvent.Version()),
|
&types.HeaderedEvent{Event: response.JoinEvent},
|
||||||
serverName,
|
serverName,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
@ -384,7 +385,7 @@ func (r *FederationInternalAPI) performOutboundPeekUsingServer(
|
|||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
|
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
|
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
|
||||||
},
|
},
|
||||||
respPeek.LatestEvent.Headered(respPeek.RoomVersion),
|
&types.HeaderedEvent{Event: respPeek.LatestEvent},
|
||||||
serverName,
|
serverName,
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
@ -531,7 +532,7 @@ func (r *FederationInternalAPI) PerformInvite(
|
|||||||
"destination": destination,
|
"destination": destination,
|
||||||
}).Info("Sending invite")
|
}).Info("Sending invite")
|
||||||
|
|
||||||
inviteReq, err := fclient.NewInviteV2Request(request.Event, request.InviteRoomState)
|
inviteReq, err := fclient.NewInviteV2Request(request.Event.Event, request.InviteRoomState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gomatrixserverlib.NewInviteV2Request: %w", err)
|
return fmt.Errorf("gomatrixserverlib.NewInviteV2Request: %w", err)
|
||||||
}
|
}
|
||||||
@ -549,7 +550,7 @@ func (r *FederationInternalAPI) PerformInvite(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err)
|
return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err)
|
||||||
}
|
}
|
||||||
response.Event = inviteEvent.Headered(request.RoomVersion)
|
response.Event = &types.HeaderedEvent{Event: inviteEvent}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/storage"
|
"github.com/matrix-org/dendrite/federationapi/storage"
|
||||||
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ type destinationQueue struct {
|
|||||||
// Send event adds the event to the pending queue for the destination.
|
// Send event adds the event to the pending queue for the destination.
|
||||||
// If the queue is empty then it starts a background goroutine to
|
// If the queue is empty then it starts a background goroutine to
|
||||||
// start sending events to that destination.
|
// start sending events to that destination.
|
||||||
func (oq *destinationQueue) sendEvent(event *gomatrixserverlib.HeaderedEvent, dbReceipt *receipt.Receipt) {
|
func (oq *destinationQueue) sendEvent(event *types.HeaderedEvent, dbReceipt *receipt.Receipt) {
|
||||||
if event == nil {
|
if event == nil {
|
||||||
logrus.Errorf("attempt to send nil PDU with destination %q", oq.destination)
|
logrus.Errorf("attempt to send nil PDU with destination %q", oq.destination)
|
||||||
return
|
return
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/storage"
|
"github.com/matrix-org/dendrite/federationapi/storage"
|
||||||
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ func NewOutgoingQueues(
|
|||||||
|
|
||||||
type queuedPDU struct {
|
type queuedPDU struct {
|
||||||
dbReceipt *receipt.Receipt
|
dbReceipt *receipt.Receipt
|
||||||
pdu *gomatrixserverlib.HeaderedEvent
|
pdu *types.HeaderedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
type queuedEDU struct {
|
type queuedEDU struct {
|
||||||
@ -187,7 +188,7 @@ func (oqs *OutgoingQueues) clearQueue(oq *destinationQueue) {
|
|||||||
|
|
||||||
// SendEvent sends an event to the destinations
|
// SendEvent sends an event to the destinations
|
||||||
func (oqs *OutgoingQueues) SendEvent(
|
func (oqs *OutgoingQueues) SendEvent(
|
||||||
ev *gomatrixserverlib.HeaderedEvent, origin spec.ServerName,
|
ev *types.HeaderedEvent, origin spec.ServerName,
|
||||||
destinations []spec.ServerName,
|
destinations []spec.ServerName,
|
||||||
) error {
|
) error {
|
||||||
if oqs.disabled {
|
if oqs.disabled {
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/statistics"
|
"github.com/matrix-org/dendrite/federationapi/statistics"
|
||||||
"github.com/matrix-org/dendrite/federationapi/storage"
|
"github.com/matrix-org/dendrite/federationapi/storage"
|
||||||
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
@ -101,14 +102,14 @@ func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u
|
|||||||
return fclient.EmptyResp{}, result
|
return fclient.EmptyResp{}, result
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent {
|
func mustCreatePDU(t *testing.T) *types.HeaderedEvent {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
content := `{"type":"m.room.message"}`
|
content := `{"type":"m.room.message"}`
|
||||||
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV10).NewEventFromTrustedJSON([]byte(content), false)
|
ev, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV10).NewEventFromTrustedJSON([]byte(content), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create event: %v", err)
|
t.Fatalf("failed to create event: %v", err)
|
||||||
}
|
}
|
||||||
return ev.Headered(gomatrixserverlib.RoomVersionV10)
|
return &types.HeaderedEvent{Event: ev}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreateEDU(t *testing.T) *gomatrixserverlib.EDU {
|
func mustCreateEDU(t *testing.T) *gomatrixserverlib.EDU {
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -104,7 +105,7 @@ func Backfill(
|
|||||||
// Filter any event that's not from the requested room out.
|
// Filter any event that's not from the requested room out.
|
||||||
evs := make([]*gomatrixserverlib.Event, 0)
|
evs := make([]*gomatrixserverlib.Event, 0)
|
||||||
|
|
||||||
var ev *gomatrixserverlib.HeaderedEvent
|
var ev *types.HeaderedEvent
|
||||||
for _, ev = range res.Events {
|
for _, ev = range res.Events {
|
||||||
if ev.RoomID() == roomID {
|
if ev.RoomID() == roomID {
|
||||||
evs = append(evs, ev.Event)
|
evs = append(evs, ev.Event)
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
@ -72,7 +72,7 @@ func GetEventAuth(
|
|||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: fclient.RespEventAuth{
|
JSON: fclient.RespEventAuth{
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -196,11 +197,11 @@ func processInvite(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Add the invite event to the roomserver.
|
// Add the invite event to the roomserver.
|
||||||
inviteEvent := signedEvent.Headered(roomVer)
|
inviteEvent := &types.HeaderedEvent{Event: &signedEvent}
|
||||||
request := &api.PerformInviteRequest{
|
request := &api.PerformInviteRequest{
|
||||||
Event: inviteEvent,
|
Event: inviteEvent,
|
||||||
InviteRoomState: strippedState,
|
InviteRoomState: strippedState,
|
||||||
RoomVersion: inviteEvent.RoomVersion,
|
RoomVersion: inviteEvent.Version(),
|
||||||
SendAsServer: string(api.DoNotSendToOtherServers),
|
SendAsServer: string(api.DoNotSendToOtherServers),
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -413,7 +414,7 @@ func SendJoin(
|
|||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
Event: signed.Headered(stateAndAuthChainResponse.RoomVersion),
|
Event: &types.HeaderedEvent{Event: &signed},
|
||||||
SendAsServer: string(cfg.Matrix.ServerName),
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
@ -443,8 +444,8 @@ func SendJoin(
|
|||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: fclient.RespSendJoin{
|
JSON: fclient.RespSendJoin{
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.StateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(stateAndAuthChainResponse.AuthChainEvents),
|
||||||
Origin: cfg.Matrix.ServerName,
|
Origin: cfg.Matrix.ServerName,
|
||||||
Event: signed.JSON(),
|
Event: signed.JSON(),
|
||||||
},
|
},
|
||||||
@ -519,7 +520,7 @@ func checkRestrictedJoin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type eventsByDepth []*gomatrixserverlib.HeaderedEvent
|
type eventsByDepth []*types.HeaderedEvent
|
||||||
|
|
||||||
func (e eventsByDepth) Len() int {
|
func (e eventsByDepth) Len() int {
|
||||||
return len(e)
|
return len(e)
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -101,7 +102,7 @@ func MakeLeave(
|
|||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: map[string]interface{}{
|
JSON: map[string]interface{}{
|
||||||
"room_version": event.RoomVersion,
|
"room_version": event.Version(),
|
||||||
"event": state,
|
"event": state,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -124,7 +125,7 @@ func MakeLeave(
|
|||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: map[string]interface{}{
|
JSON: map[string]interface{}{
|
||||||
"room_version": event.RoomVersion,
|
"room_version": event.Version(),
|
||||||
"event": builder,
|
"event": builder,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -312,7 +313,7 @@ func SendLeave(
|
|||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
Event: event.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: event},
|
||||||
SendAsServer: string(cfg.Matrix.ServerName),
|
SendAsServer: string(cfg.Matrix.ServerName),
|
||||||
TransactionID: nil,
|
TransactionID: nil,
|
||||||
},
|
},
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
@ -69,7 +69,7 @@ func GetMissingEvents(
|
|||||||
eventsResponse.Events = filterEvents(eventsResponse.Events, roomID)
|
eventsResponse.Events = filterEvents(eventsResponse.Events, roomID)
|
||||||
|
|
||||||
resp := fclient.RespMissingEvents{
|
resp := fclient.RespMissingEvents{
|
||||||
Events: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(eventsResponse.Events),
|
Events: types.NewEventJSONsFromHeaderedEvents(eventsResponse.Events),
|
||||||
}
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
@ -80,8 +80,8 @@ func GetMissingEvents(
|
|||||||
|
|
||||||
// filterEvents returns only those events with matching roomID
|
// filterEvents returns only those events with matching roomID
|
||||||
func filterEvents(
|
func filterEvents(
|
||||||
events []*gomatrixserverlib.HeaderedEvent, roomID string,
|
events []*types.HeaderedEvent, roomID string,
|
||||||
) []*gomatrixserverlib.HeaderedEvent {
|
) []*types.HeaderedEvent {
|
||||||
ref := events[:0]
|
ref := events[:0]
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
if ev.RoomID() == roomID {
|
if ev.RoomID() == roomID {
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -87,10 +88,10 @@ func Peek(
|
|||||||
}
|
}
|
||||||
|
|
||||||
respPeek := fclient.RespPeek{
|
respPeek := fclient.RespPeek{
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(response.StateEvents),
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(response.AuthChainEvents),
|
||||||
RoomVersion: response.RoomVersion,
|
RoomVersion: response.RoomVersion,
|
||||||
LatestEvent: response.LatestEvent.Unwrap(),
|
LatestEvent: response.LatestEvent.Event,
|
||||||
RenewalInterval: renewalInterval,
|
RenewalInterval: renewalInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
@ -42,8 +42,8 @@ func GetState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return util.JSONResponse{Code: http.StatusOK, JSON: &fclient.RespState{
|
return util.JSONResponse{Code: http.StatusOK, JSON: &fclient.RespState{
|
||||||
AuthEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(authChain),
|
AuthEvents: types.NewEventJSONsFromHeaderedEvents(authChain),
|
||||||
StateEvents: gomatrixserverlib.NewEventJSONsFromHeaderedEvents(stateEvents),
|
StateEvents: types.NewEventJSONsFromHeaderedEvents(stateEvents),
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ func getState(
|
|||||||
rsAPI api.FederationRoomserverAPI,
|
rsAPI api.FederationRoomserverAPI,
|
||||||
roomID string,
|
roomID string,
|
||||||
eventID string,
|
eventID string,
|
||||||
) (stateEvents, authEvents []*gomatrixserverlib.HeaderedEvent, errRes *util.JSONResponse) {
|
) (stateEvents, authEvents []*types.HeaderedEvent, errRes *util.JSONResponse) {
|
||||||
// If we don't think we belong to this room then don't waste the effort
|
// If we don't think we belong to this room then don't waste the effort
|
||||||
// responding to expensive requests for it.
|
// responding to expensive requests for it.
|
||||||
if err := ErrorIfLocalServerNotInRoom(ctx, rsAPI, roomID); err != nil {
|
if err := ErrorIfLocalServerNotInRoom(ctx, rsAPI, roomID); err != nil {
|
||||||
@ -157,7 +157,7 @@ func getState(
|
|||||||
return response.StateEvents, response.AuthChainEvents, nil
|
return response.StateEvents, response.AuthChainEvents, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIDsFromEvent(events []*gomatrixserverlib.HeaderedEvent) []string {
|
func getIDsFromEvent(events []*types.HeaderedEvent) []string {
|
||||||
IDs := make([]string, len(events))
|
IDs := make([]string, len(events))
|
||||||
for i := range events {
|
for i := range events {
|
||||||
IDs[i] = events[i].EventID()
|
IDs[i] = events[i].EventID()
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
@ -67,9 +68,9 @@ func CreateInvitesFrom3PIDInvites(
|
|||||||
return *reqErr
|
return *reqErr
|
||||||
}
|
}
|
||||||
|
|
||||||
evs := []*gomatrixserverlib.HeaderedEvent{}
|
evs := []*types.HeaderedEvent{}
|
||||||
for _, inv := range body.Invites {
|
for _, inv := range body.Invites {
|
||||||
roomVersion, err := rsAPI.QueryRoomVersionForRoom(req.Context(), inv.RoomID)
|
_, err := rsAPI.QueryRoomVersionForRoom(req.Context(), inv.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
@ -85,7 +86,7 @@ func CreateInvitesFrom3PIDInvites(
|
|||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
if event != nil {
|
if event != nil {
|
||||||
evs = append(evs, event.Headered(roomVersion))
|
evs = append(evs, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +184,7 @@ func ExchangeThirdPartyInvite(
|
|||||||
|
|
||||||
// Ask the requesting server to sign the newly created event so we know it
|
// Ask the requesting server to sign the newly created event so we know it
|
||||||
// acknowledged it
|
// acknowledged it
|
||||||
inviteReq, err := fclient.NewInviteV2Request(event.Headered(roomVersion), nil)
|
inviteReq, err := fclient.NewInviteV2Request(event, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("failed to make invite v2 request")
|
util.GetLogger(httpReq.Context()).WithError(err).Error("failed to make invite v2 request")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -208,8 +209,8 @@ func ExchangeThirdPartyInvite(
|
|||||||
if err = api.SendEvents(
|
if err = api.SendEvents(
|
||||||
httpReq.Context(), rsAPI,
|
httpReq.Context(), rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
[]*types.HeaderedEvent{
|
||||||
inviteEvent.Headered(roomVersion),
|
{Event: inviteEvent},
|
||||||
},
|
},
|
||||||
request.Destination(),
|
request.Destination(),
|
||||||
request.Origin(),
|
request.Origin(),
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
||||||
"github.com/matrix-org/dendrite/federationapi/types"
|
"github.com/matrix-org/dendrite/federationapi/types"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Database interface {
|
type Database interface {
|
||||||
@ -38,7 +39,7 @@ type Database interface {
|
|||||||
|
|
||||||
StoreJSON(ctx context.Context, js string) (*receipt.Receipt, error)
|
StoreJSON(ctx context.Context, js string) (*receipt.Receipt, error)
|
||||||
|
|
||||||
GetPendingPDUs(ctx context.Context, serverName spec.ServerName, limit int) (pdus map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent, err error)
|
GetPendingPDUs(ctx context.Context, serverName spec.ServerName, limit int) (pdus map[*receipt.Receipt]*rstypes.HeaderedEvent, err error)
|
||||||
GetPendingEDUs(ctx context.Context, serverName spec.ServerName, limit int) (edus map[*receipt.Receipt]*gomatrixserverlib.EDU, err error)
|
GetPendingEDUs(ctx context.Context, serverName spec.ServerName, limit int) (edus map[*receipt.Receipt]*gomatrixserverlib.EDU, err error)
|
||||||
|
|
||||||
AssociatePDUWithDestinations(ctx context.Context, destinations map[spec.ServerName]struct{}, dbReceipt *receipt.Receipt) error
|
AssociatePDUWithDestinations(ctx context.Context, destinations map[spec.ServerName]struct{}, dbReceipt *receipt.Receipt) error
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
"github.com/matrix-org/dendrite/federationapi/storage/shared/receipt"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ func (d *Database) GetPendingPDUs(
|
|||||||
serverName spec.ServerName,
|
serverName spec.ServerName,
|
||||||
limit int,
|
limit int,
|
||||||
) (
|
) (
|
||||||
events map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent,
|
events map[*receipt.Receipt]*types.HeaderedEvent,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
// Strictly speaking this doesn't need to be using the writer
|
// Strictly speaking this doesn't need to be using the writer
|
||||||
@ -64,7 +64,7 @@ func (d *Database) GetPendingPDUs(
|
|||||||
// a guarantee of transactional isolation, it's actually useful
|
// a guarantee of transactional isolation, it's actually useful
|
||||||
// to know in SQLite mode that nothing else is trying to modify
|
// to know in SQLite mode that nothing else is trying to modify
|
||||||
// the database.
|
// the database.
|
||||||
events = make(map[*receipt.Receipt]*gomatrixserverlib.HeaderedEvent)
|
events = make(map[*receipt.Receipt]*types.HeaderedEvent)
|
||||||
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
nids, err := d.FederationQueuePDUs.SelectQueuePDUs(ctx, txn, serverName, limit)
|
nids, err := d.FederationQueuePDUs.SelectQueuePDUs(ctx, txn, serverName, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -87,7 +87,7 @@ func (d *Database) GetPendingPDUs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for nid, blob := range blobs {
|
for nid, blob := range blobs {
|
||||||
var event gomatrixserverlib.HeaderedEvent
|
var event types.HeaderedEvent
|
||||||
if err := json.Unmarshal(blob, &event); err != nil {
|
if err := json.Unmarshal(blob, &event); err != nil {
|
||||||
return fmt.Errorf("json.Unmarshal: %w", err)
|
return fmt.Errorf("json.Unmarshal: %w", err)
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427002343-809b162d0e4f
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427113737-4a73af377afe
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
|
||||||
github.com/mattn/go-sqlite3 v1.14.16
|
github.com/mattn/go-sqlite3 v1.14.16
|
||||||
|
10
go.sum
10
go.sum
@ -321,8 +321,14 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
|
|||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427002343-809b162d0e4f h1:nck6OTEVtxXoF9mDsvZRXaXjNkz03DuhNgrl462xOso=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230424155704-8daeaebaa0bc h1:F73iHhpTZxWVO6qbyGZxd7Ch44v1gK6xNQZ7QVos/Es=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427002343-809b162d0e4f/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230424155704-8daeaebaa0bc/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230425114847-3f4aa39cdc54 h1:FiXd7w+dfX9/z0g1r//Xvhvk731mTyTJOWNBqqA6q9Q=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230425114847-3f4aa39cdc54/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427083830-f2324ed2e085 h1:QRj+06UWlwpZJFAa0AzxlWqRNVnh17vIgR141WSfu98=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427083830-f2324ed2e085/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427113737-4a73af377afe h1:+FeGaWZCDw7w3DGZhQW3n0amZ4iW5at/ocErlOFrO58=
|
||||||
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20230427113737-4a73af377afe/go.mod h1:7HTbSZe+CIdmeqVyFMekwD5dFU8khWQyngKATvd12FU=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
|
||||||
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
|
||||||
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package caching
|
package caching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FederationCache contains the subset of functions needed for
|
// FederationCache contains the subset of functions needed for
|
||||||
// a federation event cache.
|
// a federation event cache.
|
||||||
type FederationCache interface {
|
type FederationCache interface {
|
||||||
GetFederationQueuedPDU(eventNID int64) (event *gomatrixserverlib.HeaderedEvent, ok bool)
|
GetFederationQueuedPDU(eventNID int64) (event *types.HeaderedEvent, ok bool)
|
||||||
StoreFederationQueuedPDU(eventNID int64, event *gomatrixserverlib.HeaderedEvent)
|
StoreFederationQueuedPDU(eventNID int64, event *types.HeaderedEvent)
|
||||||
EvictFederationQueuedPDU(eventNID int64)
|
EvictFederationQueuedPDU(eventNID int64)
|
||||||
|
|
||||||
GetFederationQueuedEDU(eventNID int64) (event *gomatrixserverlib.EDU, ok bool)
|
GetFederationQueuedEDU(eventNID int64) (event *gomatrixserverlib.EDU, ok bool)
|
||||||
@ -16,11 +17,11 @@ type FederationCache interface {
|
|||||||
EvictFederationQueuedEDU(eventNID int64)
|
EvictFederationQueuedEDU(eventNID int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) GetFederationQueuedPDU(eventNID int64) (*gomatrixserverlib.HeaderedEvent, bool) {
|
func (c Caches) GetFederationQueuedPDU(eventNID int64) (*types.HeaderedEvent, bool) {
|
||||||
return c.FederationPDUs.Get(eventNID)
|
return c.FederationPDUs.Get(eventNID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Caches) StoreFederationQueuedPDU(eventNID int64, event *gomatrixserverlib.HeaderedEvent) {
|
func (c Caches) StoreFederationQueuedPDU(eventNID int64, event *types.HeaderedEvent) {
|
||||||
c.FederationPDUs.Set(eventNID, event)
|
c.FederationPDUs.Set(eventNID, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ type Caches struct {
|
|||||||
RoomServerStateKeyNIDs Cache[string, types.EventStateKeyNID] // event state key -> eventStateKey NID
|
RoomServerStateKeyNIDs Cache[string, types.EventStateKeyNID] // event state key -> eventStateKey NID
|
||||||
RoomServerEventTypeNIDs Cache[string, types.EventTypeNID] // eventType -> eventType NID
|
RoomServerEventTypeNIDs Cache[string, types.EventTypeNID] // eventType -> eventType NID
|
||||||
RoomServerEventTypes Cache[types.EventTypeNID, string] // eventType NID -> eventType
|
RoomServerEventTypes Cache[types.EventTypeNID, string] // eventType NID -> eventType
|
||||||
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
|
FederationPDUs Cache[int64, *types.HeaderedEvent] // queue NID -> PDU
|
||||||
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
|
||||||
SpaceSummaryRooms Cache[string, fclient.MSC2946SpacesResponse] // room ID -> space response
|
SpaceSummaryRooms Cache[string, fclient.MSC2946SpacesResponse] // room ID -> space response
|
||||||
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
LazyLoading Cache[lazyLoadingCacheKey, string] // composite key -> event ID
|
||||||
|
@ -131,8 +131,8 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
|
|||||||
Prefix: eventTypeNIDCache,
|
Prefix: eventTypeNIDCache,
|
||||||
MaxAge: maxAge,
|
MaxAge: maxAge,
|
||||||
},
|
},
|
||||||
FederationPDUs: &RistrettoCostedCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{ // queue NID -> PDU
|
FederationPDUs: &RistrettoCostedCachePartition[int64, *types.HeaderedEvent]{ // queue NID -> PDU
|
||||||
&RistrettoCachePartition[int64, *gomatrixserverlib.HeaderedEvent]{
|
&RistrettoCachePartition[int64, *types.HeaderedEvent]{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
Prefix: federationPDUsCache,
|
Prefix: federationPDUsCache,
|
||||||
Mutable: true,
|
Mutable: true,
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
@ -43,7 +44,7 @@ func QueryAndBuildEvent(
|
|||||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
||||||
identity *fclient.SigningIdentity, evTime time.Time,
|
identity *fclient.SigningIdentity, evTime time.Time,
|
||||||
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
rsAPI api.QueryLatestEventsAndStateAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*types.HeaderedEvent, error) {
|
||||||
if queryRes == nil {
|
if queryRes == nil {
|
||||||
queryRes = &api.QueryLatestEventsAndStateResponse{}
|
queryRes = &api.QueryLatestEventsAndStateResponse{}
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ func BuildEvent(
|
|||||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
builder *gomatrixserverlib.EventBuilder, cfg *config.Global,
|
||||||
identity *fclient.SigningIdentity, evTime time.Time,
|
identity *fclient.SigningIdentity, evTime time.Time,
|
||||||
eventsNeeded *gomatrixserverlib.StateNeeded, queryRes *api.QueryLatestEventsAndStateResponse,
|
eventsNeeded *gomatrixserverlib.StateNeeded, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*types.HeaderedEvent, error) {
|
||||||
if err := addPrevEventsToEvent(builder, eventsNeeded, queryRes); err != nil {
|
if err := addPrevEventsToEvent(builder, eventsNeeded, queryRes); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -76,7 +77,7 @@ func BuildEvent(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return event.Headered(queryRes.RoomVersion), nil
|
return &types.HeaderedEvent{Event: event}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// queryRequiredEventsForBuilder queries the roomserver for auth/prev events needed for this builder.
|
// queryRequiredEventsForBuilder queries the roomserver for auth/prev events needed for this builder.
|
||||||
|
@ -21,17 +21,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// KindNewEventPersisted is a hook which is called with *gomatrixserverlib.HeaderedEvent
|
// KindNewEventPersisted is a hook which is called with *types.HeaderedEvent
|
||||||
// It is run when a new event is persisted in the roomserver.
|
// It is run when a new event is persisted in the roomserver.
|
||||||
// Usage:
|
// Usage:
|
||||||
// hooks.Attach(hooks.KindNewEventPersisted, func(headeredEvent interface{}) { ... })
|
// hooks.Attach(hooks.KindNewEventPersisted, func(headeredEvent interface{}) { ... })
|
||||||
KindNewEventPersisted = "new_event_persisted"
|
KindNewEventPersisted = "new_event_persisted"
|
||||||
// KindNewEventReceived is a hook which is called with *gomatrixserverlib.HeaderedEvent
|
// KindNewEventReceived is a hook which is called with *types.HeaderedEvent
|
||||||
// It is run before a new event is processed by the roomserver. This hook can be used
|
// It is run before a new event is processed by the roomserver. This hook can be used
|
||||||
// to modify the event before it is persisted by adding data to `unsigned`.
|
// to modify the event before it is persisted by adding data to `unsigned`.
|
||||||
// Usage:
|
// Usage:
|
||||||
// hooks.Attach(hooks.KindNewEventReceived, func(headeredEvent interface{}) {
|
// hooks.Attach(hooks.KindNewEventReceived, func(headeredEvent interface{}) {
|
||||||
// ev := headeredEvent.(*gomatrixserverlib.HeaderedEvent)
|
// ev := headeredEvent.(*types.HeaderedEvent)
|
||||||
// _ = ev.SetUnsignedField("key", "val")
|
// _ = ev.SetUnsignedField("key", "val")
|
||||||
// })
|
// })
|
||||||
KindNewEventReceived = "new_event_received"
|
KindNewEventReceived = "new_event_received"
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/federationapi/producers"
|
"github.com/matrix-org/dendrite/federationapi/producers"
|
||||||
"github.com/matrix-org/dendrite/federationapi/types"
|
"github.com/matrix-org/dendrite/federationapi/types"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
syncTypes "github.com/matrix-org/dendrite/syncapi/types"
|
syncTypes "github.com/matrix-org/dendrite/syncapi/types"
|
||||||
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -182,8 +183,8 @@ func (t *TxnReq) ProcessTransaction(ctx context.Context) (*fclient.RespSend, *ut
|
|||||||
ctx,
|
ctx,
|
||||||
t.rsAPI,
|
t.rsAPI,
|
||||||
api.KindNew,
|
api.KindNew,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{
|
[]*rstypes.HeaderedEvent{
|
||||||
event.Headered(roomVersion),
|
{Event: event},
|
||||||
},
|
},
|
||||||
t.Destination,
|
t.Destination,
|
||||||
t.Origin,
|
t.Origin,
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/federationapi/producers"
|
"github.com/matrix-org/dendrite/federationapi/producers"
|
||||||
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
|
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
@ -59,8 +60,8 @@ var (
|
|||||||
}
|
}
|
||||||
testEvent = []byte(`{"auth_events":["$x4MKEPRSF6OGlo0qpnsP3BfSmYX5HhVlykOsQH3ECyg","$BcEcbZnlFLB5rxSNSZNBn6fO3jU/TKAJ79wfKyCQLiU"],"content":{"body":"Test Message"},"depth":3917,"hashes":{"sha256":"cNAWtlHIegrji0mMA6x1rhpYCccY8W1NsWZqSpJFhjs"},"origin":"localhost","origin_server_ts":0,"prev_events":["$4GDB0bVjkWwS3G4noUZCq5oLWzpBYpwzdMcf7gj24CI"],"room_id":"!roomid:localhost","sender":"@userid:localhost","signatures":{"localhost":{"ed25519:auto":"NKym6Kcy3u9mGUr21Hjfe3h7DfDilDhN5PqztT0QZ4NTZ+8Y7owseLolQVXp+TvNjecvzdDywsXXVvGiuQiWAQ"}},"type":"m.room.message"}`)
|
testEvent = []byte(`{"auth_events":["$x4MKEPRSF6OGlo0qpnsP3BfSmYX5HhVlykOsQH3ECyg","$BcEcbZnlFLB5rxSNSZNBn6fO3jU/TKAJ79wfKyCQLiU"],"content":{"body":"Test Message"},"depth":3917,"hashes":{"sha256":"cNAWtlHIegrji0mMA6x1rhpYCccY8W1NsWZqSpJFhjs"},"origin":"localhost","origin_server_ts":0,"prev_events":["$4GDB0bVjkWwS3G4noUZCq5oLWzpBYpwzdMcf7gj24CI"],"room_id":"!roomid:localhost","sender":"@userid:localhost","signatures":{"localhost":{"ed25519:auto":"NKym6Kcy3u9mGUr21Hjfe3h7DfDilDhN5PqztT0QZ4NTZ+8Y7owseLolQVXp+TvNjecvzdDywsXXVvGiuQiWAQ"}},"type":"m.room.message"}`)
|
||||||
testRoomVersion = gomatrixserverlib.RoomVersionV1
|
testRoomVersion = gomatrixserverlib.RoomVersionV1
|
||||||
testEvents = []*gomatrixserverlib.HeaderedEvent{}
|
testEvents = []*rstypes.HeaderedEvent{}
|
||||||
testStateEvents = make(map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent)
|
testStateEvents = make(map[gomatrixserverlib.StateKeyTuple]*rstypes.HeaderedEvent)
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeRsAPI struct {
|
type FakeRsAPI struct {
|
||||||
@ -635,7 +636,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("cannot load test data: " + err.Error())
|
panic("cannot load test data: " + err.Error())
|
||||||
}
|
}
|
||||||
h := e.Headered(testRoomVersion)
|
h := &rstypes.HeaderedEvent{Event: e}
|
||||||
testEvents = append(testEvents, h)
|
testEvents = append(testEvents, h)
|
||||||
if e.StateKey() != nil {
|
if e.StateKey() != nil {
|
||||||
testStateEvents[gomatrixserverlib.StateKeyTuple{
|
testStateEvents[gomatrixserverlib.StateKeyTuple{
|
||||||
@ -777,7 +778,7 @@ NextPDU:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertInputRoomEvents(t *testing.T, got []rsAPI.InputRoomEvent, want []*gomatrixserverlib.HeaderedEvent) {
|
func assertInputRoomEvents(t *testing.T, got []rsAPI.InputRoomEvent, want []*rstypes.HeaderedEvent) {
|
||||||
for _, g := range got {
|
for _, g := range got {
|
||||||
fmt.Println("GOT ", g.Event.EventID())
|
fmt.Println("GOT ", g.Event.EventID())
|
||||||
}
|
}
|
||||||
@ -801,7 +802,7 @@ func TestBasicTransaction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
txn := mustCreateTransaction(rsAPI, pdus)
|
txn := mustCreateTransaction(rsAPI, pdus)
|
||||||
mustProcessTransaction(t, txn, nil)
|
mustProcessTransaction(t, txn, nil)
|
||||||
assertInputRoomEvents(t, rsAPI.inputRoomEvents, []*gomatrixserverlib.HeaderedEvent{testEvents[len(testEvents)-1]})
|
assertInputRoomEvents(t, rsAPI.inputRoomEvents, []*rstypes.HeaderedEvent{testEvents[len(testEvents)-1]})
|
||||||
}
|
}
|
||||||
|
|
||||||
// The purpose of this test is to check that if the event received fails auth checks the event is still sent to the roomserver
|
// The purpose of this test is to check that if the event received fails auth checks the event is still sent to the roomserver
|
||||||
@ -814,5 +815,5 @@ func TestTransactionFailAuthChecks(t *testing.T) {
|
|||||||
txn := mustCreateTransaction(rsAPI, pdus)
|
txn := mustCreateTransaction(rsAPI, pdus)
|
||||||
mustProcessTransaction(t, txn, []string{})
|
mustProcessTransaction(t, txn, []string{})
|
||||||
// expect message to be sent to the roomserver
|
// expect message to be sent to the roomserver
|
||||||
assertInputRoomEvents(t, rsAPI.inputRoomEvents, []*gomatrixserverlib.HeaderedEvent{testEvents[len(testEvents)-1]})
|
assertInputRoomEvents(t, rsAPI.inputRoomEvents, []*rstypes.HeaderedEvent{testEvents[len(testEvents)-1]})
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -34,7 +35,7 @@ type ServerACLDatabase interface {
|
|||||||
// GetStateEvent returns the state event of a given type for a given room with a given state key
|
// GetStateEvent returns the state event of a given type for a given room with a given state key
|
||||||
// If no event could be found, returns nil
|
// If no event could be found, returns nil
|
||||||
// If there was an issue during the retrieval, returns an error
|
// If there was an issue during the retrieval, returns an error
|
||||||
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error)
|
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*types.HeaderedEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerACLs struct {
|
type ServerACLs struct {
|
||||||
|
@ -102,7 +102,7 @@ type SyncRoomserverAPI interface {
|
|||||||
) error
|
) error
|
||||||
|
|
||||||
// QueryMembershipAtEvent queries the memberships at the given events.
|
// QueryMembershipAtEvent queries the memberships at the given events.
|
||||||
// Returns a map from eventID to a slice of gomatrixserverlib.HeaderedEvent.
|
// Returns a map from eventID to a slice of types.HeaderedEvent.
|
||||||
QueryMembershipAtEvent(
|
QueryMembershipAtEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *QueryMembershipAtEventRequest,
|
request *QueryMembershipAtEventRequest,
|
||||||
|
@ -18,6 +18,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
)
|
)
|
||||||
@ -67,7 +68,7 @@ type InputRoomEvent struct {
|
|||||||
// This controls how the event is processed.
|
// This controls how the event is processed.
|
||||||
Kind Kind `json:"kind"`
|
Kind Kind `json:"kind"`
|
||||||
// The event JSON for the event to add.
|
// The event JSON for the event to add.
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *types.HeaderedEvent `json:"event"`
|
||||||
// Which server told us about this event.
|
// Which server told us about this event.
|
||||||
Origin spec.ServerName `json:"origin"`
|
Origin spec.ServerName `json:"origin"`
|
||||||
// Whether the state is supplied as a list of event IDs or whether it
|
// Whether the state is supplied as a list of event IDs or whether it
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
)
|
)
|
||||||
@ -107,7 +108,7 @@ const (
|
|||||||
// prev_events.
|
// prev_events.
|
||||||
type OutputNewRoomEvent struct {
|
type OutputNewRoomEvent struct {
|
||||||
// The Event.
|
// The Event.
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *types.HeaderedEvent `json:"event"`
|
||||||
// Does the event completely rewrite the room state? If so, then AddsStateEventIDs
|
// Does the event completely rewrite the room state? If so, then AddsStateEventIDs
|
||||||
// will contain the entire room state.
|
// will contain the entire room state.
|
||||||
RewritesState bool `json:"rewrites_state,omitempty"`
|
RewritesState bool `json:"rewrites_state,omitempty"`
|
||||||
@ -170,8 +171,8 @@ type OutputNewRoomEvent struct {
|
|||||||
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OutputNewRoomEvent) NeededStateEventIDs() ([]*gomatrixserverlib.HeaderedEvent, []string) {
|
func (o *OutputNewRoomEvent) NeededStateEventIDs() ([]*types.HeaderedEvent, []string) {
|
||||||
addsStateEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, 1)
|
addsStateEvents := make([]*types.HeaderedEvent, 0, 1)
|
||||||
missingEventIDs := make([]string, 0, len(o.AddsStateEventIDs))
|
missingEventIDs := make([]string, 0, len(o.AddsStateEventIDs))
|
||||||
for _, eventID := range o.AddsStateEventIDs {
|
for _, eventID := range o.AddsStateEventIDs {
|
||||||
if eventID != o.Event.EventID() {
|
if eventID != o.Event.EventID() {
|
||||||
@ -194,7 +195,7 @@ func (o *OutputNewRoomEvent) NeededStateEventIDs() ([]*gomatrixserverlib.Headere
|
|||||||
// should build their current room state up from OutputNewRoomEvents only.
|
// should build their current room state up from OutputNewRoomEvents only.
|
||||||
type OutputOldRoomEvent struct {
|
type OutputOldRoomEvent struct {
|
||||||
// The Event.
|
// The Event.
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *types.HeaderedEvent `json:"event"`
|
||||||
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ type OutputNewInviteEvent struct {
|
|||||||
// The room version of the invited room.
|
// The room version of the invited room.
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
// The "m.room.member" invite event.
|
// The "m.room.member" invite event.
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *types.HeaderedEvent `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// An OutputRetireInviteEvent is written whenever an existing invite is no longer
|
// An OutputRetireInviteEvent is written whenever an existing invite is no longer
|
||||||
@ -232,7 +233,7 @@ type OutputRedactedEvent struct {
|
|||||||
// The event ID that was redacted
|
// The event ID that was redacted
|
||||||
RedactedEventID string
|
RedactedEventID string
|
||||||
// The value of `unsigned.redacted_because` - the redaction event itself
|
// The value of `unsigned.redacted_because` - the redaction event itself
|
||||||
RedactedBecause *gomatrixserverlib.HeaderedEvent
|
RedactedBecause *types.HeaderedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
// An OutputNewPeek is written whenever a user starts peeking into a room
|
// An OutputNewPeek is written whenever a user starts peeking into a room
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PerformErrorCode int
|
type PerformErrorCode int
|
||||||
@ -105,11 +106,11 @@ type PerformLeaveResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PerformInviteRequest struct {
|
type PerformInviteRequest struct {
|
||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
Event *types.HeaderedEvent `json:"event"`
|
||||||
InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
|
InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
|
||||||
SendAsServer string `json:"send_as_server"`
|
SendAsServer string `json:"send_as_server"`
|
||||||
TransactionID *TransactionID `json:"transaction_id"`
|
TransactionID *TransactionID `json:"transaction_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformInviteResponse struct {
|
type PerformInviteResponse struct {
|
||||||
@ -168,7 +169,7 @@ func (r *PerformBackfillRequest) PrevEventIDs() []string {
|
|||||||
// PerformBackfillResponse is a response to PerformBackfill.
|
// PerformBackfillResponse is a response to PerformBackfill.
|
||||||
type PerformBackfillResponse struct {
|
type PerformBackfillResponse struct {
|
||||||
// Missing events, arbritrary order.
|
// Missing events, arbritrary order.
|
||||||
Events []*gomatrixserverlib.HeaderedEvent `json:"events"`
|
Events []*types.HeaderedEvent `json:"events"`
|
||||||
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
HistoryVisibility gomatrixserverlib.HistoryVisibility `json:"history_visibility"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,10 +201,10 @@ type PerformInboundPeekResponse struct {
|
|||||||
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
||||||
// The current state and auth chain events.
|
// The current state and auth chain events.
|
||||||
// The lists will be in an arbitrary order.
|
// The lists will be in an arbitrary order.
|
||||||
StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"`
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
||||||
AuthChainEvents []*gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"`
|
AuthChainEvents []*types.HeaderedEvent `json:"auth_chain_events"`
|
||||||
// The event at which this state was captured
|
// The event at which this state was captured
|
||||||
LatestEvent *gomatrixserverlib.HeaderedEvent `json:"latest_event"`
|
LatestEvent *types.HeaderedEvent `json:"latest_event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformForgetRequest is a request to PerformForget
|
// PerformForgetRequest is a request to PerformForget
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ type QueryLatestEventsAndStateResponse struct {
|
|||||||
// This list will be in an arbitrary order.
|
// This list will be in an arbitrary order.
|
||||||
// These are used to set the auth_events when sending an event.
|
// These are used to set the auth_events when sending an event.
|
||||||
// These are used to check whether the event is allowed.
|
// These are used to check whether the event is allowed.
|
||||||
StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"`
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
||||||
// The depth of the latest events.
|
// The depth of the latest events.
|
||||||
// This is one greater than the maximum depth of the latest events.
|
// This is one greater than the maximum depth of the latest events.
|
||||||
// This is used to set the depth when sending an event.
|
// This is used to set the depth when sending an event.
|
||||||
@ -83,7 +84,7 @@ type QueryStateAfterEventsResponse struct {
|
|||||||
PrevEventsExist bool `json:"prev_events_exist"`
|
PrevEventsExist bool `json:"prev_events_exist"`
|
||||||
// The state events requested.
|
// The state events requested.
|
||||||
// This list will be in an arbitrary order.
|
// This list will be in an arbitrary order.
|
||||||
StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"`
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryEventsByIDRequest is a request to QueryEventsByID
|
// QueryEventsByIDRequest is a request to QueryEventsByID
|
||||||
@ -104,7 +105,7 @@ type QueryEventsByIDResponse struct {
|
|||||||
// fails to read it from the database then it will fail
|
// fails to read it from the database then it will fail
|
||||||
// the entire request.
|
// the entire request.
|
||||||
// This list will be in an arbitrary order.
|
// This list will be in an arbitrary order.
|
||||||
Events []*gomatrixserverlib.HeaderedEvent `json:"events"`
|
Events []*types.HeaderedEvent `json:"events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryMembershipForUserRequest is a request to QueryMembership
|
// QueryMembershipForUserRequest is a request to QueryMembership
|
||||||
@ -202,7 +203,7 @@ type QueryMissingEventsRequest struct {
|
|||||||
// QueryMissingEventsResponse is a response to QueryMissingEvents
|
// QueryMissingEventsResponse is a response to QueryMissingEvents
|
||||||
type QueryMissingEventsResponse struct {
|
type QueryMissingEventsResponse struct {
|
||||||
// Missing events, arbritrary order.
|
// Missing events, arbritrary order.
|
||||||
Events []*gomatrixserverlib.HeaderedEvent `json:"events"`
|
Events []*types.HeaderedEvent `json:"events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryStateAndAuthChainRequest is a request to QueryStateAndAuthChain
|
// QueryStateAndAuthChainRequest is a request to QueryStateAndAuthChain
|
||||||
@ -236,8 +237,8 @@ type QueryStateAndAuthChainResponse struct {
|
|||||||
StateKnown bool `json:"state_known"`
|
StateKnown bool `json:"state_known"`
|
||||||
// The state and auth chain events that were requested.
|
// The state and auth chain events that were requested.
|
||||||
// The lists will be in an arbitrary order.
|
// The lists will be in an arbitrary order.
|
||||||
StateEvents []*gomatrixserverlib.HeaderedEvent `json:"state_events"`
|
StateEvents []*types.HeaderedEvent `json:"state_events"`
|
||||||
AuthChainEvents []*gomatrixserverlib.HeaderedEvent `json:"auth_chain_events"`
|
AuthChainEvents []*types.HeaderedEvent `json:"auth_chain_events"`
|
||||||
// True if the queried event was rejected earlier.
|
// True if the queried event was rejected earlier.
|
||||||
IsRejected bool `json:"is_rejected"`
|
IsRejected bool `json:"is_rejected"`
|
||||||
}
|
}
|
||||||
@ -269,7 +270,7 @@ type QueryAuthChainRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueryAuthChainResponse struct {
|
type QueryAuthChainResponse struct {
|
||||||
AuthChain []*gomatrixserverlib.HeaderedEvent
|
AuthChain []*types.HeaderedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
type QuerySharedUsersRequest struct {
|
type QuerySharedUsersRequest struct {
|
||||||
@ -327,7 +328,7 @@ type QueryCurrentStateRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type QueryCurrentStateResponse struct {
|
type QueryCurrentStateResponse struct {
|
||||||
StateEvents map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent
|
StateEvents map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryKnownUsersRequest struct {
|
type QueryKnownUsersRequest struct {
|
||||||
@ -404,7 +405,7 @@ func (r *QueryBulkStateContentResponse) UnmarshalJSON(data []byte) error {
|
|||||||
|
|
||||||
// MarshalJSON stringifies the StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
// MarshalJSON stringifies the StateKeyTuple keys so they can be sent over the wire in HTTP API mode.
|
||||||
func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) {
|
func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) {
|
||||||
se := make(map[string]*gomatrixserverlib.HeaderedEvent, len(r.StateEvents))
|
se := make(map[string]*types.HeaderedEvent, len(r.StateEvents))
|
||||||
for k, v := range r.StateEvents {
|
for k, v := range r.StateEvents {
|
||||||
// use 0x1F (unit separator) as the delimiter between type/state key,
|
// use 0x1F (unit separator) as the delimiter between type/state key,
|
||||||
se[fmt.Sprintf("%s\x1F%s", k.EventType, k.StateKey)] = v
|
se[fmt.Sprintf("%s\x1F%s", k.EventType, k.StateKey)] = v
|
||||||
@ -413,12 +414,12 @@ func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *QueryCurrentStateResponse) UnmarshalJSON(data []byte) error {
|
func (r *QueryCurrentStateResponse) UnmarshalJSON(data []byte) error {
|
||||||
res := make(map[string]*gomatrixserverlib.HeaderedEvent)
|
res := make(map[string]*types.HeaderedEvent)
|
||||||
err := json.Unmarshal(data, &res)
|
err := json.Unmarshal(data, &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
r.StateEvents = make(map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent, len(res))
|
r.StateEvents = make(map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent, len(res))
|
||||||
for k, v := range res {
|
for k, v := range res {
|
||||||
fields := strings.Split(k, "\x1F")
|
fields := strings.Split(k, "\x1F")
|
||||||
r.StateEvents[gomatrixserverlib.StateKeyTuple{
|
r.StateEvents[gomatrixserverlib.StateKeyTuple{
|
||||||
@ -442,7 +443,7 @@ type QueryMembershipAtEventResponse struct {
|
|||||||
// Membership is a map from eventID to membership event. Events that
|
// Membership is a map from eventID to membership event. Events that
|
||||||
// do not have known state will return a nil event, resulting in a "leave" membership
|
// do not have known state will return a nil event, resulting in a "leave" membership
|
||||||
// when calculating history visibility.
|
// when calculating history visibility.
|
||||||
Membership map[string]*gomatrixserverlib.HeaderedEvent `json:"membership"`
|
Membership map[string]*types.HeaderedEvent `json:"membership"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryLeftUsersRequest is a request to calculate users that we (the server) don't share a
|
// QueryLeftUsersRequest is a request to calculate users that we (the server) don't share a
|
||||||
|
@ -17,6 +17,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
@ -27,7 +28,7 @@ import (
|
|||||||
// SendEvents to the roomserver The events are written with KindNew.
|
// SendEvents to the roomserver The events are written with KindNew.
|
||||||
func SendEvents(
|
func SendEvents(
|
||||||
ctx context.Context, rsAPI InputRoomEventsAPI,
|
ctx context.Context, rsAPI InputRoomEventsAPI,
|
||||||
kind Kind, events []*gomatrixserverlib.HeaderedEvent,
|
kind Kind, events []*types.HeaderedEvent,
|
||||||
virtualHost, origin spec.ServerName,
|
virtualHost, origin spec.ServerName,
|
||||||
sendAsServer spec.ServerName, txnID *TransactionID,
|
sendAsServer spec.ServerName, txnID *TransactionID,
|
||||||
async bool,
|
async bool,
|
||||||
@ -51,10 +52,10 @@ func SendEvents(
|
|||||||
func SendEventWithState(
|
func SendEventWithState(
|
||||||
ctx context.Context, rsAPI InputRoomEventsAPI,
|
ctx context.Context, rsAPI InputRoomEventsAPI,
|
||||||
virtualHost spec.ServerName, kind Kind,
|
virtualHost spec.ServerName, kind Kind,
|
||||||
state gomatrixserverlib.StateResponse, event *gomatrixserverlib.HeaderedEvent,
|
state gomatrixserverlib.StateResponse, event *types.HeaderedEvent,
|
||||||
origin spec.ServerName, haveEventIDs map[string]bool, async bool,
|
origin spec.ServerName, haveEventIDs map[string]bool, async bool,
|
||||||
) error {
|
) error {
|
||||||
outliers := gomatrixserverlib.LineariseStateResponse(event.RoomVersion, state)
|
outliers := gomatrixserverlib.LineariseStateResponse(event.Version(), state)
|
||||||
ires := make([]InputRoomEvent, 0, len(outliers))
|
ires := make([]InputRoomEvent, 0, len(outliers))
|
||||||
for _, outlier := range outliers {
|
for _, outlier := range outliers {
|
||||||
if haveEventIDs[outlier.EventID()] {
|
if haveEventIDs[outlier.EventID()] {
|
||||||
@ -62,12 +63,12 @@ func SendEventWithState(
|
|||||||
}
|
}
|
||||||
ires = append(ires, InputRoomEvent{
|
ires = append(ires, InputRoomEvent{
|
||||||
Kind: KindOutlier,
|
Kind: KindOutlier,
|
||||||
Event: outlier.Headered(event.RoomVersion),
|
Event: &types.HeaderedEvent{Event: outlier},
|
||||||
Origin: origin,
|
Origin: origin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stateEvents := state.GetStateEvents().UntrustedEvents(event.RoomVersion)
|
stateEvents := state.GetStateEvents().UntrustedEvents(event.Version())
|
||||||
stateEventIDs := make([]string, len(stateEvents))
|
stateEventIDs := make([]string, len(stateEvents))
|
||||||
for i := range stateEvents {
|
for i := range stateEvents {
|
||||||
stateEventIDs[i] = stateEvents[i].EventID()
|
stateEventIDs[i] = stateEvents[i].EventID()
|
||||||
@ -110,7 +111,7 @@ func SendInputRoomEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEvent returns the event or nil, even on errors.
|
// GetEvent returns the event or nil, even on errors.
|
||||||
func GetEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID, eventID string) *gomatrixserverlib.HeaderedEvent {
|
func GetEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID, eventID string) *types.HeaderedEvent {
|
||||||
var res QueryEventsByIDResponse
|
var res QueryEventsByIDResponse
|
||||||
err := rsAPI.QueryEventsByID(ctx, &QueryEventsByIDRequest{
|
err := rsAPI.QueryEventsByID(ctx, &QueryEventsByIDRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
@ -127,7 +128,7 @@ func GetEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID, eventID string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetStateEvent returns the current state event in the room or nil.
|
// GetStateEvent returns the current state event in the room or nil.
|
||||||
func GetStateEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID string, tuple gomatrixserverlib.StateKeyTuple) *gomatrixserverlib.HeaderedEvent {
|
func GetStateEvent(ctx context.Context, rsAPI QueryEventsAPI, roomID string, tuple gomatrixserverlib.StateKeyTuple) *types.HeaderedEvent {
|
||||||
var res QueryCurrentStateResponse
|
var res QueryCurrentStateResponse
|
||||||
err := rsAPI.QueryCurrentState(ctx, &QueryCurrentStateRequest{
|
err := rsAPI.QueryCurrentState(ctx, &QueryCurrentStateRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/internal/helpers"
|
"github.com/matrix-org/dendrite/roomserver/internal/helpers"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@ -140,7 +141,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if creatorID != request.UserID {
|
if creatorID != request.UserID {
|
||||||
var plEvent *gomatrixserverlib.HeaderedEvent
|
var plEvent *types.HeaderedEvent
|
||||||
var pls *gomatrixserverlib.PowerLevelContent
|
var pls *gomatrixserverlib.PowerLevelContent
|
||||||
|
|
||||||
plEvent, err = r.DB.GetStateEvent(ctx, roomID, spec.MRoomPowerLevels, "")
|
plEvent, err = r.DB.GetStateEvent(ctx, roomID, spec.MRoomPowerLevels, "")
|
||||||
@ -212,7 +213,7 @@ func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = api.SendEvents(ctx, r, api.KindNew, []*gomatrixserverlib.HeaderedEvent{newEvent}, virtualHost, r.ServerName, r.ServerName, nil, false)
|
err = api.SendEvents(ctx, r, api.KindNew, []*types.HeaderedEvent{newEvent}, virtualHost, r.ServerName, r.ServerName, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func CheckForSoftFail(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
db storage.RoomDatabase,
|
db storage.RoomDatabase,
|
||||||
roomInfo *types.RoomInfo,
|
roomInfo *types.RoomInfo,
|
||||||
event *gomatrixserverlib.HeaderedEvent,
|
event *types.HeaderedEvent,
|
||||||
stateEventIDs []string,
|
stateEventIDs []string,
|
||||||
) (bool, error) {
|
) (bool, error) {
|
||||||
rewritesState := len(stateEventIDs) > 1
|
rewritesState := len(stateEventIDs) > 1
|
||||||
@ -65,7 +65,7 @@ func CheckForSoftFail(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Work out which of the state events we actually need.
|
// Work out which of the state events we actually need.
|
||||||
stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Unwrap()})
|
stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Event})
|
||||||
|
|
||||||
// Load the actual auth events from the database.
|
// Load the actual auth events from the database.
|
||||||
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
||||||
@ -87,7 +87,7 @@ func CheckAuthEvents(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
db storage.RoomDatabase,
|
db storage.RoomDatabase,
|
||||||
roomInfo *types.RoomInfo,
|
roomInfo *types.RoomInfo,
|
||||||
event *gomatrixserverlib.HeaderedEvent,
|
event *types.HeaderedEvent,
|
||||||
authEventIDs []string,
|
authEventIDs []string,
|
||||||
) ([]types.EventNID, error) {
|
) ([]types.EventNID, error) {
|
||||||
// Grab the numeric IDs for the supplied auth state events from the database.
|
// Grab the numeric IDs for the supplied auth state events from the database.
|
||||||
@ -98,7 +98,7 @@ func CheckAuthEvents(
|
|||||||
authStateEntries = types.DeduplicateStateEntries(authStateEntries)
|
authStateEntries = types.DeduplicateStateEntries(authStateEntries)
|
||||||
|
|
||||||
// Work out which of the state events we actually need.
|
// Work out which of the state events we actually need.
|
||||||
stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Unwrap()})
|
stateNeeded := gomatrixserverlib.StateNeededForAuth([]*gomatrixserverlib.Event{event.Event})
|
||||||
|
|
||||||
// Load the actual auth events from the database.
|
// Load the actual auth events from the database.
|
||||||
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
authEvents, err := loadAuthEvents(ctx, db, roomInfo, stateNeeded, authStateEntries)
|
||||||
|
@ -45,7 +45,7 @@ func UpdateToInviteMembership(
|
|||||||
updates = append(updates, api.OutputEvent{
|
updates = append(updates, api.OutputEvent{
|
||||||
Type: api.OutputTypeNewInviteEvent,
|
Type: api.OutputTypeNewInviteEvent,
|
||||||
NewInviteEvent: &api.OutputNewInviteEvent{
|
NewInviteEvent: &api.OutputNewInviteEvent{
|
||||||
Event: add.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: add.Event},
|
||||||
RoomVersion: roomVersion,
|
RoomVersion: roomVersion,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -479,7 +479,7 @@ func QueryLatestEventsAndState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, event.Headered(roomInfo.RoomVersion))
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -41,7 +41,7 @@ func TestIsInvitePendingWithoutNID(t *testing.T) {
|
|||||||
var authNIDs []types.EventNID
|
var authNIDs []types.EventNID
|
||||||
for _, x := range room.Events() {
|
for _, x := range room.Events() {
|
||||||
|
|
||||||
roomInfo, err := db.GetOrCreateRoomInfo(context.Background(), x.Unwrap())
|
roomInfo, err := db.GetOrCreateRoomInfo(context.Background(), x.Event)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, roomInfo)
|
assert.NotNil(t, roomInfo)
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
|
|
||||||
// Parse and validate the event JSON
|
// Parse and validate the event JSON
|
||||||
headered := input.Event
|
headered := input.Event
|
||||||
event := headered.Unwrap()
|
event := headered.Event
|
||||||
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
logger := util.GetLogger(ctx).WithFields(logrus.Fields{
|
||||||
"event_id": event.EventID(),
|
"event_id": event.EventID(),
|
||||||
"room_id": event.RoomID(),
|
"room_id": event.RoomID(),
|
||||||
@ -235,7 +235,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
haveEvents: map[string]*gomatrixserverlib.Event{},
|
haveEvents: map[string]*gomatrixserverlib.Event{},
|
||||||
}
|
}
|
||||||
var stateSnapshot *parsedRespState
|
var stateSnapshot *parsedRespState
|
||||||
if stateSnapshot, err = missingState.processEventWithMissingState(ctx, event, headered.RoomVersion); err != nil {
|
if stateSnapshot, err = missingState.processEventWithMissingState(ctx, event, headered.Version()); err != nil {
|
||||||
// Something went wrong with retrieving the missing state, so we can't
|
// Something went wrong with retrieving the missing state, so we can't
|
||||||
// really do anything with the event other than reject it at this point.
|
// really do anything with the event other than reject it at this point.
|
||||||
isRejected = true
|
isRejected = true
|
||||||
@ -467,7 +467,7 @@ func (r *Inputer) processRoomEvent(
|
|||||||
Type: api.OutputTypeRedactedEvent,
|
Type: api.OutputTypeRedactedEvent,
|
||||||
RedactedEvent: &api.OutputRedactedEvent{
|
RedactedEvent: &api.OutputRedactedEvent{
|
||||||
RedactedEventID: redactedEventID,
|
RedactedEventID: redactedEventID,
|
||||||
RedactedBecause: redactionEvent.Headered(headered.RoomVersion),
|
RedactedBecause: &types.HeaderedEvent{Event: redactionEvent},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -509,7 +509,7 @@ func (r *Inputer) processStateBefore(
|
|||||||
missingPrev bool,
|
missingPrev bool,
|
||||||
) (historyVisibility gomatrixserverlib.HistoryVisibility, rejectionErr error, err error) {
|
) (historyVisibility gomatrixserverlib.HistoryVisibility, rejectionErr error, err error) {
|
||||||
historyVisibility = gomatrixserverlib.HistoryVisibilityShared // Default to shared.
|
historyVisibility = gomatrixserverlib.HistoryVisibilityShared // Default to shared.
|
||||||
event := input.Event.Unwrap()
|
event := input.Event.Event
|
||||||
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
isCreateEvent := event.Type() == spec.MRoomCreate && event.StateKeyEquals("")
|
||||||
var stateBeforeEvent []*gomatrixserverlib.Event
|
var stateBeforeEvent []*gomatrixserverlib.Event
|
||||||
switch {
|
switch {
|
||||||
@ -567,7 +567,10 @@ func (r *Inputer) processStateBefore(
|
|||||||
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
rejectionErr = fmt.Errorf("prev events of %q are not known", event.EventID())
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
stateBeforeEvent = gomatrixserverlib.UnwrapEventHeaders(stateBeforeRes.StateEvents)
|
stateBeforeEvent = make([]*gomatrixserverlib.Event, len(stateBeforeRes.StateEvents))
|
||||||
|
for i := range stateBeforeRes.StateEvents {
|
||||||
|
stateBeforeEvent[i] = stateBeforeRes.StateEvents[i].Event
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// At this point, stateBeforeEvent should be populated either by
|
// At this point, stateBeforeEvent should be populated either by
|
||||||
@ -575,6 +578,7 @@ func (r *Inputer) processStateBefore(
|
|||||||
// Check whether the event is allowed or not.
|
// Check whether the event is allowed or not.
|
||||||
stateBeforeAuth := gomatrixserverlib.NewAuthEvents(stateBeforeEvent)
|
stateBeforeAuth := gomatrixserverlib.NewAuthEvents(stateBeforeEvent)
|
||||||
if rejectionErr = gomatrixserverlib.Allowed(event, &stateBeforeAuth); rejectionErr != nil {
|
if rejectionErr = gomatrixserverlib.Allowed(event, &stateBeforeAuth); rejectionErr != nil {
|
||||||
|
rejectionErr = fmt.Errorf("Allowed() failed for stateBeforeEvent: %w", rejectionErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Work out what the history visibility was at the time of the
|
// Work out what the history visibility was at the time of the
|
||||||
@ -604,7 +608,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
logger *logrus.Entry,
|
logger *logrus.Entry,
|
||||||
roomInfo *types.RoomInfo,
|
roomInfo *types.RoomInfo,
|
||||||
virtualHost spec.ServerName,
|
virtualHost spec.ServerName,
|
||||||
event *gomatrixserverlib.HeaderedEvent,
|
event *types.HeaderedEvent,
|
||||||
auth *gomatrixserverlib.AuthEvents,
|
auth *gomatrixserverlib.AuthEvents,
|
||||||
known map[string]*types.Event,
|
known map[string]*types.Event,
|
||||||
servers []spec.ServerName,
|
servers []spec.ServerName,
|
||||||
@ -654,7 +658,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
// Request the entire auth chain for the event in question. This should
|
// Request the entire auth chain for the event in question. This should
|
||||||
// contain all of the auth events — including ones that we already know —
|
// contain all of the auth events — including ones that we already know —
|
||||||
// so we'll need to filter through those in the next section.
|
// so we'll need to filter through those in the next section.
|
||||||
res, err = r.FSAPI.GetEventAuth(ctx, virtualHost, serverName, event.RoomVersion, event.RoomID(), event.EventID())
|
res, err = r.FSAPI.GetEventAuth(ctx, virtualHost, serverName, event.Version(), event.RoomID(), event.EventID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.WithError(err).Warnf("Failed to get event auth from federation for %q: %s", event.EventID(), err)
|
logger.WithError(err).Warnf("Failed to get event auth from federation for %q: %s", event.EventID(), err)
|
||||||
continue
|
continue
|
||||||
@ -671,7 +675,7 @@ func (r *Inputer) fetchAuthEvents(
|
|||||||
isRejected := false
|
isRejected := false
|
||||||
nextAuthEvent:
|
nextAuthEvent:
|
||||||
for _, authEvent := range gomatrixserverlib.ReverseTopologicalOrdering(
|
for _, authEvent := range gomatrixserverlib.ReverseTopologicalOrdering(
|
||||||
res.AuthEvents.UntrustedEvents(event.RoomVersion),
|
res.AuthEvents.UntrustedEvents(event.Version()),
|
||||||
gomatrixserverlib.TopologicalOrderByAuthEvents,
|
gomatrixserverlib.TopologicalOrderByAuthEvents,
|
||||||
) {
|
) {
|
||||||
// If we already know about this event from the database then we don't
|
// If we already know about this event from the database then we don't
|
||||||
|
@ -393,7 +393,7 @@ func (u *latestEventsUpdater) makeOutputNewRoomEvent() (*api.OutputEvent, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ore := api.OutputNewRoomEvent{
|
ore := api.OutputNewRoomEvent{
|
||||||
Event: u.event.Headered(u.roomInfo.RoomVersion),
|
Event: &types.HeaderedEvent{Event: u.event},
|
||||||
RewritesState: u.rewritesState,
|
RewritesState: u.rewritesState,
|
||||||
LastSentEventID: u.lastEventIDSent,
|
LastSentEventID: u.lastEventIDSent,
|
||||||
LatestEventIDs: latestEventIDs,
|
LatestEventIDs: latestEventIDs,
|
||||||
|
@ -106,7 +106,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
for _, newEvent := range newEvents {
|
for _, newEvent := range newEvents {
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: newEvent.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: newEvent},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
SendAsServer: api.DoNotSendToOtherServers,
|
SendAsServer: api.DoNotSendToOtherServers,
|
||||||
})
|
})
|
||||||
@ -155,7 +155,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
}
|
}
|
||||||
outlierRoomEvents = append(outlierRoomEvents, api.InputRoomEvent{
|
outlierRoomEvents = append(outlierRoomEvents, api.InputRoomEvent{
|
||||||
Kind: api.KindOutlier,
|
Kind: api.KindOutlier,
|
||||||
Event: outlier.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: outlier},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
|
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: backwardsExtremity.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: backwardsExtremity},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
HasState: true,
|
HasState: true,
|
||||||
StateEventIDs: stateIDs,
|
StateEventIDs: stateIDs,
|
||||||
@ -204,7 +204,7 @@ func (t *missingStateReq) processEventWithMissingState(
|
|||||||
for _, newEvent := range newEvents {
|
for _, newEvent := range newEvents {
|
||||||
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
err = t.inputer.processRoomEvent(ctx, t.virtualHost, &api.InputRoomEvent{
|
||||||
Kind: api.KindOld,
|
Kind: api.KindOld,
|
||||||
Event: newEvent.Headered(roomVersion),
|
Event: &types.HeaderedEvent{Event: newEvent},
|
||||||
Origin: t.origin,
|
Origin: t.origin,
|
||||||
SendAsServer: api.DoNotSendToOtherServers,
|
SendAsServer: api.DoNotSendToOtherServers,
|
||||||
})
|
})
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/test"
|
"github.com/matrix-org/dendrite/test"
|
||||||
"github.com/matrix-org/dendrite/test/testrig"
|
"github.com/matrix-org/dendrite/test/testrig"
|
||||||
@ -44,7 +45,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
in := api.InputRoomEvent{
|
in := api.InputRoomEvent{
|
||||||
Kind: api.KindOutlier, // don't panic if we generate an output event
|
Kind: api.KindOutlier, // don't panic if we generate an output event
|
||||||
Event: event.Headered(gomatrixserverlib.RoomVersionV6),
|
Event: &types.HeaderedEvent{Event: event},
|
||||||
}
|
}
|
||||||
|
|
||||||
inputter := &input.Inputer{
|
inputter := &input.Inputer{
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
||||||
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
@ -346,15 +347,15 @@ func (r *Admin) PerformAdminDownloadState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
authEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, len(authEventMap))
|
authEvents := make([]*types.HeaderedEvent, 0, len(authEventMap))
|
||||||
stateEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, len(stateEventMap))
|
stateEvents := make([]*types.HeaderedEvent, 0, len(stateEventMap))
|
||||||
stateIDs := make([]string, 0, len(stateEventMap))
|
stateIDs := make([]string, 0, len(stateEventMap))
|
||||||
|
|
||||||
for _, authEvent := range authEventMap {
|
for _, authEvent := range authEventMap {
|
||||||
authEvents = append(authEvents, authEvent.Headered(roomInfo.RoomVersion))
|
authEvents = append(authEvents, &types.HeaderedEvent{Event: authEvent})
|
||||||
}
|
}
|
||||||
for _, stateEvent := range stateEventMap {
|
for _, stateEvent := range stateEventMap {
|
||||||
stateEvents = append(stateEvents, stateEvent.Headered(roomInfo.RoomVersion))
|
stateEvents = append(stateEvents, &types.HeaderedEvent{Event: stateEvent})
|
||||||
stateIDs = append(stateIDs, stateEvent.EventID())
|
stateIDs = append(stateIDs, stateEvent.EventID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func (r *Backfiller) PerformBackfill(
|
|||||||
if _, ok := redactEventIDs[event.EventID()]; ok {
|
if _, ok := redactEventIDs[event.EventID()]; ok {
|
||||||
event.Redact()
|
event.Redact()
|
||||||
}
|
}
|
||||||
response.Events = append(response.Events, event.Headered(info.RoomVersion))
|
response.Events = append(response.Events, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -168,7 +168,10 @@ func (r *Backfiller) backfillViaFederation(ctx context.Context, req *api.Perform
|
|||||||
|
|
||||||
// TODO: update backwards extremities, as that should be moved from syncapi to roomserver at some point.
|
// TODO: update backwards extremities, as that should be moved from syncapi to roomserver at some point.
|
||||||
|
|
||||||
res.Events = events
|
res.Events = make([]*types.HeaderedEvent, len(events))
|
||||||
|
for i := range events {
|
||||||
|
res.Events[i] = &types.HeaderedEvent{Event: events[i]}
|
||||||
|
}
|
||||||
res.HistoryVisibility = requester.historyVisiblity
|
res.HistoryVisibility = requester.historyVisiblity
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -186,7 +189,7 @@ func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gom
|
|||||||
util.GetLogger(ctx).WithError(err).Warn("cannot query missing events")
|
util.GetLogger(ctx).WithError(err).Warn("cannot query missing events")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
missingMap := make(map[string]*gomatrixserverlib.HeaderedEvent) // id -> event
|
missingMap := make(map[string]*types.HeaderedEvent) // id -> event
|
||||||
for _, id := range stateIDs {
|
for _, id := range stateIDs {
|
||||||
if _, ok := nidMap[id]; !ok {
|
if _, ok := nidMap[id]; !ok {
|
||||||
missingMap[id] = nil
|
missingMap[id] = nil
|
||||||
@ -227,15 +230,15 @@ func (r *Backfiller) fetchAndStoreMissingEvents(ctx context.Context, roomVer gom
|
|||||||
logger.WithError(err).Warn("event failed PDU checks")
|
logger.WithError(err).Warn("event failed PDU checks")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
missingMap[id] = res.Event
|
missingMap[id] = &types.HeaderedEvent{Event: res.Event}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newEvents []*gomatrixserverlib.HeaderedEvent
|
var newEvents []*gomatrixserverlib.Event
|
||||||
for _, ev := range missingMap {
|
for _, ev := range missingMap {
|
||||||
if ev != nil {
|
if ev != nil {
|
||||||
newEvents = append(newEvents, ev)
|
newEvents = append(newEvents, ev.Event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
util.GetLogger(ctx).Infof("Persisting %d new events", len(newEvents))
|
util.GetLogger(ctx).Infof("Persisting %d new events", len(newEvents))
|
||||||
@ -282,8 +285,8 @@ func newBackfillRequester(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent *gomatrixserverlib.HeaderedEvent) ([]string, error) {
|
func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent *gomatrixserverlib.Event) ([]string, error) {
|
||||||
b.eventIDMap[targetEvent.EventID()] = targetEvent.Unwrap()
|
b.eventIDMap[targetEvent.EventID()] = targetEvent
|
||||||
if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok {
|
if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok {
|
||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
@ -305,7 +308,7 @@ func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent
|
|||||||
if !ok {
|
if !ok {
|
||||||
goto FederationHit
|
goto FederationHit
|
||||||
}
|
}
|
||||||
newStateIDs := b.calculateNewStateIDs(targetEvent.Unwrap(), prevEvent, prevEventStateIDs)
|
newStateIDs := b.calculateNewStateIDs(targetEvent, prevEvent, prevEventStateIDs)
|
||||||
if newStateIDs != nil {
|
if newStateIDs != nil {
|
||||||
b.eventIDToBeforeStateIDs[targetEvent.EventID()] = newStateIDs
|
b.eventIDToBeforeStateIDs[targetEvent.EventID()] = newStateIDs
|
||||||
return newStateIDs, nil
|
return newStateIDs, nil
|
||||||
@ -372,7 +375,7 @@ func (b *backfillRequester) calculateNewStateIDs(targetEvent, prevEvent *gomatri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatrixserverlib.RoomVersion,
|
func (b *backfillRequester) StateBeforeEvent(ctx context.Context, roomVer gomatrixserverlib.RoomVersion,
|
||||||
event *gomatrixserverlib.HeaderedEvent, eventIDs []string) (map[string]*gomatrixserverlib.Event, error) {
|
event *gomatrixserverlib.Event, eventIDs []string) (map[string]*gomatrixserverlib.Event, error) {
|
||||||
|
|
||||||
// try to fetch the events from the database first
|
// try to fetch the events from the database first
|
||||||
events, err := b.ProvideEvents(roomVer, eventIDs)
|
events, err := b.ProvideEvents(roomVer, eventIDs)
|
||||||
@ -587,7 +590,7 @@ func joinEventsFromHistoryVisibility(
|
|||||||
return evs, visibility, err
|
return evs, visibility, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixserverlib.HeaderedEvent) (types.RoomNID, map[string]types.Event) {
|
func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixserverlib.Event) (types.RoomNID, map[string]types.Event) {
|
||||||
var roomNID types.RoomNID
|
var roomNID types.RoomNID
|
||||||
var eventNID types.EventNID
|
var eventNID types.EventNID
|
||||||
backfilledEventMap := make(map[string]types.Event)
|
backfilledEventMap := make(map[string]types.Event)
|
||||||
@ -604,7 +607,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
roomInfo, err := db.GetOrCreateRoomInfo(ctx, ev.Unwrap())
|
roomInfo, err := db.GetOrCreateRoomInfo(ctx, ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to get or create roomNID")
|
logrus.WithError(err).Error("failed to get or create roomNID")
|
||||||
continue
|
continue
|
||||||
@ -623,7 +626,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
eventNID, _, err = db.StoreEvent(ctx, ev.Unwrap(), roomInfo, eventTypeNID, eventStateKeyNID, authNids, false)
|
eventNID, _, err = db.StoreEvent(ctx, ev, roomInfo, eventTypeNID, eventStateKeyNID, authNids, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to persist event")
|
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to persist event")
|
||||||
continue
|
continue
|
||||||
@ -631,7 +634,7 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||||||
|
|
||||||
resolver := state.NewStateResolution(db, roomInfo)
|
resolver := state.NewStateResolution(db, roomInfo)
|
||||||
|
|
||||||
_, redactedEvent, err := db.MaybeRedactEvent(ctx, roomInfo, eventNID, ev.Unwrap(), &resolver)
|
_, redactedEvent, err := db.MaybeRedactEvent(ctx, roomInfo, eventNID, ev, &resolver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to redact event")
|
logrus.WithError(err).WithField("event_id", ev.EventID()).Error("Failed to redact event")
|
||||||
continue
|
continue
|
||||||
@ -640,12 +643,12 @@ func persistEvents(ctx context.Context, db storage.Database, events []*gomatrixs
|
|||||||
// It's also possible for this event to be a redaction which results in another event being
|
// It's also possible for this event to be a redaction which results in another event being
|
||||||
// redacted, which we don't care about since we aren't returning it in this backfill.
|
// redacted, which we don't care about since we aren't returning it in this backfill.
|
||||||
if redactedEvent != nil && redactedEvent.EventID() == ev.EventID() {
|
if redactedEvent != nil && redactedEvent.EventID() == ev.EventID() {
|
||||||
ev = redactedEvent.Headered(ev.RoomVersion)
|
ev = redactedEvent
|
||||||
events[j] = ev
|
events[j] = ev
|
||||||
}
|
}
|
||||||
backfilledEventMap[ev.EventID()] = types.Event{
|
backfilledEventMap[ev.EventID()] = types.Event{
|
||||||
EventNID: eventNID,
|
EventNID: eventNID,
|
||||||
Event: ev.Unwrap(),
|
Event: ev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return roomNID, backfilledEventMap
|
return roomNID, backfilledEventMap
|
||||||
|
@ -76,7 +76,7 @@ func (r *InboundPeeker) PerformInboundPeek(
|
|||||||
sortedLatestEvents,
|
sortedLatestEvents,
|
||||||
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
||||||
)
|
)
|
||||||
response.LatestEvent = sortedLatestEvents[0].Headered(info.RoomVersion)
|
response.LatestEvent = &types.HeaderedEvent{Event: sortedLatestEvents[0]}
|
||||||
|
|
||||||
// XXX: do we actually need to do a state resolution here?
|
// XXX: do we actually need to do a state resolution here?
|
||||||
roomState := state.NewStateResolution(r.DB, info)
|
roomState := state.NewStateResolution(r.DB, info)
|
||||||
@ -106,11 +106,11 @@ func (r *InboundPeeker) PerformInboundPeek(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, event.Headered(info.RoomVersion))
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, event.Headered(info.RoomVersion))
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.Inputer.OutputProducer.ProduceRoomEvents(request.RoomID, []api.OutputEvent{
|
err = r.Inputer.OutputProducer.ProduceRoomEvents(request.RoomID, []api.OutputEvent{
|
||||||
|
@ -119,8 +119,8 @@ func (r *Inviter) PerformInvite(
|
|||||||
}
|
}
|
||||||
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
outputUpdates, err = helpers.UpdateToInviteMembership(updater, &types.Event{
|
||||||
EventNID: 0,
|
EventNID: 0,
|
||||||
Event: event.Unwrap(),
|
Event: event.Event,
|
||||||
}, outputUpdates, req.Event.RoomVersion)
|
}, outputUpdates, req.Event.Version())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("updateToInviteMembership: %w", err)
|
return nil, fmt.Errorf("updateToInviteMembership: %w", err)
|
||||||
}
|
}
|
||||||
@ -300,7 +300,7 @@ func buildInviteStrippedState(
|
|||||||
inviteState := []fclient.InviteV2StrippedState{
|
inviteState := []fclient.InviteV2StrippedState{
|
||||||
fclient.NewInviteV2StrippedState(input.Event.Event),
|
fclient.NewInviteV2StrippedState(input.Event.Event),
|
||||||
}
|
}
|
||||||
stateEvents = append(stateEvents, types.Event{Event: input.Event.Unwrap()})
|
stateEvents = append(stateEvents, types.Event{Event: input.Event.Event})
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
inviteState = append(inviteState, fclient.NewInviteV2StrippedState(event.Event))
|
inviteState = append(inviteState, fclient.NewInviteV2StrippedState(event.Event))
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
||||||
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -273,7 +274,7 @@ func (r *Joiner) performJoinRoomByID(
|
|||||||
|
|
||||||
// If a guest is trying to join a room, check that the room has a m.room.guest_access event
|
// If a guest is trying to join a room, check that the room has a m.room.guest_access event
|
||||||
if req.IsGuest {
|
if req.IsGuest {
|
||||||
var guestAccessEvent *gomatrixserverlib.HeaderedEvent
|
var guestAccessEvent *types.HeaderedEvent
|
||||||
guestAccess := "forbidden"
|
guestAccess := "forbidden"
|
||||||
guestAccessEvent, err = r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, spec.MRoomGuestAccess, "")
|
guestAccessEvent, err = r.DB.GetStateEvent(ctx, req.RoomIDOrAlias, spec.MRoomGuestAccess, "")
|
||||||
if (err != nil && !errors.Is(err, sql.ErrNoRows)) || guestAccessEvent == nil {
|
if (err != nil && !errors.Is(err, sql.ErrNoRows)) || guestAccessEvent == nil {
|
||||||
@ -334,7 +335,7 @@ func (r *Joiner) performJoinRoomByID(
|
|||||||
InputRoomEvents: []rsAPI.InputRoomEvent{
|
InputRoomEvents: []rsAPI.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: rsAPI.KindNew,
|
Kind: rsAPI.KindNew,
|
||||||
Event: event.Headered(buildRes.RoomVersion),
|
Event: event,
|
||||||
SendAsServer: string(userDomain),
|
SendAsServer: string(userDomain),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -196,7 +196,7 @@ func (r *Leaver) performLeaveRoomByID(
|
|||||||
InputRoomEvents: []api.InputRoomEvent{
|
InputRoomEvents: []api.InputRoomEvent{
|
||||||
{
|
{
|
||||||
Kind: api.KindNew,
|
Kind: api.KindNew,
|
||||||
Event: event.Headered(buildRes.RoomVersion),
|
Event: event,
|
||||||
Origin: senderDomain,
|
Origin: senderDomain,
|
||||||
SendAsServer: string(senderDomain),
|
SendAsServer: string(senderDomain),
|
||||||
},
|
},
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
@ -347,8 +348,8 @@ func (r *Upgrader) userIsAuthorized(ctx context.Context, userID, roomID string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.QueryLatestEventsAndStateResponse, userID, roomID, newVersion string, tombstoneEvent *gomatrixserverlib.HeaderedEvent) ([]fledglingEvent, *api.PerformError) {
|
func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.QueryLatestEventsAndStateResponse, userID, roomID, newVersion string, tombstoneEvent *types.HeaderedEvent) ([]fledglingEvent, *api.PerformError) {
|
||||||
state := make(map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent, len(oldRoom.StateEvents))
|
state := make(map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent, len(oldRoom.StateEvents))
|
||||||
for _, event := range oldRoom.StateEvents {
|
for _, event := range oldRoom.StateEvents {
|
||||||
if event.StateKey() == nil {
|
if event.StateKey() == nil {
|
||||||
// This shouldn't ever happen, but better to be safe than sorry.
|
// This shouldn't ever happen, but better to be safe than sorry.
|
||||||
@ -507,7 +508,7 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
|
|||||||
|
|
||||||
func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, userID string, userDomain spec.ServerName, newRoomID, newVersion string, eventsToMake []fledglingEvent) *api.PerformError {
|
func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, userID string, userDomain spec.ServerName, newRoomID, newVersion string, eventsToMake []fledglingEvent) *api.PerformError {
|
||||||
var err error
|
var err error
|
||||||
var builtEvents []*gomatrixserverlib.HeaderedEvent
|
var builtEvents []*types.HeaderedEvent
|
||||||
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
for i, e := range eventsToMake {
|
for i, e := range eventsToMake {
|
||||||
depth := i + 1 // depth starts at 1
|
depth := i + 1 // depth starts at 1
|
||||||
@ -543,7 +544,7 @@ func (r *Upgrader) sendInitialEvents(ctx context.Context, evTime time.Time, user
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the event to the list of auth events
|
// Add the event to the list of auth events
|
||||||
builtEvents = append(builtEvents, event.Headered(gomatrixserverlib.RoomVersion(newVersion)))
|
builtEvents = append(builtEvents, &types.HeaderedEvent{Event: event})
|
||||||
err = authEvents.AddEvent(event)
|
err = authEvents.AddEvent(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &api.PerformError{
|
return &api.PerformError{
|
||||||
@ -573,7 +574,7 @@ func (r *Upgrader) makeTombstoneEvent(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
evTime time.Time,
|
evTime time.Time,
|
||||||
userID, roomID, newRoomID string,
|
userID, roomID, newRoomID string,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, *api.PerformError) {
|
) (*types.HeaderedEvent, *api.PerformError) {
|
||||||
content := map[string]interface{}{
|
content := map[string]interface{}{
|
||||||
"body": "This room has been replaced",
|
"body": "This room has been replaced",
|
||||||
"replacement_room": newRoomID,
|
"replacement_room": newRoomID,
|
||||||
@ -585,7 +586,7 @@ func (r *Upgrader) makeTombstoneEvent(
|
|||||||
return r.makeHeaderedEvent(ctx, evTime, userID, roomID, event)
|
return r.makeHeaderedEvent(ctx, evTime, userID, roomID, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Upgrader) makeHeaderedEvent(ctx context.Context, evTime time.Time, userID, roomID string, event fledglingEvent) (*gomatrixserverlib.HeaderedEvent, *api.PerformError) {
|
func (r *Upgrader) makeHeaderedEvent(ctx context.Context, evTime time.Time, userID, roomID string, event fledglingEvent) (*types.HeaderedEvent, *api.PerformError) {
|
||||||
builder := gomatrixserverlib.EventBuilder{
|
builder := gomatrixserverlib.EventBuilder{
|
||||||
Sender: userID,
|
Sender: userID,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
@ -692,7 +693,7 @@ func createTemporaryPowerLevels(powerLevelContent *gomatrixserverlib.PowerLevelC
|
|||||||
func (r *Upgrader) sendHeaderedEvent(
|
func (r *Upgrader) sendHeaderedEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
serverName spec.ServerName,
|
serverName spec.ServerName,
|
||||||
headeredEvent *gomatrixserverlib.HeaderedEvent,
|
headeredEvent *types.HeaderedEvent,
|
||||||
sendAsServer string,
|
sendAsServer string,
|
||||||
) *api.PerformError {
|
) *api.PerformError {
|
||||||
var inputs []api.InputRoomEvent
|
var inputs []api.InputRoomEvent
|
||||||
|
@ -128,7 +128,7 @@ func (r *Queryer) QueryStateAfterEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, event.Headered(info.RoomVersion))
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -173,7 +173,7 @@ func (r *Queryer) QueryEventsByID(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
response.Events = append(response.Events, event.Headered(roomInfo.RoomVersion))
|
response.Events = append(response.Events, &types.HeaderedEvent{Event: event.Event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -231,7 +231,7 @@ func (r *Queryer) QueryMembershipAtEvent(
|
|||||||
request *api.QueryMembershipAtEventRequest,
|
request *api.QueryMembershipAtEventRequest,
|
||||||
response *api.QueryMembershipAtEventResponse,
|
response *api.QueryMembershipAtEventResponse,
|
||||||
) error {
|
) error {
|
||||||
response.Membership = make(map[string]*gomatrixserverlib.HeaderedEvent)
|
response.Membership = make(map[string]*types.HeaderedEvent)
|
||||||
|
|
||||||
info, err := r.DB.RoomInfo(ctx, request.RoomID)
|
info, err := r.DB.RoomInfo(ctx, request.RoomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -259,7 +259,7 @@ func (r *Queryer) QueryMembershipAtEvent(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Membership = make(map[string]*gomatrixserverlib.HeaderedEvent)
|
response.Membership = make(map[string]*types.HeaderedEvent)
|
||||||
stateEntries, err := helpers.MembershipAtEvent(ctx, r.DB, nil, request.EventIDs, stateKeyNIDs[request.UserID])
|
stateEntries, err := helpers.MembershipAtEvent(ctx, r.DB, nil, request.EventIDs, stateKeyNIDs[request.UserID])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get state before event: %w", err)
|
return fmt.Errorf("unable to get state before event: %w", err)
|
||||||
@ -307,7 +307,7 @@ func (r *Queryer) QueryMembershipAtEvent(
|
|||||||
for i := range memberships {
|
for i := range memberships {
|
||||||
ev := memberships[i]
|
ev := memberships[i]
|
||||||
if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(request.UserID) {
|
if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(request.UserID) {
|
||||||
response.Membership[eventID] = ev.Event.Headered(info.RoomVersion)
|
response.Membership[eventID] = &types.HeaderedEvent{Event: ev.Event}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -518,13 +518,13 @@ func (r *Queryer) QueryMissingEvents(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Events = make([]*gomatrixserverlib.HeaderedEvent, 0, len(loadedEvents)-len(eventsToFilter))
|
response.Events = make([]*types.HeaderedEvent, 0, len(loadedEvents)-len(eventsToFilter))
|
||||||
for _, event := range loadedEvents {
|
for _, event := range loadedEvents {
|
||||||
if !eventsToFilter[event.EventID()] {
|
if !eventsToFilter[event.EventID()] {
|
||||||
if _, ok := redactEventIDs[event.EventID()]; ok {
|
if _, ok := redactEventIDs[event.EventID()]; ok {
|
||||||
event.Redact()
|
event.Redact()
|
||||||
}
|
}
|
||||||
response.Events = append(response.Events, event.Headered(info.RoomVersion))
|
response.Events = append(response.Events, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ func (r *Queryer) QueryStateAndAuthChain(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, event.Headered(info.RoomVersion))
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -593,11 +593,11 @@ func (r *Queryer) QueryStateAndAuthChain(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
response.StateEvents = append(response.StateEvents, event.Headered(info.RoomVersion))
|
response.StateEvents = append(response.StateEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, event := range authEvents {
|
for _, event := range authEvents {
|
||||||
response.AuthChainEvents = append(response.AuthChainEvents, event.Headered(info.RoomVersion))
|
response.AuthChainEvents = append(response.AuthChainEvents, &types.HeaderedEvent{Event: event})
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -730,7 +730,7 @@ func (r *Queryer) QueryPublishedRooms(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Queryer) QueryCurrentState(ctx context.Context, req *api.QueryCurrentStateRequest, res *api.QueryCurrentStateResponse) error {
|
func (r *Queryer) QueryCurrentState(ctx context.Context, req *api.QueryCurrentStateRequest, res *api.QueryCurrentStateResponse) error {
|
||||||
res.StateEvents = make(map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent)
|
res.StateEvents = make(map[gomatrixserverlib.StateKeyTuple]*types.HeaderedEvent)
|
||||||
for _, tuple := range req.StateTuples {
|
for _, tuple := range req.StateTuples {
|
||||||
if tuple.StateKey == "*" && req.AllowWildcards {
|
if tuple.StateKey == "*" && req.AllowWildcards {
|
||||||
events, err := r.DB.GetStateEventsWithEventType(ctx, req.RoomID, tuple.EventType)
|
events, err := r.DB.GetStateEventsWithEventType(ctx, req.RoomID, tuple.EventType)
|
||||||
@ -847,9 +847,9 @@ func (r *Queryer) QueryAuthChain(ctx context.Context, req *api.QueryAuthChainReq
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
hchain := make([]*gomatrixserverlib.HeaderedEvent, len(chain))
|
hchain := make([]*types.HeaderedEvent, len(chain))
|
||||||
for i := range chain {
|
for i := range chain {
|
||||||
hchain[i] = chain[i].Headered(chain[i].Version())
|
hchain[i] = &types.HeaderedEvent{Event: chain[i]}
|
||||||
}
|
}
|
||||||
res.AuthChain = hchain
|
res.AuthChain = hchain
|
||||||
return nil
|
return nil
|
||||||
|
@ -74,7 +74,7 @@ func (r *RoomEventProducer) ProduceRoomEvents(roomID string, updates []api.Outpu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if eventType == "m.room.server_acl" && update.NewRoomEvent.Event.StateKeyEquals("") {
|
if eventType == "m.room.server_acl" && update.NewRoomEvent.Event.StateKeyEquals("") {
|
||||||
ev := update.NewRoomEvent.Event.Unwrap()
|
ev := update.NewRoomEvent.Event.Event
|
||||||
defer r.ACLs.OnServerACLUpdate(ev)
|
defer r.ACLs.OnServerACLUpdate(ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ func testKickUsers(t *testing.T, rsAPI api.RoomserverInternalAPI, usrAPI userAPI
|
|||||||
|
|
||||||
// revoke guest access
|
// revoke guest access
|
||||||
revokeEvent := room.CreateAndInsert(t, alice, spec.MRoomGuestAccess, map[string]string{"guest_access": "forbidden"}, test.WithStateKey(""))
|
revokeEvent := room.CreateAndInsert(t, alice, spec.MRoomGuestAccess, map[string]string{"guest_access": "forbidden"}, test.WithStateKey(""))
|
||||||
if err := api.SendEvents(ctx, rsAPI, api.KindNew, []*gomatrixserverlib.HeaderedEvent{revokeEvent}, "test", "test", "test", nil, false); err != nil {
|
if err := api.SendEvents(ctx, rsAPI, api.KindNew, []*types.HeaderedEvent{revokeEvent}, "test", "test", "test", nil, false); err != nil {
|
||||||
t.Errorf("failed to send events: %v", err)
|
t.Errorf("failed to send events: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ type fledglingEvent struct {
|
|||||||
PrevEvents []interface{}
|
PrevEvents []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib.HeaderedEvent) {
|
func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *types.HeaderedEvent) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
roomVer := gomatrixserverlib.RoomVersionV9
|
roomVer := gomatrixserverlib.RoomVersionV9
|
||||||
seed := make([]byte, ed25519.SeedSize) // zero seed
|
seed := make([]byte, ed25519.SeedSize) // zero seed
|
||||||
@ -426,7 +426,7 @@ func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
||||||
}
|
}
|
||||||
h := signedEvent.Headered(roomVer)
|
h := &types.HeaderedEvent{Event: signedEvent}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
Depth: redactedEvent.Depth() + 1,
|
Depth: redactedEvent.Depth() + 1,
|
||||||
PrevEvents: []interface{}{redactedEvent.EventID()},
|
PrevEvents: []interface{}{redactedEvent.EventID()},
|
||||||
})
|
})
|
||||||
room.InsertEvent(t, builderEv.Headered(gomatrixserverlib.RoomVersionV9))
|
room.InsertEvent(t, builderEv)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -471,7 +471,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
Depth: redactedEvent.Depth() + 1,
|
Depth: redactedEvent.Depth() + 1,
|
||||||
PrevEvents: []interface{}{redactedEvent.EventID()},
|
PrevEvents: []interface{}{redactedEvent.EventID()},
|
||||||
})
|
})
|
||||||
room.InsertEvent(t, builderEv.Headered(gomatrixserverlib.RoomVersionV9))
|
room.InsertEvent(t, builderEv)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -488,7 +488,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
Depth: redactedEvent.Depth() + 1,
|
Depth: redactedEvent.Depth() + 1,
|
||||||
PrevEvents: []interface{}{redactedEvent.EventID()},
|
PrevEvents: []interface{}{redactedEvent.EventID()},
|
||||||
})
|
})
|
||||||
room.InsertEvent(t, builderEv.Headered(gomatrixserverlib.RoomVersionV9))
|
room.InsertEvent(t, builderEv)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -504,7 +504,7 @@ func TestRedaction(t *testing.T) {
|
|||||||
Depth: redactedEvent.Depth() + 1,
|
Depth: redactedEvent.Depth() + 1,
|
||||||
PrevEvents: []interface{}{redactedEvent.EventID()},
|
PrevEvents: []interface{}{redactedEvent.EventID()},
|
||||||
})
|
})
|
||||||
room.InsertEvent(t, builderEv.Headered(gomatrixserverlib.RoomVersionV9))
|
room.InsertEvent(t, builderEv)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,8 @@ type Database interface {
|
|||||||
// GetStateEvent returns the state event of a given type for a given room with a given state key
|
// GetStateEvent returns the state event of a given type for a given room with a given state key
|
||||||
// If no event could be found, returns nil
|
// If no event could be found, returns nil
|
||||||
// If there was an issue during the retrieval, returns an error
|
// If there was an issue during the retrieval, returns an error
|
||||||
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error)
|
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*types.HeaderedEvent, error)
|
||||||
GetStateEventsWithEventType(ctx context.Context, roomID, evType string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
GetStateEventsWithEventType(ctx context.Context, roomID, evType string) ([]*types.HeaderedEvent, error)
|
||||||
// GetRoomsByMembership returns a list of room IDs matching the provided membership and user ID (as state_key).
|
// GetRoomsByMembership returns a list of room IDs matching the provided membership and user ID (as state_key).
|
||||||
GetRoomsByMembership(ctx context.Context, userID, membership string) ([]string, error)
|
GetRoomsByMembership(ctx context.Context, userID, membership string) ([]string, error)
|
||||||
// GetBulkStateContent returns all state events which match a given room ID and a given state key tuple. Both must be satisfied for a match.
|
// GetBulkStateContent returns all state events which match a given room ID and a given state key tuple. Both must be satisfied for a match.
|
||||||
@ -181,7 +181,7 @@ type Database interface {
|
|||||||
// a membership of "leave" when calculating history visibility.
|
// a membership of "leave" when calculating history visibility.
|
||||||
GetMembershipForHistoryVisibility(
|
GetMembershipForHistoryVisibility(
|
||||||
ctx context.Context, userNID types.EventStateKeyNID, info *types.RoomInfo, eventIDs ...string,
|
ctx context.Context, userNID types.EventStateKeyNID, info *types.RoomInfo, eventIDs ...string,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, error)
|
) (map[string]*types.HeaderedEvent, error)
|
||||||
GetOrCreateRoomInfo(ctx context.Context, event *gomatrixserverlib.Event) (*types.RoomInfo, error)
|
GetOrCreateRoomInfo(ctx context.Context, event *gomatrixserverlib.Event) (*types.RoomInfo, error)
|
||||||
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
||||||
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
||||||
@ -210,7 +210,7 @@ type RoomDatabase interface {
|
|||||||
GetOrCreateRoomInfo(ctx context.Context, event *gomatrixserverlib.Event) (*types.RoomInfo, error)
|
GetOrCreateRoomInfo(ctx context.Context, event *gomatrixserverlib.Event) (*types.RoomInfo, error)
|
||||||
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
GetOrCreateEventTypeNID(ctx context.Context, eventType string) (eventTypeNID types.EventTypeNID, err error)
|
||||||
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
GetOrCreateEventStateKeyNID(ctx context.Context, eventStateKey *string) (types.EventStateKeyNID, error)
|
||||||
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error)
|
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*types.HeaderedEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventDatabase interface {
|
type EventDatabase interface {
|
||||||
|
@ -205,19 +205,19 @@ func (s *stateSnapshotStatements) BulkSelectStateForHistoryVisibility(
|
|||||||
|
|
||||||
func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
|
func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
|
||||||
ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, error) {
|
) (map[string]*types.HeaderedEvent, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.bulktSelectMembershipForHistoryVisibilityStmt)
|
stmt := sqlutil.TxStmt(txn, s.bulktSelectMembershipForHistoryVisibilityStmt)
|
||||||
rows, err := stmt.QueryContext(ctx, userNID, pq.Array(eventIDs), roomInfo.RoomNID)
|
rows, err := stmt.QueryContext(ctx, userNID, pq.Array(eventIDs), roomInfo.RoomNID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close() // nolint: errcheck
|
defer rows.Close() // nolint: errcheck
|
||||||
result := make(map[string]*gomatrixserverlib.HeaderedEvent, len(eventIDs))
|
result := make(map[string]*types.HeaderedEvent, len(eventIDs))
|
||||||
var evJson []byte
|
var evJson []byte
|
||||||
var eventID string
|
var eventID string
|
||||||
var membershipEventID string
|
var membershipEventID string
|
||||||
|
|
||||||
knownEvents := make(map[string]*gomatrixserverlib.HeaderedEvent, len(eventIDs))
|
knownEvents := make(map[string]*types.HeaderedEvent, len(eventIDs))
|
||||||
verImpl, err := gomatrixserverlib.GetRoomVersion(roomInfo.RoomVersion)
|
verImpl, err := gomatrixserverlib.GetRoomVersion(roomInfo.RoomVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -228,7 +228,7 @@ func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(evJson) == 0 {
|
if len(evJson) == 0 {
|
||||||
result[eventID] = &gomatrixserverlib.HeaderedEvent{}
|
result[eventID] = &types.HeaderedEvent{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// If we already know this event, don't try to marshal the json again
|
// If we already know this event, don't try to marshal the json again
|
||||||
@ -238,11 +238,11 @@ func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(
|
|||||||
}
|
}
|
||||||
event, err := verImpl.NewEventFromTrustedJSON(evJson, false)
|
event, err := verImpl.NewEventFromTrustedJSON(evJson, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result[eventID] = &gomatrixserverlib.HeaderedEvent{}
|
result[eventID] = &types.HeaderedEvent{}
|
||||||
// not fatal
|
// not fatal
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
he := event.Headered(roomInfo.RoomVersion)
|
he := &types.HeaderedEvent{Event: event}
|
||||||
result[eventID] = he
|
result[eventID] = he
|
||||||
knownEvents[membershipEventID] = he
|
knownEvents[membershipEventID] = he
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (d *Database) SupportsConcurrentRoomInputs() bool {
|
|||||||
|
|
||||||
func (d *Database) GetMembershipForHistoryVisibility(
|
func (d *Database) GetMembershipForHistoryVisibility(
|
||||||
ctx context.Context, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
ctx context.Context, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, error) {
|
) (map[string]*types.HeaderedEvent, error) {
|
||||||
return d.StateSnapshotTable.BulkSelectMembershipForHistoryVisibility(ctx, nil, userNID, roomInfo, eventIDs...)
|
return d.StateSnapshotTable.BulkSelectMembershipForHistoryVisibility(ctx, nil, userNID, roomInfo, eventIDs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1156,7 +1156,7 @@ func (d *Database) GetHistoryVisibilityState(ctx context.Context, roomInfo *type
|
|||||||
// GetStateEvent returns the current state event of a given type for a given room with a given state key
|
// GetStateEvent returns the current state event of a given type for a given room with a given state key
|
||||||
// If no event could be found, returns nil
|
// If no event could be found, returns nil
|
||||||
// If there was an issue during the retrieval, returns an error
|
// If there was an issue during the retrieval, returns an error
|
||||||
func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*types.HeaderedEvent, error) {
|
||||||
roomInfo, err := d.roomInfo(ctx, nil, roomID)
|
roomInfo, err := d.roomInfo(ctx, nil, roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1207,7 +1207,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
|
|||||||
if e.EventTypeNID == eventTypeNID && e.EventStateKeyNID == stateKeyNID {
|
if e.EventTypeNID == eventTypeNID && e.EventStateKeyNID == stateKeyNID {
|
||||||
cachedEvent, ok := d.Cache.GetRoomServerEvent(e.EventNID)
|
cachedEvent, ok := d.Cache.GetRoomServerEvent(e.EventNID)
|
||||||
if ok {
|
if ok {
|
||||||
return cachedEvent.Headered(roomInfo.RoomVersion), nil
|
return &types.HeaderedEvent{Event: cachedEvent}, nil
|
||||||
}
|
}
|
||||||
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{e.EventNID})
|
data, err := d.EventJSONTable.BulkSelectEventJSON(ctx, nil, []types.EventNID{e.EventNID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1220,7 +1220,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ev.Headered(roomInfo.RoomVersion), nil
|
return &types.HeaderedEvent{Event: ev}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1229,7 +1229,7 @@ func (d *Database) GetStateEvent(ctx context.Context, roomID, evType, stateKey s
|
|||||||
|
|
||||||
// Same as GetStateEvent but returns all matching state events with this event type. Returns no error
|
// Same as GetStateEvent but returns all matching state events with this event type. Returns no error
|
||||||
// if there are no events with this event type.
|
// if there are no events with this event type.
|
||||||
func (d *Database) GetStateEventsWithEventType(ctx context.Context, roomID, evType string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) GetStateEventsWithEventType(ctx context.Context, roomID, evType string) ([]*types.HeaderedEvent, error) {
|
||||||
roomInfo, err := d.roomInfo(ctx, nil, roomID)
|
roomInfo, err := d.roomInfo(ctx, nil, roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1275,13 +1275,13 @@ func (d *Database) GetStateEventsWithEventType(ctx context.Context, roomID, evTy
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var result []*gomatrixserverlib.HeaderedEvent
|
var result []*types.HeaderedEvent
|
||||||
for _, pair := range eventPairs {
|
for _, pair := range eventPairs {
|
||||||
ev, err := verImpl.NewEventFromTrustedJSONWithEventID(eventIDs[pair.EventNID], pair.EventJSON, false)
|
ev, err := verImpl.NewEventFromTrustedJSONWithEventID(eventIDs[pair.EventNID], pair.EventJSON, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, ev.Headered(roomInfo.RoomVersion))
|
result = append(result, &types.HeaderedEvent{Event: ev})
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
@ -1409,7 +1409,7 @@ func (d *Database) GetBulkStateContent(ctx context.Context, roomIDs []string, tu
|
|||||||
EventType: ev.Type(),
|
EventType: ev.Type(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID(),
|
||||||
StateKey: *ev.StateKey(),
|
StateKey: *ev.StateKey(),
|
||||||
ContentValue: tables.ExtractContentValue(ev.Headered(roomVer)),
|
ContentValue: tables.ExtractContentValue(&types.HeaderedEvent{Event: ev}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -153,7 +152,7 @@ func (s *stateSnapshotStatements) BulkSelectStateForHistoryVisibility(
|
|||||||
return nil, tables.OptimisationNotSupportedError
|
return nil, tables.OptimisationNotSupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string) (map[string]*gomatrixserverlib.HeaderedEvent, error) {
|
func (s *stateSnapshotStatements) BulkSelectMembershipForHistoryVisibility(ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string) (map[string]*types.HeaderedEvent, error) {
|
||||||
return nil, tables.OptimisationNotSupportedError
|
return nil, tables.OptimisationNotSupportedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ type StateSnapshot interface {
|
|||||||
|
|
||||||
BulkSelectMembershipForHistoryVisibility(
|
BulkSelectMembershipForHistoryVisibility(
|
||||||
ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomInfo *types.RoomInfo, eventIDs ...string,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, error)
|
) (map[string]*types.HeaderedEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type StateBlock interface {
|
type StateBlock interface {
|
||||||
@ -196,7 +196,7 @@ type StrippedEvent struct {
|
|||||||
// ExtractContentValue from the given state event. For example, given an m.room.name event with:
|
// ExtractContentValue from the given state event. For example, given an m.room.name event with:
|
||||||
// content: { name: "Foo" }
|
// content: { name: "Foo" }
|
||||||
// this returns "Foo".
|
// this returns "Foo".
|
||||||
func ExtractContentValue(ev *gomatrixserverlib.HeaderedEvent) string {
|
func ExtractContentValue(ev *types.HeaderedEvent) string {
|
||||||
content := ev.Content()
|
content := ev.Content()
|
||||||
key := ""
|
key := ""
|
||||||
switch ev.Type() {
|
switch ev.Type() {
|
||||||
|
47
roomserver/types/headered_event.go
Normal file
47
roomserver/types/headered_event.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2023 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 types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HeaderedEvent is an Event which serialises to the headered form, which includes
|
||||||
|
// _room_version and _event_id fields.
|
||||||
|
type HeaderedEvent struct {
|
||||||
|
*gomatrixserverlib.Event
|
||||||
|
Visibility gomatrixserverlib.HistoryVisibility
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *HeaderedEvent) MarshalJSON() ([]byte, error) {
|
||||||
|
return h.Event.ToHeaderedJSON()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *HeaderedEvent) UnmarshalJSON(data []byte) error {
|
||||||
|
ev, err := gomatrixserverlib.NewEventFromHeaderedJSON(data, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
j.Event = ev
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEventJSONsFromHeaderedEvents(hes []*HeaderedEvent) gomatrixserverlib.EventJSONs {
|
||||||
|
result := make(gomatrixserverlib.EventJSONs, len(hes))
|
||||||
|
for i := range hes {
|
||||||
|
result[i] = hes[i].JSON()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
@ -112,7 +113,7 @@ func Enable(
|
|||||||
}
|
}
|
||||||
hooks.Enable()
|
hooks.Enable()
|
||||||
hooks.Attach(hooks.KindNewEventPersisted, func(headeredEvent interface{}) {
|
hooks.Attach(hooks.KindNewEventPersisted, func(headeredEvent interface{}) {
|
||||||
he := headeredEvent.(*gomatrixserverlib.HeaderedEvent)
|
he := headeredEvent.(*types.HeaderedEvent)
|
||||||
hookErr := db.StoreRelation(context.Background(), he)
|
hookErr := db.StoreRelation(context.Background(), he)
|
||||||
if hookErr != nil {
|
if hookErr != nil {
|
||||||
util.GetLogger(context.Background()).WithError(hookErr).WithField("event_id", he.EventID()).Error(
|
util.GetLogger(context.Background()).WithError(hookErr).WithField("event_id", he.EventID()).Error(
|
||||||
@ -255,7 +256,7 @@ func federatedEventRelationship(
|
|||||||
|
|
||||||
func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONResponse) {
|
func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONResponse) {
|
||||||
var res MSC2836EventRelationshipsResponse
|
var res MSC2836EventRelationshipsResponse
|
||||||
var returnEvents []*gomatrixserverlib.HeaderedEvent
|
var returnEvents []*types.HeaderedEvent
|
||||||
// Can the user see (according to history visibility) event_id? If no, reject the request, else continue.
|
// Can the user see (according to history visibility) event_id? If no, reject the request, else continue.
|
||||||
event := rc.getLocalEvent(rc.req.RoomID, rc.req.EventID)
|
event := rc.getLocalEvent(rc.req.RoomID, rc.req.EventID)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
@ -299,7 +300,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
|
|||||||
for _, ev := range returnEvents {
|
for _, ev := range returnEvents {
|
||||||
included[ev.EventID()] = true
|
included[ev.EventID()] = true
|
||||||
}
|
}
|
||||||
var events []*gomatrixserverlib.HeaderedEvent
|
var events []*types.HeaderedEvent
|
||||||
events, walkLimited = walkThread(
|
events, walkLimited = walkThread(
|
||||||
rc.ctx, rc.db, rc, included, remaining,
|
rc.ctx, rc.db, rc, included, remaining,
|
||||||
)
|
)
|
||||||
@ -309,7 +310,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
|
|||||||
for i, ev := range returnEvents {
|
for i, ev := range returnEvents {
|
||||||
// for each event, extract the children_count | hash and add it as unsigned data.
|
// for each event, extract the children_count | hash and add it as unsigned data.
|
||||||
rc.addChildMetadata(ev)
|
rc.addChildMetadata(ev)
|
||||||
res.ParsedEvents[i] = ev.Unwrap()
|
res.ParsedEvents[i] = ev.Event
|
||||||
}
|
}
|
||||||
res.Limited = remaining == 0 || walkLimited
|
res.Limited = remaining == 0 || walkLimited
|
||||||
return &res, nil
|
return &res, nil
|
||||||
@ -318,7 +319,7 @@ func (rc *reqCtx) process() (*MSC2836EventRelationshipsResponse, *util.JSONRespo
|
|||||||
// fetchUnknownEvent retrieves an unknown event from the room specified. This server must
|
// fetchUnknownEvent retrieves an unknown event from the room specified. This server must
|
||||||
// be joined to the room in question. This has the side effect of injecting surround threaded
|
// be joined to the room in question. This has the side effect of injecting surround threaded
|
||||||
// events into the roomserver.
|
// events into the roomserver.
|
||||||
func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.HeaderedEvent {
|
func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *types.HeaderedEvent {
|
||||||
if rc.isFederatedRequest || roomID == "" {
|
if rc.isFederatedRequest || roomID == "" {
|
||||||
// we don't do fed hits for fed requests, and we can't ask servers without a room ID!
|
// we don't do fed hits for fed requests, and we can't ask servers without a room ID!
|
||||||
return nil
|
return nil
|
||||||
@ -372,7 +373,7 @@ func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.H
|
|||||||
rc.injectResponseToRoomserver(res)
|
rc.injectResponseToRoomserver(res)
|
||||||
for _, ev := range res.ParsedEvents {
|
for _, ev := range res.ParsedEvents {
|
||||||
if ev.EventID() == eventID {
|
if ev.EventID() == eventID {
|
||||||
return ev.Headered(ev.Version())
|
return &types.HeaderedEvent{Event: ev}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,7 +383,7 @@ func (rc *reqCtx) fetchUnknownEvent(eventID, roomID string) *gomatrixserverlib.H
|
|||||||
|
|
||||||
// If include_parent: true and there is a valid m.relationship field in the event,
|
// If include_parent: true and there is a valid m.relationship field in the event,
|
||||||
// retrieve the referenced event. Apply history visibility check to that event and if it passes, add it to the response array.
|
// retrieve the referenced event. Apply history visibility check to that event and if it passes, add it to the response array.
|
||||||
func (rc *reqCtx) includeParent(childEvent *gomatrixserverlib.HeaderedEvent) (parent *gomatrixserverlib.HeaderedEvent) {
|
func (rc *reqCtx) includeParent(childEvent *types.HeaderedEvent) (parent *types.HeaderedEvent) {
|
||||||
parentID, _, _ := parentChildEventIDs(childEvent)
|
parentID, _, _ := parentChildEventIDs(childEvent)
|
||||||
if parentID == "" {
|
if parentID == "" {
|
||||||
return nil
|
return nil
|
||||||
@ -393,7 +394,7 @@ func (rc *reqCtx) includeParent(childEvent *gomatrixserverlib.HeaderedEvent) (pa
|
|||||||
// If include_children: true, lookup all events which have event_id as an m.relationship
|
// If include_children: true, lookup all events which have event_id as an m.relationship
|
||||||
// Apply history visibility checks to all these events and add the ones which pass into the response array,
|
// Apply history visibility checks to all these events and add the ones which pass into the response array,
|
||||||
// honouring the recent_first flag and the limit.
|
// honouring the recent_first flag and the limit.
|
||||||
func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recentFirst bool) ([]*gomatrixserverlib.HeaderedEvent, *util.JSONResponse) {
|
func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recentFirst bool) ([]*types.HeaderedEvent, *util.JSONResponse) {
|
||||||
if rc.hasUnexploredChildren(parentID) {
|
if rc.hasUnexploredChildren(parentID) {
|
||||||
// we need to do a remote request to pull in the children as we are missing them locally.
|
// we need to do a remote request to pull in the children as we are missing them locally.
|
||||||
serversToQuery := rc.getServersForEventID(parentID)
|
serversToQuery := rc.getServersForEventID(parentID)
|
||||||
@ -430,7 +431,7 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
|
|||||||
resErr := jsonerror.InternalServerError()
|
resErr := jsonerror.InternalServerError()
|
||||||
return nil, &resErr
|
return nil, &resErr
|
||||||
}
|
}
|
||||||
var childEvents []*gomatrixserverlib.HeaderedEvent
|
var childEvents []*types.HeaderedEvent
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
childEvent := rc.lookForEvent(child.EventID)
|
childEvent := rc.lookForEvent(child.EventID)
|
||||||
if childEvent != nil {
|
if childEvent != nil {
|
||||||
@ -447,8 +448,8 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
|
|||||||
// honouring the limit, max_depth and max_breadth values according to the following rules
|
// honouring the limit, max_depth and max_breadth values according to the following rules
|
||||||
func walkThread(
|
func walkThread(
|
||||||
ctx context.Context, db Database, rc *reqCtx, included map[string]bool, limit int,
|
ctx context.Context, db Database, rc *reqCtx, included map[string]bool, limit int,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, bool) {
|
) ([]*types.HeaderedEvent, bool) {
|
||||||
var result []*gomatrixserverlib.HeaderedEvent
|
var result []*types.HeaderedEvent
|
||||||
eventWalker := walker{
|
eventWalker := walker{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
req: rc.req,
|
req: rc.req,
|
||||||
@ -510,7 +511,7 @@ func (rc *reqCtx) MSC2836EventRelationships(eventID string, srv spec.ServerName,
|
|||||||
|
|
||||||
// authorisedToSeeEvent checks that the user or server is allowed to see this event. Returns true if allowed to
|
// authorisedToSeeEvent checks that the user or server is allowed to see this event. Returns true if allowed to
|
||||||
// see this request. This only needs to be done once per room at present as we just check for joined status.
|
// see this request. This only needs to be done once per room at present as we just check for joined status.
|
||||||
func (rc *reqCtx) authorisedToSeeEvent(event *gomatrixserverlib.HeaderedEvent) bool {
|
func (rc *reqCtx) authorisedToSeeEvent(event *types.HeaderedEvent) bool {
|
||||||
if rc.isFederatedRequest {
|
if rc.isFederatedRequest {
|
||||||
// make sure the server is in this room
|
// make sure the server is in this room
|
||||||
var res fs.QueryJoinedHostServerNamesInRoomResponse
|
var res fs.QueryJoinedHostServerNamesInRoomResponse
|
||||||
@ -593,7 +594,7 @@ func (rc *reqCtx) remoteEventRelationships(eventID string) *MSC2836EventRelation
|
|||||||
|
|
||||||
// lookForEvent returns the event for the event ID given, by trying to query remote servers
|
// lookForEvent returns the event for the event ID given, by trying to query remote servers
|
||||||
// if the event ID is unknown via /event_relationships.
|
// if the event ID is unknown via /event_relationships.
|
||||||
func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent {
|
func (rc *reqCtx) lookForEvent(eventID string) *types.HeaderedEvent {
|
||||||
event := rc.getLocalEvent(rc.req.RoomID, eventID)
|
event := rc.getLocalEvent(rc.req.RoomID, eventID)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
queryRes := rc.remoteEventRelationships(eventID)
|
queryRes := rc.remoteEventRelationships(eventID)
|
||||||
@ -602,7 +603,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent
|
|||||||
rc.injectResponseToRoomserver(queryRes)
|
rc.injectResponseToRoomserver(queryRes)
|
||||||
for _, ev := range queryRes.ParsedEvents {
|
for _, ev := range queryRes.ParsedEvents {
|
||||||
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
|
if ev.EventID() == eventID && rc.req.RoomID == ev.RoomID() {
|
||||||
return ev.Headered(ev.Version())
|
return &types.HeaderedEvent{Event: ev}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -624,7 +625,7 @@ func (rc *reqCtx) lookForEvent(eventID string) *gomatrixserverlib.HeaderedEvent
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reqCtx) getLocalEvent(roomID, eventID string) *gomatrixserverlib.HeaderedEvent {
|
func (rc *reqCtx) getLocalEvent(roomID, eventID string) *types.HeaderedEvent {
|
||||||
var queryEventsRes roomserver.QueryEventsByIDResponse
|
var queryEventsRes roomserver.QueryEventsByIDResponse
|
||||||
err := rc.rsAPI.QueryEventsByID(rc.ctx, &roomserver.QueryEventsByIDRequest{
|
err := rc.rsAPI.QueryEventsByID(rc.ctx, &roomserver.QueryEventsByIDRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
@ -664,7 +665,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
|
|||||||
for _, outlier := range append(eventsInOrder, messageEvents...) {
|
for _, outlier := range append(eventsInOrder, messageEvents...) {
|
||||||
ires = append(ires, roomserver.InputRoomEvent{
|
ires = append(ires, roomserver.InputRoomEvent{
|
||||||
Kind: roomserver.KindOutlier,
|
Kind: roomserver.KindOutlier,
|
||||||
Event: outlier.Headered(outlier.Version()),
|
Event: &types.HeaderedEvent{Event: outlier},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// we've got the data by this point so use a background context
|
// we've got the data by this point so use a background context
|
||||||
@ -683,7 +684,7 @@ func (rc *reqCtx) injectResponseToRoomserver(res *MSC2836EventRelationshipsRespo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reqCtx) addChildMetadata(ev *gomatrixserverlib.HeaderedEvent) {
|
func (rc *reqCtx) addChildMetadata(ev *types.HeaderedEvent) {
|
||||||
count, hash := rc.getChildMetadata(ev.EventID())
|
count, hash := rc.getChildMetadata(ev.EventID())
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
return
|
return
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
|
"github.com/matrix-org/dendrite/setup/mscs/msc2836"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
@ -171,7 +172,7 @@ func TestMSC2836(t *testing.T) {
|
|||||||
bob: {roomID},
|
bob: {roomID},
|
||||||
charlie: {roomID},
|
charlie: {roomID},
|
||||||
},
|
},
|
||||||
events: map[string]*gomatrixserverlib.HeaderedEvent{
|
events: map[string]*types.HeaderedEvent{
|
||||||
eventA.EventID(): eventA,
|
eventA.EventID(): eventA,
|
||||||
eventB.EventID(): eventB,
|
eventB.EventID(): eventB,
|
||||||
eventC.EventID(): eventC,
|
eventC.EventID(): eventC,
|
||||||
@ -182,7 +183,7 @@ func TestMSC2836(t *testing.T) {
|
|||||||
eventH.EventID(): eventH,
|
eventH.EventID(): eventH,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
router := injectEvents(t, nopUserAPI, nopRsAPI, []*gomatrixserverlib.HeaderedEvent{
|
router := injectEvents(t, nopUserAPI, nopRsAPI, []*types.HeaderedEvent{
|
||||||
eventA, eventB, eventC, eventD, eventE, eventF, eventG, eventH,
|
eventA, eventB, eventC, eventD, eventE, eventF, eventG, eventH,
|
||||||
})
|
})
|
||||||
cancel := runServer(t, router)
|
cancel := runServer(t, router)
|
||||||
@ -521,7 +522,7 @@ type testRoomserverAPI struct {
|
|||||||
// We'll override the functions we care about.
|
// We'll override the functions we care about.
|
||||||
roomserver.RoomserverInternalAPI
|
roomserver.RoomserverInternalAPI
|
||||||
userToJoinedRooms map[string][]string
|
userToJoinedRooms map[string][]string
|
||||||
events map[string]*gomatrixserverlib.HeaderedEvent
|
events map[string]*types.HeaderedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *testRoomserverAPI) QueryEventsByID(ctx context.Context, req *roomserver.QueryEventsByIDRequest, res *roomserver.QueryEventsByIDResponse) error {
|
func (r *testRoomserverAPI) QueryEventsByID(ctx context.Context, req *roomserver.QueryEventsByIDRequest, res *roomserver.QueryEventsByIDResponse) error {
|
||||||
@ -547,7 +548,7 @@ func (r *testRoomserverAPI) QueryMembershipForUser(ctx context.Context, req *roo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*gomatrixserverlib.HeaderedEvent) *mux.Router {
|
func injectEvents(t *testing.T, userAPI userapi.UserInternalAPI, rsAPI roomserver.RoomserverInternalAPI, events []*types.HeaderedEvent) *mux.Router {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
cfg := &config.Dendrite{}
|
cfg := &config.Dendrite{}
|
||||||
cfg.Defaults(config.DefaultOpts{
|
cfg.Defaults(config.DefaultOpts{
|
||||||
@ -579,7 +580,7 @@ type fledglingEvent struct {
|
|||||||
RoomID string
|
RoomID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib.HeaderedEvent) {
|
func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *types.HeaderedEvent) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
roomVer := gomatrixserverlib.RoomVersionV6
|
roomVer := gomatrixserverlib.RoomVersionV6
|
||||||
seed := make([]byte, ed25519.SeedSize) // zero seed
|
seed := make([]byte, ed25519.SeedSize) // zero seed
|
||||||
@ -601,6 +602,6 @@ func mustCreateEvent(t *testing.T, ev fledglingEvent) (result *gomatrixserverlib
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
t.Fatalf("mustCreateEvent: failed to sign event: %s", err)
|
||||||
}
|
}
|
||||||
h := signedEvent.Headered(roomVer)
|
h := &types.HeaderedEvent{Event: signedEvent}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
@ -23,7 +23,7 @@ type eventInfo struct {
|
|||||||
type Database interface {
|
type Database interface {
|
||||||
// StoreRelation stores the parent->child and child->parent relationship for later querying.
|
// StoreRelation stores the parent->child and child->parent relationship for later querying.
|
||||||
// Also stores the event metadata e.g timestamp
|
// Also stores the event metadata e.g timestamp
|
||||||
StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error
|
StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error
|
||||||
// ChildrenForParent returns the events who have the given `eventID` as an m.relationship with the
|
// ChildrenForParent returns the events who have the given `eventID` as an m.relationship with the
|
||||||
// provided `relType`. The returned slice is sorted by origin_server_ts according to whether
|
// provided `relType`. The returned slice is sorted by origin_server_ts according to whether
|
||||||
// `recentFirst` is true or false.
|
// `recentFirst` is true or false.
|
||||||
@ -35,7 +35,7 @@ type Database interface {
|
|||||||
// UpdateChildMetadata persists the children_count and children_hash from this event if and only if
|
// UpdateChildMetadata persists the children_count and children_hash from this event if and only if
|
||||||
// the count is greater than what was previously there. If the count is updated, the event will be
|
// the count is greater than what was previously there. If the count is updated, the event will be
|
||||||
// updated to be unexplored.
|
// updated to be unexplored.
|
||||||
UpdateChildMetadata(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error
|
UpdateChildMetadata(ctx context.Context, ev *types.HeaderedEvent) error
|
||||||
// ChildMetadata returns the children_count and children_hash for the event ID in question.
|
// ChildMetadata returns the children_count and children_hash for the event ID in question.
|
||||||
// Also returns the `explored` flag, which is set to true when MarkChildrenExplored is called and is set
|
// Also returns the `explored` flag, which is set to true when MarkChildrenExplored is called and is set
|
||||||
// back to `false` when a larger count is inserted via UpdateChildMetadata.
|
// back to `false` when a larger count is inserted via UpdateChildMetadata.
|
||||||
@ -222,7 +222,7 @@ func newSQLiteDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOption
|
|||||||
return &d, nil
|
return &d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DB) StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error {
|
func (p *DB) StoreRelation(ctx context.Context, ev *types.HeaderedEvent) error {
|
||||||
parent, child, relType := parentChildEventIDs(ev)
|
parent, child, relType := parentChildEventIDs(ev)
|
||||||
if parent == "" || child == "" {
|
if parent == "" || child == "" {
|
||||||
return nil
|
return nil
|
||||||
@ -244,7 +244,7 @@ func (p *DB) StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEv
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DB) UpdateChildMetadata(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent) error {
|
func (p *DB) UpdateChildMetadata(ctx context.Context, ev *types.HeaderedEvent) error {
|
||||||
eventCount, eventHash := extractChildMetadata(ev)
|
eventCount, eventHash := extractChildMetadata(ev)
|
||||||
if eventCount == 0 {
|
if eventCount == 0 {
|
||||||
return nil // nothing to update with
|
return nil // nothing to update with
|
||||||
@ -315,7 +315,7 @@ func (p *DB) ParentForChild(ctx context.Context, eventID, relType string) (*even
|
|||||||
return &ei, nil
|
return &ei, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parentChildEventIDs(ev *gomatrixserverlib.HeaderedEvent) (parent, child, relType string) {
|
func parentChildEventIDs(ev *types.HeaderedEvent) (parent, child, relType string) {
|
||||||
if ev == nil {
|
if ev == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ func parentChildEventIDs(ev *gomatrixserverlib.HeaderedEvent) (parent, child, re
|
|||||||
return body.Relationship.EventID, ev.EventID(), body.Relationship.RelType
|
return body.Relationship.EventID, ev.EventID(), body.Relationship.RelType
|
||||||
}
|
}
|
||||||
|
|
||||||
func roomIDAndServers(ev *gomatrixserverlib.HeaderedEvent) (roomID string, servers []string) {
|
func roomIDAndServers(ev *types.HeaderedEvent) (roomID string, servers []string) {
|
||||||
servers = []string{}
|
servers = []string{}
|
||||||
if ev == nil {
|
if ev == nil {
|
||||||
return
|
return
|
||||||
@ -349,7 +349,7 @@ func roomIDAndServers(ev *gomatrixserverlib.HeaderedEvent) (roomID string, serve
|
|||||||
return body.RoomID, body.Servers
|
return body.RoomID, body.Servers
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractChildMetadata(ev *gomatrixserverlib.HeaderedEvent) (count int, hash []byte) {
|
func extractChildMetadata(ev *types.HeaderedEvent) (count int, hash []byte) {
|
||||||
unsigned := struct {
|
unsigned := struct {
|
||||||
Counts map[string]int `json:"children"`
|
Counts map[string]int `json:"children"`
|
||||||
Hash spec.Base64Bytes `json:"children_hash"`
|
Hash spec.Base64Bytes `json:"children_hash"`
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/internal/httputil"
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
@ -388,7 +389,7 @@ func (w *walker) walk() util.JSONResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *walker) stateEvent(roomID, evType, stateKey string) *gomatrixserverlib.HeaderedEvent {
|
func (w *walker) stateEvent(roomID, evType, stateKey string) *types.HeaderedEvent {
|
||||||
var queryRes roomserver.QueryCurrentStateResponse
|
var queryRes roomserver.QueryCurrentStateResponse
|
||||||
tuple := gomatrixserverlib.StateKeyTuple{
|
tuple := gomatrixserverlib.StateKeyTuple{
|
||||||
EventType: evType,
|
EventType: evType,
|
||||||
@ -636,7 +637,7 @@ func (w *walker) authorisedUser(roomID, parentRoomID string) (authed bool, isJoi
|
|||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *walker) restrictedJoinRuleAllowedRooms(joinRuleEv *gomatrixserverlib.HeaderedEvent, allowType string) (allows []string) {
|
func (w *walker) restrictedJoinRuleAllowedRooms(joinRuleEv *types.HeaderedEvent, allowType string) (allows []string) {
|
||||||
rule, _ := joinRuleEv.JoinRule()
|
rule, _ := joinRuleEv.JoinRule()
|
||||||
if rule != spec.Restricted {
|
if rule != spec.Restricted {
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -31,6 +30,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/fulltext"
|
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
@ -318,7 +318,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
|||||||
pduPos, err := s.db.WriteEvent(
|
pduPos, err := s.db.WriteEvent(
|
||||||
ctx,
|
ctx,
|
||||||
ev,
|
ev,
|
||||||
[]*gomatrixserverlib.HeaderedEvent{},
|
[]*rstypes.HeaderedEvent{},
|
||||||
[]string{}, // adds no state
|
[]string{}, // adds no state
|
||||||
[]string{}, // removes no state
|
[]string{}, // removes no state
|
||||||
nil, // no transaction
|
nil, // no transaction
|
||||||
@ -362,7 +362,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent, sp types.StreamPosition) (types.StreamPosition, error) {
|
func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *rstypes.HeaderedEvent, sp types.StreamPosition) (types.StreamPosition, error) {
|
||||||
if ev.Type() != spec.MRoomMember {
|
if ev.Type() != spec.MRoomMember {
|
||||||
return sp, nil
|
return sp, nil
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ func (s *OutputRoomEventConsumer) onPurgeRoom(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OutputRoomEventConsumer) updateStateEvent(event *gomatrixserverlib.HeaderedEvent) (*gomatrixserverlib.HeaderedEvent, error) {
|
func (s *OutputRoomEventConsumer) updateStateEvent(event *rstypes.HeaderedEvent) (*rstypes.HeaderedEvent, error) {
|
||||||
if event.StateKey() == nil {
|
if event.StateKey() == nil {
|
||||||
return event, nil
|
return event, nil
|
||||||
}
|
}
|
||||||
@ -531,7 +531,7 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *gomatrixserverlib.Head
|
|||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent, pduPosition types.StreamPosition) error {
|
func (s *OutputRoomEventConsumer) writeFTS(ev *rstypes.HeaderedEvent, pduPosition types.StreamPosition) error {
|
||||||
if !s.cfg.Fulltext.Enabled {
|
if !s.cfg.Fulltext.Enabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,16 +99,16 @@ func (ev eventVisibility) allowed() (allowed bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyHistoryVisibilityFilter applies the room history visibility filter on gomatrixserverlib.HeaderedEvents.
|
// ApplyHistoryVisibilityFilter applies the room history visibility filter on types.HeaderedEvents.
|
||||||
// Returns the filtered events and an error, if any.
|
// Returns the filtered events and an error, if any.
|
||||||
func ApplyHistoryVisibilityFilter(
|
func ApplyHistoryVisibilityFilter(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
syncDB storage.DatabaseTransaction,
|
syncDB storage.DatabaseTransaction,
|
||||||
rsAPI api.SyncRoomserverAPI,
|
rsAPI api.SyncRoomserverAPI,
|
||||||
events []*gomatrixserverlib.HeaderedEvent,
|
events []*types.HeaderedEvent,
|
||||||
alwaysIncludeEventIDs map[string]struct{},
|
alwaysIncludeEventIDs map[string]struct{},
|
||||||
userID, endpoint string,
|
userID, endpoint string,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*types.HeaderedEvent, error) {
|
||||||
if len(events) == 0 {
|
if len(events) == 0 {
|
||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
@ -120,7 +121,7 @@ func ApplyHistoryVisibilityFilter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the mapping from eventID -> eventVisibility
|
// Get the mapping from eventID -> eventVisibility
|
||||||
eventsFiltered := make([]*gomatrixserverlib.HeaderedEvent, 0, len(events))
|
eventsFiltered := make([]*types.HeaderedEvent, 0, len(events))
|
||||||
visibilities := visibilityForEvents(ctx, rsAPI, events, userID, events[0].RoomID())
|
visibilities := visibilityForEvents(ctx, rsAPI, events, userID, events[0].RoomID())
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
evVis := visibilities[ev.EventID()]
|
evVis := visibilities[ev.EventID()]
|
||||||
@ -170,7 +171,7 @@ func ApplyHistoryVisibilityFilter(
|
|||||||
func visibilityForEvents(
|
func visibilityForEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
rsAPI api.SyncRoomserverAPI,
|
rsAPI api.SyncRoomserverAPI,
|
||||||
events []*gomatrixserverlib.HeaderedEvent,
|
events []*types.HeaderedEvent,
|
||||||
userID, roomID string,
|
userID, roomID string,
|
||||||
) map[string]eventVisibility {
|
) map[string]eventVisibility {
|
||||||
eventIDs := make([]string, len(events))
|
eventIDs := make([]string, len(events))
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"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"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -87,7 +87,7 @@ func (n *Notifier) SetCurrentPosition(currPos types.StreamingToken) {
|
|||||||
// Typically a consumer supplies a posUpdate with the latest sync position for the
|
// Typically a consumer supplies a posUpdate with the latest sync position for the
|
||||||
// event type it handles, leaving other fields as 0.
|
// event type it handles, leaving other fields as 0.
|
||||||
func (n *Notifier) OnNewEvent(
|
func (n *Notifier) OnNewEvent(
|
||||||
ev *gomatrixserverlib.HeaderedEvent, roomID string, userIDs []string,
|
ev *rstypes.HeaderedEvent, roomID string, userIDs []string,
|
||||||
posUpdate types.StreamingToken,
|
posUpdate types.StreamingToken,
|
||||||
) {
|
) {
|
||||||
// update the current position then notify relevant /sync streams.
|
// update the current position then notify relevant /sync streams.
|
||||||
|
@ -22,16 +22,16 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
randomMessageEvent gomatrixserverlib.HeaderedEvent
|
randomMessageEvent rstypes.HeaderedEvent
|
||||||
aliceInviteBobEvent gomatrixserverlib.HeaderedEvent
|
aliceInviteBobEvent rstypes.HeaderedEvent
|
||||||
bobLeaveEvent gomatrixserverlib.HeaderedEvent
|
bobLeaveEvent rstypes.HeaderedEvent
|
||||||
syncPositionVeryOld = types.StreamingToken{PDUPosition: 5}
|
syncPositionVeryOld = types.StreamingToken{PDUPosition: 5}
|
||||||
syncPositionBefore = types.StreamingToken{PDUPosition: 11}
|
syncPositionBefore = types.StreamingToken{PDUPosition: 11}
|
||||||
syncPositionAfter = types.StreamingToken{PDUPosition: 12}
|
syncPositionAfter = types.StreamingToken{PDUPosition: 12}
|
||||||
|
@ -27,12 +27,12 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
"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/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -122,7 +122,7 @@ func Context(
|
|||||||
|
|
||||||
// verify the user is allowed to see the context for this room/event
|
// verify the user is allowed to see the context for this room/event
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
filteredEvents, err := internal.ApplyHistoryVisibilityFilter(ctx, snapshot, rsAPI, []*gomatrixserverlib.HeaderedEvent{&requestedEvent}, nil, device.UserID, "context")
|
filteredEvents, err := internal.ApplyHistoryVisibilityFilter(ctx, snapshot, rsAPI, []*rstypes.HeaderedEvent{&requestedEvent}, nil, device.UserID, "context")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("unable to apply history visibility filter")
|
logrus.WithError(err).Error("unable to apply history visibility filter")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
@ -212,9 +212,9 @@ func Context(
|
|||||||
// and an error, if any.
|
// and an error, if any.
|
||||||
func applyHistoryVisibilityOnContextEvents(
|
func applyHistoryVisibilityOnContextEvents(
|
||||||
ctx context.Context, snapshot storage.DatabaseTransaction, rsAPI roomserver.SyncRoomserverAPI,
|
ctx context.Context, snapshot storage.DatabaseTransaction, rsAPI roomserver.SyncRoomserverAPI,
|
||||||
eventsBefore, eventsAfter []*gomatrixserverlib.HeaderedEvent,
|
eventsBefore, eventsAfter []*rstypes.HeaderedEvent,
|
||||||
userID string,
|
userID string,
|
||||||
) (filteredBefore, filteredAfter []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (filteredBefore, filteredAfter []*rstypes.HeaderedEvent, err error) {
|
||||||
eventIDsBefore := make(map[string]struct{}, len(eventsBefore))
|
eventIDsBefore := make(map[string]struct{}, len(eventsBefore))
|
||||||
eventIDsAfter := make(map[string]struct{}, len(eventsAfter))
|
eventIDsAfter := make(map[string]struct{}, len(eventsAfter))
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ func applyHistoryVisibilityOnContextEvents(
|
|||||||
return filteredBefore, filteredAfter, nil
|
return filteredBefore, filteredAfter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStartEnd(ctx context.Context, snapshot storage.DatabaseTransaction, startEvents, endEvents []*gomatrixserverlib.HeaderedEvent) (start, end types.TopologyToken, err error) {
|
func getStartEnd(ctx context.Context, snapshot storage.DatabaseTransaction, startEvents, endEvents []*rstypes.HeaderedEvent) (start, end types.TopologyToken, err error) {
|
||||||
if len(startEvents) > 0 {
|
if len(startEvents) > 0 {
|
||||||
start, err = snapshot.EventPositionInTopology(ctx, startEvents[0].EventID())
|
start, err = snapshot.EventPositionInTopology(ctx, startEvents[0].EventID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -265,7 +265,7 @@ func applyLazyLoadMembers(
|
|||||||
roomID string,
|
roomID string,
|
||||||
events []synctypes.ClientEvent,
|
events []synctypes.ClientEvent,
|
||||||
lazyLoadCache caching.LazyLoadCache,
|
lazyLoadCache caching.LazyLoadCache,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*rstypes.HeaderedEvent, error) {
|
||||||
eventSenders := make(map[string]struct{})
|
eventSenders := make(map[string]struct{})
|
||||||
// get members who actually send an event
|
// get members who actually send an event
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
@ -303,7 +304,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var events []*gomatrixserverlib.HeaderedEvent
|
var events []*rstypes.HeaderedEvent
|
||||||
util.GetLogger(r.ctx).WithFields(logrus.Fields{
|
util.GetLogger(r.ctx).WithFields(logrus.Fields{
|
||||||
"start": r.from,
|
"start": r.from,
|
||||||
"end": r.to,
|
"end": r.to,
|
||||||
@ -342,8 +343,8 @@ func (r *messagesReq) retrieveEvents() (
|
|||||||
// Sort the events to ensure we send them in the right order.
|
// Sort the events to ensure we send them in the right order.
|
||||||
if r.backwardOrdering {
|
if r.backwardOrdering {
|
||||||
// This reverses the array from old->new to new->old
|
// This reverses the array from old->new to new->old
|
||||||
reversed := func(in []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent {
|
reversed := func(in []*rstypes.HeaderedEvent) []*rstypes.HeaderedEvent {
|
||||||
out := make([]*gomatrixserverlib.HeaderedEvent, len(in))
|
out := make([]*rstypes.HeaderedEvent, len(in))
|
||||||
for i := 0; i < len(in); i++ {
|
for i := 0; i < len(in); i++ {
|
||||||
out[i] = in[len(in)-i-1]
|
out[i] = in[len(in)-i-1]
|
||||||
}
|
}
|
||||||
@ -367,7 +368,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||||||
return synctypes.HeaderedToClientEvents(filteredEvents, synctypes.FormatAll), start, end, err
|
return synctypes.HeaderedToClientEvents(filteredEvents, synctypes.FormatAll), start, end, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *messagesReq) getStartEnd(events []*gomatrixserverlib.HeaderedEvent) (start, end types.TopologyToken, err error) {
|
func (r *messagesReq) getStartEnd(events []*rstypes.HeaderedEvent) (start, end types.TopologyToken, err error) {
|
||||||
if r.backwardOrdering {
|
if r.backwardOrdering {
|
||||||
start = *r.from
|
start = *r.from
|
||||||
if events[len(events)-1].Type() == spec.MRoomCreate {
|
if events[len(events)-1].Type() == spec.MRoomCreate {
|
||||||
@ -406,7 +407,7 @@ func (r *messagesReq) getStartEnd(events []*gomatrixserverlib.HeaderedEvent) (st
|
|||||||
// Returns an error if there was an issue talking with the database or
|
// Returns an error if there was an issue talking with the database or
|
||||||
// backfilling.
|
// backfilling.
|
||||||
func (r *messagesReq) handleEmptyEventsSlice() (
|
func (r *messagesReq) handleEmptyEventsSlice() (
|
||||||
events []*gomatrixserverlib.HeaderedEvent, err error,
|
events []*rstypes.HeaderedEvent, err error,
|
||||||
) {
|
) {
|
||||||
backwardExtremities, err := r.snapshot.BackwardExtremitiesForRoom(r.ctx, r.roomID)
|
backwardExtremities, err := r.snapshot.BackwardExtremitiesForRoom(r.ctx, r.roomID)
|
||||||
|
|
||||||
@ -420,7 +421,7 @@ func (r *messagesReq) handleEmptyEventsSlice() (
|
|||||||
} else {
|
} else {
|
||||||
// If not, it means the slice was empty because we reached the room's
|
// If not, it means the slice was empty because we reached the room's
|
||||||
// creation, so return an empty slice.
|
// creation, so return an empty slice.
|
||||||
events = []*gomatrixserverlib.HeaderedEvent{}
|
events = []*rstypes.HeaderedEvent{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -432,7 +433,7 @@ func (r *messagesReq) handleEmptyEventsSlice() (
|
|||||||
// through backfilling if needed.
|
// through backfilling if needed.
|
||||||
// Returns an error if there was an issue while backfilling.
|
// Returns an error if there was an issue while backfilling.
|
||||||
func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent) (
|
func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent) (
|
||||||
events []*gomatrixserverlib.HeaderedEvent, err error,
|
events []*rstypes.HeaderedEvent, err error,
|
||||||
) {
|
) {
|
||||||
// Check if we have enough events.
|
// Check if we have enough events.
|
||||||
isSetLargeEnough := len(streamEvents) >= r.filter.Limit
|
isSetLargeEnough := len(streamEvents) >= r.filter.Limit
|
||||||
@ -460,7 +461,7 @@ func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent
|
|||||||
// Backfill is needed if we've reached a backward extremity and need more
|
// Backfill is needed if we've reached a backward extremity and need more
|
||||||
// events. It's only needed if the direction is backward.
|
// events. It's only needed if the direction is backward.
|
||||||
if len(backwardExtremities) > 0 && !isSetLargeEnough && r.backwardOrdering {
|
if len(backwardExtremities) > 0 && !isSetLargeEnough && r.backwardOrdering {
|
||||||
var pdus []*gomatrixserverlib.HeaderedEvent
|
var pdus []*rstypes.HeaderedEvent
|
||||||
// Only ask the remote server for enough events to reach the limit.
|
// Only ask the remote server for enough events to reach the limit.
|
||||||
pdus, err = r.backfill(r.roomID, backwardExtremities, r.filter.Limit-len(streamEvents))
|
pdus, err = r.backfill(r.roomID, backwardExtremities, r.filter.Limit-len(streamEvents))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -478,7 +479,7 @@ func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type eventsByDepth []*gomatrixserverlib.HeaderedEvent
|
type eventsByDepth []*rstypes.HeaderedEvent
|
||||||
|
|
||||||
func (e eventsByDepth) Len() int {
|
func (e eventsByDepth) Len() int {
|
||||||
return len(e)
|
return len(e)
|
||||||
@ -499,7 +500,7 @@ func (e eventsByDepth) Less(i, j int) bool {
|
|||||||
// event, or if there is no remote homeserver to contact.
|
// event, or if there is no remote homeserver to contact.
|
||||||
// Returns an error if there was an issue with retrieving the list of servers in
|
// Returns an error if there was an issue with retrieving the list of servers in
|
||||||
// the room or sending the request.
|
// the room or sending the request.
|
||||||
func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]string, limit int) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]string, limit int) ([]*rstypes.HeaderedEvent, error) {
|
||||||
var res api.PerformBackfillResponse
|
var res api.PerformBackfillResponse
|
||||||
err := r.rsAPI.PerformBackfill(context.Background(), &api.PerformBackfillRequest{
|
err := r.rsAPI.PerformBackfill(context.Background(), &api.PerformBackfillRequest{
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
@ -532,7 +533,7 @@ func (r *messagesReq) backfill(roomID string, backwardsExtremities map[string][]
|
|||||||
_, err = r.db.WriteEvent(
|
_, err = r.db.WriteEvent(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
res.Events[i],
|
res.Events[i],
|
||||||
[]*gomatrixserverlib.HeaderedEvent{},
|
[]*rstypes.HeaderedEvent{},
|
||||||
[]string{},
|
[]string{},
|
||||||
[]string{},
|
[]string{},
|
||||||
nil, true,
|
nil, true,
|
||||||
|
@ -18,13 +18,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
"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/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -96,7 +96,7 @@ func Relations(
|
|||||||
return util.ErrorResponse(err)
|
return util.ErrorResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
headeredEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, len(events))
|
headeredEvents := make([]*rstypes.HeaderedEvent, 0, len(events))
|
||||||
for _, event := range events {
|
for _, event := range events {
|
||||||
headeredEvents = append(headeredEvents, event.HeaderedEvent)
|
headeredEvents = append(headeredEvents, event.HeaderedEvent)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve/v2/search"
|
"github.com/blevesearch/bleve/v2/search"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -32,6 +31,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/internal/fulltext"
|
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/userapi/api"
|
"github.com/matrix-org/dendrite/userapi/api"
|
||||||
@ -263,10 +263,10 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||||||
func contextEvents(
|
func contextEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
snapshot storage.DatabaseTransaction,
|
snapshot storage.DatabaseTransaction,
|
||||||
event *gomatrixserverlib.HeaderedEvent,
|
event *types.HeaderedEvent,
|
||||||
roomFilter *synctypes.RoomEventFilter,
|
roomFilter *synctypes.RoomEventFilter,
|
||||||
searchReq SearchRequest,
|
searchReq SearchRequest,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, []*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*types.HeaderedEvent, []*types.HeaderedEvent, error) {
|
||||||
id, _, err := snapshot.SelectContextEvent(ctx, event.RoomID(), event.EventID())
|
id, _, err := snapshot.SelectContextEvent(ctx, event.RoomID(), event.EventID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to query context event")
|
logrus.WithError(err).Error("failed to query context event")
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/fulltext"
|
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
@ -215,7 +216,7 @@ func TestSearch(t *testing.T) {
|
|||||||
// store the events in the database
|
// store the events in the database
|
||||||
var sp types.StreamPosition
|
var sp types.StreamPosition
|
||||||
for _, x := range room.Events() {
|
for _, x := range room.Events() {
|
||||||
var stateEvents []*gomatrixserverlib.HeaderedEvent
|
var stateEvents []*rstypes.HeaderedEvent
|
||||||
var stateEventIDs []string
|
var stateEventIDs []string
|
||||||
if x.Type() == spec.MRoomMember {
|
if x.Type() == spec.MRoomMember {
|
||||||
stateEvents = append(stateEvents, x)
|
stateEvents = append(stateEvents, x)
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/shared"
|
"github.com/matrix-org/dendrite/syncapi/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
@ -42,16 +43,16 @@ type DatabaseTransaction interface {
|
|||||||
MaxStreamPositionForPresence(ctx context.Context) (types.StreamPosition, error)
|
MaxStreamPositionForPresence(ctx context.Context) (types.StreamPosition, error)
|
||||||
MaxStreamPositionForRelations(ctx context.Context) (types.StreamPosition, error)
|
MaxStreamPositionForRelations(ctx context.Context) (types.StreamPosition, error)
|
||||||
|
|
||||||
CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*rstypes.HeaderedEvent, error)
|
||||||
GetStateDeltasForFullStateSync(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *synctypes.StateFilter) ([]types.StateDelta, []string, error)
|
GetStateDeltasForFullStateSync(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *synctypes.StateFilter) ([]types.StateDelta, []string, error)
|
||||||
GetStateDeltas(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *synctypes.StateFilter) ([]types.StateDelta, []string, error)
|
GetStateDeltas(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *synctypes.StateFilter) ([]types.StateDelta, []string, error)
|
||||||
RoomIDsWithMembership(ctx context.Context, userID string, membership string) ([]string, error)
|
RoomIDsWithMembership(ctx context.Context, userID string, membership string) ([]string, error)
|
||||||
MembershipCount(ctx context.Context, roomID, membership string, pos types.StreamPosition) (int, error)
|
MembershipCount(ctx context.Context, roomID, membership string, pos types.StreamPosition) (int, error)
|
||||||
GetRoomSummary(ctx context.Context, roomID, userID string) (summary *types.Summary, err error)
|
GetRoomSummary(ctx context.Context, roomID, userID string) (summary *types.Summary, err error)
|
||||||
RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error)
|
RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error)
|
||||||
GetBackwardTopologyPos(ctx context.Context, events []*gomatrixserverlib.HeaderedEvent) (types.TopologyToken, error)
|
GetBackwardTopologyPos(ctx context.Context, events []*rstypes.HeaderedEvent) (types.TopologyToken, error)
|
||||||
PositionInTopology(ctx context.Context, eventID string) (pos types.StreamPosition, spos types.StreamPosition, err error)
|
PositionInTopology(ctx context.Context, eventID string) (pos types.StreamPosition, spos types.StreamPosition, err error)
|
||||||
InviteEventsInRange(ctx context.Context, targetUserID string, r types.Range) (map[string]*gomatrixserverlib.HeaderedEvent, map[string]*gomatrixserverlib.HeaderedEvent, types.StreamPosition, error)
|
InviteEventsInRange(ctx context.Context, targetUserID string, r types.Range) (map[string]*rstypes.HeaderedEvent, map[string]*rstypes.HeaderedEvent, types.StreamPosition, error)
|
||||||
PeeksInRange(ctx context.Context, userID, deviceID string, r types.Range) (peeks []types.Peek, err error)
|
PeeksInRange(ctx context.Context, userID, deviceID string, r types.Range) (peeks []types.Peek, err error)
|
||||||
RoomReceiptsAfter(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) (types.StreamPosition, []types.OutputReceiptEvent, error)
|
RoomReceiptsAfter(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) (types.StreamPosition, []types.OutputReceiptEvent, error)
|
||||||
// AllJoinedUsersInRooms returns a map of room ID to a list of all joined user IDs.
|
// AllJoinedUsersInRooms returns a map of room ID to a list of all joined user IDs.
|
||||||
@ -65,15 +66,15 @@ type DatabaseTransaction interface {
|
|||||||
// If an event is not found in the database then it will be omitted from the list.
|
// If an event is not found in the database then it will be omitted from the list.
|
||||||
// Returns an error if there was a problem talking with the database.
|
// Returns an error if there was a problem talking with the database.
|
||||||
// Does not include any transaction IDs in the returned events.
|
// Does not include any transaction IDs in the returned events.
|
||||||
Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error)
|
||||||
// GetStateEvent returns the Matrix state event of a given type for a given room with a given state key
|
// GetStateEvent returns the Matrix state event of a given type for a given room with a given state key
|
||||||
// If no event could be found, returns nil
|
// If no event could be found, returns nil
|
||||||
// If there was an issue during the retrieval, returns an error
|
// If there was an issue during the retrieval, returns an error
|
||||||
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error)
|
GetStateEvent(ctx context.Context, roomID, evType, stateKey string) (*rstypes.HeaderedEvent, error)
|
||||||
// GetStateEventsForRoom fetches the state events for a given room.
|
// GetStateEventsForRoom fetches the state events for a given room.
|
||||||
// Returns an empty slice if no state events could be found for this room.
|
// Returns an empty slice if no state events could be found for this room.
|
||||||
// Returns an error if there was an issue with the retrieval.
|
// Returns an error if there was an issue with the retrieval.
|
||||||
GetStateEventsForRoom(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error)
|
GetStateEventsForRoom(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter) (stateEvents []*rstypes.HeaderedEvent, err error)
|
||||||
// GetAccountDataInRange returns all account data for a given user inserted or
|
// GetAccountDataInRange returns all account data for a given user inserted or
|
||||||
// updated between two given positions
|
// updated between two given positions
|
||||||
// Returns a map following the format data[roomID] = []dataTypes
|
// Returns a map following the format data[roomID] = []dataTypes
|
||||||
@ -89,15 +90,15 @@ type DatabaseTransaction interface {
|
|||||||
// StreamEventsToEvents converts streamEvent to Event. If device is non-nil and
|
// StreamEventsToEvents converts streamEvent to Event. If device is non-nil and
|
||||||
// matches the streamevent.transactionID device then the transaction ID gets
|
// matches the streamevent.transactionID device then the transaction ID gets
|
||||||
// added to the unsigned section of the output event.
|
// added to the unsigned section of the output event.
|
||||||
StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*gomatrixserverlib.HeaderedEvent
|
StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*rstypes.HeaderedEvent
|
||||||
// SendToDeviceUpdatesForSync returns a list of send-to-device updates. It returns the
|
// SendToDeviceUpdatesForSync returns a list of send-to-device updates. It returns the
|
||||||
// relevant events within the given ranges for the supplied user ID and device ID.
|
// relevant events within the given ranges for the supplied user ID and device ID.
|
||||||
SendToDeviceUpdatesForSync(ctx context.Context, userID, deviceID string, from, to types.StreamPosition) (pos types.StreamPosition, events []types.SendToDeviceEvent, err error)
|
SendToDeviceUpdatesForSync(ctx context.Context, userID, deviceID string, from, to types.StreamPosition) (pos types.StreamPosition, events []types.SendToDeviceEvent, err error)
|
||||||
// GetRoomReceipts gets all receipts for a given roomID
|
// GetRoomReceipts gets all receipts for a given roomID
|
||||||
GetRoomReceipts(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) ([]types.OutputReceiptEvent, error)
|
GetRoomReceipts(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) ([]types.OutputReceiptEvent, error)
|
||||||
SelectContextEvent(ctx context.Context, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
SelectContextEvent(ctx context.Context, roomID, eventID string) (int, rstypes.HeaderedEvent, error)
|
||||||
SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*rstypes.HeaderedEvent, error)
|
||||||
SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*rstypes.HeaderedEvent, error)
|
||||||
StreamToTopologicalPosition(ctx context.Context, roomID string, streamPos types.StreamPosition, backwardOrdering bool) (types.TopologyToken, error)
|
StreamToTopologicalPosition(ctx context.Context, roomID string, streamPos types.StreamPosition, backwardOrdering bool) (types.TopologyToken, error)
|
||||||
IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)
|
IgnoresForUser(ctx context.Context, userID string) (*types.IgnoredUsers, error)
|
||||||
// SelectMembershipForUser returns the membership of the user before and including the given position. If no membership can be found
|
// SelectMembershipForUser returns the membership of the user before and including the given position. If no membership can be found
|
||||||
@ -123,11 +124,11 @@ type Database interface {
|
|||||||
// If an event is not found in the database then it will be omitted from the list.
|
// If an event is not found in the database then it will be omitted from the list.
|
||||||
// Returns an error if there was a problem talking with the database.
|
// Returns an error if there was a problem talking with the database.
|
||||||
// Does not include any transaction IDs in the returned events.
|
// Does not include any transaction IDs in the returned events.
|
||||||
Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error)
|
||||||
// WriteEvent into the database. It is not safe to call this function from multiple goroutines, as it would create races
|
// WriteEvent into the database. It is not safe to call this function from multiple goroutines, as it would create races
|
||||||
// when generating the sync stream position for this event. Returns the sync stream position for the inserted event.
|
// when generating the sync stream position for this event. Returns the sync stream position for the inserted event.
|
||||||
// Returns an error if there was a problem inserting this event.
|
// Returns an error if there was a problem inserting this event.
|
||||||
WriteEvent(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent, addStateEvents []*gomatrixserverlib.HeaderedEvent,
|
WriteEvent(ctx context.Context, ev *rstypes.HeaderedEvent, addStateEvents []*rstypes.HeaderedEvent,
|
||||||
addStateEventIDs []string, removeStateEventIDs []string, transactionID *api.TransactionID, excludeFromSync bool,
|
addStateEventIDs []string, removeStateEventIDs []string, transactionID *api.TransactionID, excludeFromSync bool,
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility,
|
historyVisibility gomatrixserverlib.HistoryVisibility,
|
||||||
) (types.StreamPosition, error)
|
) (types.StreamPosition, error)
|
||||||
@ -146,7 +147,7 @@ type Database interface {
|
|||||||
// AddInviteEvent stores a new invite event for a user.
|
// AddInviteEvent stores a new invite event for a user.
|
||||||
// If the invite was successfully stored this returns the stream ID it was stored at.
|
// If the invite was successfully stored this returns the stream ID it was stored at.
|
||||||
// Returns an error if there was a problem communicating with the database.
|
// Returns an error if there was a problem communicating with the database.
|
||||||
AddInviteEvent(ctx context.Context, inviteEvent *gomatrixserverlib.HeaderedEvent) (types.StreamPosition, error)
|
AddInviteEvent(ctx context.Context, inviteEvent *rstypes.HeaderedEvent) (types.StreamPosition, error)
|
||||||
// RetireInviteEvent removes an old invite event from the database. Returns the new position of the retired invite.
|
// RetireInviteEvent removes an old invite event from the database. Returns the new position of the retired invite.
|
||||||
// Returns an error if there was a problem communicating with the database.
|
// Returns an error if there was a problem communicating with the database.
|
||||||
RetireInviteEvent(ctx context.Context, inviteEventID string) (types.StreamPosition, error)
|
RetireInviteEvent(ctx context.Context, inviteEventID string) (types.StreamPosition, error)
|
||||||
@ -173,12 +174,12 @@ type Database interface {
|
|||||||
// goes wrong.
|
// goes wrong.
|
||||||
PutFilter(ctx context.Context, localpart string, filter *synctypes.Filter) (string, error)
|
PutFilter(ctx context.Context, localpart string, filter *synctypes.Filter) (string, error)
|
||||||
// RedactEvent wipes an event in the database and sets the unsigned.redacted_because key to the redaction event
|
// RedactEvent wipes an event in the database and sets the unsigned.redacted_because key to the redaction event
|
||||||
RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) error
|
RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *rstypes.HeaderedEvent) error
|
||||||
// StoreReceipt stores new receipt events
|
// StoreReceipt stores new receipt events
|
||||||
StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error)
|
StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error)
|
||||||
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error
|
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error
|
||||||
ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error)
|
ReIndex(ctx context.Context, limit, afterID int64) (map[int64]rstypes.HeaderedEvent, error)
|
||||||
UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error
|
UpdateRelations(ctx context.Context, event *rstypes.HeaderedEvent) error
|
||||||
RedactRelations(ctx context.Context, roomID, redactedEventID string) error
|
RedactRelations(ctx context.Context, roomID, redactedEventID string) error
|
||||||
SelectMemberships(
|
SelectMemberships(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -274,7 +275,7 @@ func (s *currentRoomStateStatements) SelectCurrentState(
|
|||||||
ctx context.Context, txn *sql.Tx, roomID string,
|
ctx context.Context, txn *sql.Tx, roomID string,
|
||||||
stateFilter *synctypes.StateFilter,
|
stateFilter *synctypes.StateFilter,
|
||||||
excludeEventIDs []string,
|
excludeEventIDs []string,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*rstypes.HeaderedEvent, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.selectCurrentStateStmt)
|
stmt := sqlutil.TxStmt(txn, s.selectCurrentStateStmt)
|
||||||
senders, notSenders := getSendersStateFilterFilter(stateFilter)
|
senders, notSenders := getSendersStateFilterFilter(stateFilter)
|
||||||
// We're going to query members later, so remove them from this request
|
// We're going to query members later, so remove them from this request
|
||||||
@ -320,7 +321,7 @@ func (s *currentRoomStateStatements) DeleteRoomStateForRoom(
|
|||||||
|
|
||||||
func (s *currentRoomStateStatements) UpsertRoomState(
|
func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
event *gomatrixserverlib.HeaderedEvent, membership *string, addedAt types.StreamPosition,
|
event *rstypes.HeaderedEvent, membership *string, addedAt types.StreamPosition,
|
||||||
) error {
|
) error {
|
||||||
// Parse content as JSON and search for an "url" key
|
// Parse content as JSON and search for an "url" key
|
||||||
containsURL := false
|
containsURL := false
|
||||||
@ -378,8 +379,8 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,8 +395,8 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
|
|||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func rowsToEvents(rows *sql.Rows) ([]*rstypes.HeaderedEvent, error) {
|
||||||
result := []*gomatrixserverlib.HeaderedEvent{}
|
result := []*rstypes.HeaderedEvent{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var eventID string
|
var eventID string
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
@ -403,8 +404,8 @@ func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, &ev)
|
result = append(result, &ev)
|
||||||
@ -414,7 +415,7 @@ func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
|||||||
|
|
||||||
func (s *currentRoomStateStatements) SelectStateEvent(
|
func (s *currentRoomStateStatements) SelectStateEvent(
|
||||||
ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string,
|
ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*rstypes.HeaderedEvent, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.selectStateEventStmt)
|
stmt := sqlutil.TxStmt(txn, s.selectStateEventStmt)
|
||||||
var res []byte
|
var res []byte
|
||||||
err := stmt.QueryRowContext(ctx, roomID, evType, stateKey).Scan(&res)
|
err := stmt.QueryRowContext(ctx, roomID, evType, stateKey).Scan(&res)
|
||||||
@ -424,7 +425,7 @@ func (s *currentRoomStateStatements) SelectStateEvent(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err = json.Unmarshal(res, &ev); err != nil {
|
if err = json.Unmarshal(res, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ func currentHistoryVisibilities(ctx context.Context, tx *sql.Tx) (map[string]gom
|
|||||||
defer rows.Close() // nolint: errcheck
|
defer rows.Close() // nolint: errcheck
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
var roomID string
|
var roomID string
|
||||||
var event gomatrixserverlib.HeaderedEvent
|
var event types.HeaderedEvent
|
||||||
var hisVis gomatrixserverlib.HistoryVisibility
|
var hisVis gomatrixserverlib.HistoryVisibility
|
||||||
historyVisibilities := make(map[string]gomatrixserverlib.HistoryVisibility)
|
historyVisibilities := make(map[string]gomatrixserverlib.HistoryVisibility)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const inviteEventsSchema = `
|
const inviteEventsSchema = `
|
||||||
@ -89,7 +89,7 @@ func NewPostgresInvitesTable(db *sql.DB) (tables.Invites, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *inviteEventsStatements) InsertInviteEvent(
|
func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
ctx context.Context, txn *sql.Tx, inviteEvent *gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, txn *sql.Tx, inviteEvent *rstypes.HeaderedEvent,
|
||||||
) (streamPos types.StreamPosition, err error) {
|
) (streamPos types.StreamPosition, err error) {
|
||||||
var headeredJSON []byte
|
var headeredJSON []byte
|
||||||
headeredJSON, err = json.Marshal(inviteEvent)
|
headeredJSON, err = json.Marshal(inviteEvent)
|
||||||
@ -119,7 +119,7 @@ func (s *inviteEventsStatements) DeleteInviteEvent(
|
|||||||
// active invites for the target user ID in the supplied range.
|
// active invites for the target user ID in the supplied range.
|
||||||
func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
||||||
ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range,
|
ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, map[string]*gomatrixserverlib.HeaderedEvent, types.StreamPosition, error) {
|
) (map[string]*rstypes.HeaderedEvent, map[string]*rstypes.HeaderedEvent, types.StreamPosition, error) {
|
||||||
var lastPos types.StreamPosition
|
var lastPos types.StreamPosition
|
||||||
stmt := sqlutil.TxStmt(txn, s.selectInviteEventsInRangeStmt)
|
stmt := sqlutil.TxStmt(txn, s.selectInviteEventsInRangeStmt)
|
||||||
rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High())
|
rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High())
|
||||||
@ -127,8 +127,8 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
|||||||
return nil, nil, lastPos, err
|
return nil, nil, lastPos, err
|
||||||
}
|
}
|
||||||
defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
|
defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
|
||||||
result := map[string]*gomatrixserverlib.HeaderedEvent{}
|
result := map[string]*rstypes.HeaderedEvent{}
|
||||||
retired := map[string]*gomatrixserverlib.HeaderedEvent{}
|
retired := map[string]*rstypes.HeaderedEvent{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
id types.StreamPosition
|
id types.StreamPosition
|
||||||
@ -151,7 +151,7 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var event *gomatrixserverlib.HeaderedEvent
|
var event *rstypes.HeaderedEvent
|
||||||
if err := json.Unmarshal(eventJSON, &event); err != nil {
|
if err := json.Unmarshal(eventJSON, &event); err != nil {
|
||||||
return nil, nil, lastPos, err
|
return nil, nil, lastPos, err
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,8 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
)
|
)
|
||||||
@ -100,7 +99,7 @@ func NewPostgresMembershipsTable(db *sql.DB) (tables.Memberships, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *membershipsStatements) UpsertMembership(
|
func (s *membershipsStatements) UpsertMembership(
|
||||||
ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent,
|
||||||
streamPos, topologicalPos types.StreamPosition,
|
streamPos, topologicalPos types.StreamPosition,
|
||||||
) error {
|
) error {
|
||||||
membership, err := event.Membership()
|
membership, err := event.Membership()
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -264,7 +265,7 @@ func NewPostgresEventsTable(db *sql.DB) (tables.Events, error) {
|
|||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent) error {
|
func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent) error {
|
||||||
headeredJSON, err := json.Marshal(event)
|
headeredJSON, err := json.Marshal(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -329,8 +330,8 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
needSet := stateNeeded[ev.RoomID()]
|
needSet := stateNeeded[ev.RoomID()]
|
||||||
@ -375,7 +376,7 @@ func (s *outputRoomEventsStatements) SelectMaxEventID(
|
|||||||
// of the inserted event.
|
// of the inserted event.
|
||||||
func (s *outputRoomEventsStatements) InsertEvent(
|
func (s *outputRoomEventsStatements) InsertEvent(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
event *gomatrixserverlib.HeaderedEvent, addState, removeState []string,
|
event *rstypes.HeaderedEvent, addState, removeState []string,
|
||||||
transactionID *api.TransactionID, excludeFromSync bool, historyVisibility gomatrixserverlib.HistoryVisibility,
|
transactionID *api.TransactionID, excludeFromSync bool, historyVisibility gomatrixserverlib.HistoryVisibility,
|
||||||
) (streamPos types.StreamPosition, err error) {
|
) (streamPos types.StreamPosition, err error) {
|
||||||
var txnID *string
|
var txnID *string
|
||||||
@ -465,8 +466,8 @@ func (s *outputRoomEventsStatements) SelectRecentEvents(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +578,7 @@ func (s *outputRoomEventsStatements) DeleteEventsForRoom(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *outputRoomEventsStatements) SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (id int, evt gomatrixserverlib.HeaderedEvent, err error) {
|
func (s *outputRoomEventsStatements) SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (id int, evt rstypes.HeaderedEvent, err error) {
|
||||||
row := sqlutil.TxStmt(txn, s.selectContextEventStmt).QueryRowContext(ctx, roomID, eventID)
|
row := sqlutil.TxStmt(txn, s.selectContextEventStmt).QueryRowContext(ctx, roomID, eventID)
|
||||||
|
|
||||||
var eventAsString string
|
var eventAsString string
|
||||||
@ -595,7 +596,7 @@ func (s *outputRoomEventsStatements) SelectContextEvent(ctx context.Context, txn
|
|||||||
|
|
||||||
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||||
) (evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (evts []*rstypes.HeaderedEvent, err error) {
|
||||||
senders, notSenders := getSendersRoomEventFilter(filter)
|
senders, notSenders := getSendersRoomEventFilter(filter)
|
||||||
rows, err := sqlutil.TxStmt(txn, s.selectContextBeforeEventStmt).QueryContext(
|
rows, err := sqlutil.TxStmt(txn, s.selectContextBeforeEventStmt).QueryContext(
|
||||||
ctx, roomID, id, filter.Limit,
|
ctx, roomID, id, filter.Limit,
|
||||||
@ -612,7 +613,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
eventBytes []byte
|
eventBytes []byte
|
||||||
evt *gomatrixserverlib.HeaderedEvent
|
evt *rstypes.HeaderedEvent
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility
|
historyVisibility gomatrixserverlib.HistoryVisibility
|
||||||
)
|
)
|
||||||
if err = rows.Scan(&eventBytes, &historyVisibility); err != nil {
|
if err = rows.Scan(&eventBytes, &historyVisibility); err != nil {
|
||||||
@ -630,7 +631,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||||||
|
|
||||||
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||||
) (lastID int, evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (lastID int, evts []*rstypes.HeaderedEvent, err error) {
|
||||||
senders, notSenders := getSendersRoomEventFilter(filter)
|
senders, notSenders := getSendersRoomEventFilter(filter)
|
||||||
rows, err := sqlutil.TxStmt(txn, s.selectContextAfterEventStmt).QueryContext(
|
rows, err := sqlutil.TxStmt(txn, s.selectContextAfterEventStmt).QueryContext(
|
||||||
ctx, roomID, id, filter.Limit,
|
ctx, roomID, id, filter.Limit,
|
||||||
@ -647,7 +648,7 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
eventBytes []byte
|
eventBytes []byte
|
||||||
evt *gomatrixserverlib.HeaderedEvent
|
evt *rstypes.HeaderedEvent
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility
|
historyVisibility gomatrixserverlib.HistoryVisibility
|
||||||
)
|
)
|
||||||
if err = rows.Scan(&lastID, &eventBytes, &historyVisibility); err != nil {
|
if err = rows.Scan(&lastID, &eventBytes, &historyVisibility); err != nil {
|
||||||
@ -680,8 +681,8 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,7 +710,7 @@ func (s *outputRoomEventsStatements) PurgeEvents(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, limit, afterID int64, types []string) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
|
func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, limit, afterID int64, types []string) (map[int64]rstypes.HeaderedEvent, error) {
|
||||||
rows, err := sqlutil.TxStmt(txn, s.selectSearchStmt).QueryContext(ctx, afterID, pq.StringArray(types), limit)
|
rows, err := sqlutil.TxStmt(txn, s.selectSearchStmt).QueryContext(ctx, afterID, pq.StringArray(types), limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -718,14 +719,14 @@ func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, l
|
|||||||
|
|
||||||
var eventID string
|
var eventID string
|
||||||
var id int64
|
var id int64
|
||||||
result := make(map[int64]gomatrixserverlib.HeaderedEvent)
|
result := make(map[int64]rstypes.HeaderedEvent)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
if err = rows.Scan(&id, &eventID, &eventBytes); err != nil {
|
if err = rows.Scan(&id, &eventID, &eventBytes); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err = json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result[id] = ev
|
result[id] = ev
|
||||||
|
@ -18,10 +18,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
)
|
)
|
||||||
@ -105,7 +104,7 @@ func NewPostgresTopologyTable(db *sql.DB) (tables.Topology, error) {
|
|||||||
// InsertEventInTopology inserts the given event in the room's topology, based
|
// InsertEventInTopology inserts the given event in the room's topology, based
|
||||||
// on the event's depth.
|
// on the event's depth.
|
||||||
func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
||||||
ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, pos types.StreamPosition,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
||||||
) (topoPos types.StreamPosition, err error) {
|
) (topoPos types.StreamPosition, err error) {
|
||||||
err = sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).QueryRowContext(
|
err = sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).QueryRowContext(
|
||||||
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ func (d *Database) NewDatabaseTransaction(ctx context.Context) (*DatabaseTransac
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error) {
|
||||||
streamEvents, err := d.OutputEvents.SelectEvents(ctx, nil, eventIDs, nil, false)
|
streamEvents, err := d.OutputEvents.SelectEvents(ctx, nil, eventIDs, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -105,7 +106,7 @@ func (d *Database) Events(ctx context.Context, eventIDs []string) ([]*gomatrixse
|
|||||||
// If the invite was successfully stored this returns the stream ID it was stored at.
|
// If the invite was successfully stored this returns the stream ID it was stored at.
|
||||||
// Returns an error if there was a problem communicating with the database.
|
// Returns an error if there was a problem communicating with the database.
|
||||||
func (d *Database) AddInviteEvent(
|
func (d *Database) AddInviteEvent(
|
||||||
ctx context.Context, inviteEvent *gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, inviteEvent *rstypes.HeaderedEvent,
|
||||||
) (sp types.StreamPosition, err error) {
|
) (sp types.StreamPosition, err error) {
|
||||||
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
|
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
|
||||||
@ -189,8 +190,8 @@ func (d *Database) UpsertAccountData(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*gomatrixserverlib.HeaderedEvent {
|
func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.StreamEvent) []*rstypes.HeaderedEvent {
|
||||||
out := make([]*gomatrixserverlib.HeaderedEvent, len(in))
|
out := make([]*rstypes.HeaderedEvent, len(in))
|
||||||
for i := 0; i < len(in); i++ {
|
for i := 0; i < len(in); i++ {
|
||||||
out[i] = in[i].HeaderedEvent
|
out[i] = in[i].HeaderedEvent
|
||||||
if device != nil && in[i].TransactionID != nil {
|
if device != nil && in[i].TransactionID != nil {
|
||||||
@ -213,7 +214,7 @@ func (d *Database) StreamEventsToEvents(device *userapi.Device, in []types.Strea
|
|||||||
// the events listed in the event's 'prev_events'. This function also updates the backwards extremities table
|
// the events listed in the event's 'prev_events'. This function also updates the backwards extremities table
|
||||||
// to account for the fact that the given event is no longer a backwards extremity, but may be marked as such.
|
// to account for the fact that the given event is no longer a backwards extremity, but may be marked as such.
|
||||||
// This function should always be called within a sqlutil.Writer for safety in SQLite.
|
// This function should always be called within a sqlutil.Writer for safety in SQLite.
|
||||||
func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, ev *gomatrixserverlib.HeaderedEvent) error {
|
func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, ev *rstypes.HeaderedEvent) error {
|
||||||
if err := d.BackwardExtremities.DeleteBackwardExtremity(ctx, txn, ev.RoomID(), ev.EventID()); err != nil {
|
if err := d.BackwardExtremities.DeleteBackwardExtremity(ctx, txn, ev.RoomID(), ev.EventID()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -246,8 +247,8 @@ func (d *Database) handleBackwardExtremities(ctx context.Context, txn *sql.Tx, e
|
|||||||
|
|
||||||
func (d *Database) WriteEvent(
|
func (d *Database) WriteEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
ev *gomatrixserverlib.HeaderedEvent,
|
ev *rstypes.HeaderedEvent,
|
||||||
addStateEvents []*gomatrixserverlib.HeaderedEvent,
|
addStateEvents []*rstypes.HeaderedEvent,
|
||||||
addStateEventIDs, removeStateEventIDs []string,
|
addStateEventIDs, removeStateEventIDs []string,
|
||||||
transactionID *api.TransactionID, excludeFromSync bool,
|
transactionID *api.TransactionID, excludeFromSync bool,
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility,
|
historyVisibility gomatrixserverlib.HistoryVisibility,
|
||||||
@ -288,7 +289,7 @@ func (d *Database) WriteEvent(
|
|||||||
func (d *Database) updateRoomState(
|
func (d *Database) updateRoomState(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
removedEventIDs []string,
|
removedEventIDs []string,
|
||||||
addedEvents []*gomatrixserverlib.HeaderedEvent,
|
addedEvents []*rstypes.HeaderedEvent,
|
||||||
pduPosition types.StreamPosition,
|
pduPosition types.StreamPosition,
|
||||||
topoPosition types.StreamPosition,
|
topoPosition types.StreamPosition,
|
||||||
) error {
|
) error {
|
||||||
@ -342,7 +343,7 @@ func (d *Database) PutFilter(
|
|||||||
return filterID, err
|
return filterID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) error {
|
func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *rstypes.HeaderedEvent) error {
|
||||||
redactedEvents, err := d.Events(ctx, []string{redactedEventID})
|
redactedEvents, err := d.Events(ctx, []string{redactedEventID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -351,13 +352,13 @@ func (d *Database) RedactEvent(ctx context.Context, redactedEventID string, reda
|
|||||||
logrus.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction")
|
logrus.WithField("event_id", redactedEventID).WithField("redaction_event", redactedBecause.EventID()).Warnf("missing redacted event for redaction")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
eventToRedact := redactedEvents[0].Unwrap()
|
eventToRedact := redactedEvents[0].Event
|
||||||
redactionEvent := redactedBecause.Unwrap()
|
redactionEvent := redactedBecause.Event
|
||||||
if err = eventutil.RedactEvent(redactionEvent, eventToRedact); err != nil {
|
if err = eventutil.RedactEvent(redactionEvent, eventToRedact); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
newEvent := eventToRedact.Headered(redactedBecause.RoomVersion)
|
newEvent := &rstypes.HeaderedEvent{Event: eventToRedact}
|
||||||
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
return d.OutputEvents.UpdateEventJSON(ctx, txn, newEvent)
|
return d.OutputEvents.UpdateEventJSON(ctx, txn, newEvent)
|
||||||
})
|
})
|
||||||
@ -521,14 +522,14 @@ func (d *Database) UpsertRoomUnreadNotificationCounts(ctx context.Context, userI
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) SelectContextEvent(ctx context.Context, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) SelectContextEvent(ctx context.Context, roomID, eventID string) (int, rstypes.HeaderedEvent, error) {
|
||||||
return d.OutputEvents.SelectContextEvent(ctx, nil, roomID, eventID)
|
return d.OutputEvents.SelectContextEvent(ctx, nil, roomID, eventID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*rstypes.HeaderedEvent, error) {
|
||||||
return d.OutputEvents.SelectContextBeforeEvent(ctx, nil, id, roomID, filter)
|
return d.OutputEvents.SelectContextBeforeEvent(ctx, nil, id, roomID, filter)
|
||||||
}
|
}
|
||||||
func (d *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*rstypes.HeaderedEvent, error) {
|
||||||
return d.OutputEvents.SelectContextAfterEvent(ctx, nil, id, roomID, filter)
|
return d.OutputEvents.SelectContextAfterEvent(ctx, nil, id, roomID, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +561,7 @@ func (d *Database) SelectMembershipForUser(ctx context.Context, roomID, userID s
|
|||||||
return d.Memberships.SelectMembershipForUser(ctx, nil, roomID, userID, pos)
|
return d.Memberships.SelectMembershipForUser(ctx, nil, roomID, userID, pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
|
func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]rstypes.HeaderedEvent, error) {
|
||||||
return d.OutputEvents.ReIndex(ctx, nil, limit, afterID, []string{
|
return d.OutputEvents.ReIndex(ctx, nil, limit, afterID, []string{
|
||||||
spec.MRoomName,
|
spec.MRoomName,
|
||||||
spec.MRoomTopic,
|
spec.MRoomTopic,
|
||||||
@ -568,7 +569,7 @@ func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error {
|
func (d *Database) UpdateRelations(ctx context.Context, event *rstypes.HeaderedEvent) error {
|
||||||
// No need to unmarshal if the event is a redaction
|
// No need to unmarshal if the event is a redaction
|
||||||
if event.Type() == spec.MRoomRedaction {
|
if event.Type() == spec.MRoomRedaction {
|
||||||
return nil
|
return nil
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||||
@ -84,7 +84,7 @@ func (d *DatabaseTransaction) MaxStreamPositionForNotificationData(ctx context.C
|
|||||||
return types.StreamPosition(id), nil
|
return types.StreamPosition(id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DatabaseTransaction) CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *DatabaseTransaction) CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*rstypes.HeaderedEvent, error) {
|
||||||
return d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilterPart, excludeEventIDs)
|
return d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilterPart, excludeEventIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ func (d *DatabaseTransaction) PositionInTopology(ctx context.Context, eventID st
|
|||||||
return d.Topology.SelectPositionInTopology(ctx, d.txn, eventID)
|
return d.Topology.SelectPositionInTopology(ctx, d.txn, eventID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DatabaseTransaction) InviteEventsInRange(ctx context.Context, targetUserID string, r types.Range) (map[string]*gomatrixserverlib.HeaderedEvent, map[string]*gomatrixserverlib.HeaderedEvent, types.StreamPosition, error) {
|
func (d *DatabaseTransaction) InviteEventsInRange(ctx context.Context, targetUserID string, r types.Range) (map[string]*rstypes.HeaderedEvent, map[string]*rstypes.HeaderedEvent, types.StreamPosition, error) {
|
||||||
return d.Invites.SelectInviteEventsInRange(ctx, d.txn, targetUserID, r)
|
return d.Invites.SelectInviteEventsInRange(ctx, d.txn, targetUserID, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ func (d *DatabaseTransaction) RoomReceiptsAfter(ctx context.Context, roomIDs []s
|
|||||||
// If an event is not found in the database then it will be omitted from the list.
|
// If an event is not found in the database then it will be omitted from the list.
|
||||||
// Returns an error if there was a problem talking with the database.
|
// Returns an error if there was a problem talking with the database.
|
||||||
// Does not include any transaction IDs in the returned events.
|
// Does not include any transaction IDs in the returned events.
|
||||||
func (d *DatabaseTransaction) Events(ctx context.Context, eventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func (d *DatabaseTransaction) Events(ctx context.Context, eventIDs []string) ([]*rstypes.HeaderedEvent, error) {
|
||||||
streamEvents, err := d.OutputEvents.SelectEvents(ctx, d.txn, eventIDs, nil, false)
|
streamEvents, err := d.OutputEvents.SelectEvents(ctx, d.txn, eventIDs, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -207,13 +207,13 @@ func (d *DatabaseTransaction) SharedUsers(ctx context.Context, userID string, ot
|
|||||||
|
|
||||||
func (d *DatabaseTransaction) GetStateEvent(
|
func (d *DatabaseTransaction) GetStateEvent(
|
||||||
ctx context.Context, roomID, evType, stateKey string,
|
ctx context.Context, roomID, evType, stateKey string,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*rstypes.HeaderedEvent, error) {
|
||||||
return d.CurrentRoomState.SelectStateEvent(ctx, d.txn, roomID, evType, stateKey)
|
return d.CurrentRoomState.SelectStateEvent(ctx, d.txn, roomID, evType, stateKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DatabaseTransaction) GetStateEventsForRoom(
|
func (d *DatabaseTransaction) GetStateEventsForRoom(
|
||||||
ctx context.Context, roomID string, stateFilter *synctypes.StateFilter,
|
ctx context.Context, roomID string, stateFilter *synctypes.StateFilter,
|
||||||
) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (stateEvents []*rstypes.HeaderedEvent, err error) {
|
||||||
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilter, nil)
|
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilter, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ func (d *DatabaseTransaction) StreamToTopologicalPosition(
|
|||||||
// oldest event in the room's topology.
|
// oldest event in the room's topology.
|
||||||
func (d *DatabaseTransaction) GetBackwardTopologyPos(
|
func (d *DatabaseTransaction) GetBackwardTopologyPos(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
events []*gomatrixserverlib.HeaderedEvent,
|
events []*rstypes.HeaderedEvent,
|
||||||
) (types.TopologyToken, error) {
|
) (types.TopologyToken, error) {
|
||||||
zeroToken := types.TopologyToken{}
|
zeroToken := types.TopologyToken{}
|
||||||
if len(events) == 0 {
|
if len(events) == 0 {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -268,7 +269,7 @@ func (s *currentRoomStateStatements) SelectCurrentState(
|
|||||||
ctx context.Context, txn *sql.Tx, roomID string,
|
ctx context.Context, txn *sql.Tx, roomID string,
|
||||||
stateFilter *synctypes.StateFilter,
|
stateFilter *synctypes.StateFilter,
|
||||||
excludeEventIDs []string,
|
excludeEventIDs []string,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*rstypes.HeaderedEvent, error) {
|
||||||
// We're going to query members later, so remove them from this request
|
// We're going to query members later, so remove them from this request
|
||||||
if stateFilter.LazyLoadMembers && !stateFilter.IncludeRedundantMembers {
|
if stateFilter.LazyLoadMembers && !stateFilter.IncludeRedundantMembers {
|
||||||
notTypes := &[]string{spec.MRoomMember}
|
notTypes := &[]string{spec.MRoomMember}
|
||||||
@ -319,7 +320,7 @@ func (s *currentRoomStateStatements) DeleteRoomStateForRoom(
|
|||||||
|
|
||||||
func (s *currentRoomStateStatements) UpsertRoomState(
|
func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
event *gomatrixserverlib.HeaderedEvent, membership *string, addedAt types.StreamPosition,
|
event *rstypes.HeaderedEvent, membership *string, addedAt types.StreamPosition,
|
||||||
) error {
|
) error {
|
||||||
// Parse content as JSON and search for an "url" key
|
// Parse content as JSON and search for an "url" key
|
||||||
containsURL := false
|
containsURL := false
|
||||||
@ -405,8 +406,8 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,8 +422,8 @@ func currentRoomStateRowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, er
|
|||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
func rowsToEvents(rows *sql.Rows) ([]*rstypes.HeaderedEvent, error) {
|
||||||
result := []*gomatrixserverlib.HeaderedEvent{}
|
result := []*rstypes.HeaderedEvent{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var eventID string
|
var eventID string
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
@ -430,8 +431,8 @@ func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, &ev)
|
result = append(result, &ev)
|
||||||
@ -441,7 +442,7 @@ func rowsToEvents(rows *sql.Rows) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
|||||||
|
|
||||||
func (s *currentRoomStateStatements) SelectStateEvent(
|
func (s *currentRoomStateStatements) SelectStateEvent(
|
||||||
ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string,
|
ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string,
|
||||||
) (*gomatrixserverlib.HeaderedEvent, error) {
|
) (*rstypes.HeaderedEvent, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.selectStateEventStmt)
|
stmt := sqlutil.TxStmt(txn, s.selectStateEventStmt)
|
||||||
var res []byte
|
var res []byte
|
||||||
err := stmt.QueryRowContext(ctx, roomID, evType, stateKey).Scan(&res)
|
err := stmt.QueryRowContext(ctx, roomID, evType, stateKey).Scan(&res)
|
||||||
@ -451,7 +452,7 @@ func (s *currentRoomStateStatements) SelectStateEvent(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err = json.Unmarshal(res, &ev); err != nil {
|
if err = json.Unmarshal(res, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ func currentHistoryVisibilities(ctx context.Context, tx *sql.Tx) (map[string]gom
|
|||||||
defer rows.Close() // nolint: errcheck
|
defer rows.Close() // nolint: errcheck
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
var roomID string
|
var roomID string
|
||||||
var event gomatrixserverlib.HeaderedEvent
|
var event types.HeaderedEvent
|
||||||
var hisVis gomatrixserverlib.HistoryVisibility
|
var hisVis gomatrixserverlib.HistoryVisibility
|
||||||
historyVisibilities := make(map[string]gomatrixserverlib.HistoryVisibility)
|
historyVisibilities := make(map[string]gomatrixserverlib.HistoryVisibility)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
@ -22,9 +22,9 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const inviteEventsSchema = `
|
const inviteEventsSchema = `
|
||||||
@ -89,7 +89,7 @@ func NewSqliteInvitesTable(db *sql.DB, streamID *StreamIDStatements) (tables.Inv
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *inviteEventsStatements) InsertInviteEvent(
|
func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
ctx context.Context, txn *sql.Tx, inviteEvent *gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, txn *sql.Tx, inviteEvent *rstypes.HeaderedEvent,
|
||||||
) (streamPos types.StreamPosition, err error) {
|
) (streamPos types.StreamPosition, err error) {
|
||||||
streamPos, err = s.streamIDStatements.nextInviteID(ctx, txn)
|
streamPos, err = s.streamIDStatements.nextInviteID(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -130,7 +130,7 @@ func (s *inviteEventsStatements) DeleteInviteEvent(
|
|||||||
// active invites for the target user ID in the supplied range.
|
// active invites for the target user ID in the supplied range.
|
||||||
func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
||||||
ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range,
|
ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range,
|
||||||
) (map[string]*gomatrixserverlib.HeaderedEvent, map[string]*gomatrixserverlib.HeaderedEvent, types.StreamPosition, error) {
|
) (map[string]*rstypes.HeaderedEvent, map[string]*rstypes.HeaderedEvent, types.StreamPosition, error) {
|
||||||
var lastPos types.StreamPosition
|
var lastPos types.StreamPosition
|
||||||
stmt := sqlutil.TxStmt(txn, s.selectInviteEventsInRangeStmt)
|
stmt := sqlutil.TxStmt(txn, s.selectInviteEventsInRangeStmt)
|
||||||
rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High())
|
rows, err := stmt.QueryContext(ctx, targetUserID, r.Low(), r.High())
|
||||||
@ -138,8 +138,8 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
|||||||
return nil, nil, lastPos, err
|
return nil, nil, lastPos, err
|
||||||
}
|
}
|
||||||
defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
|
defer internal.CloseAndLogIfError(ctx, rows, "selectInviteEventsInRange: rows.close() failed")
|
||||||
result := map[string]*gomatrixserverlib.HeaderedEvent{}
|
result := map[string]*rstypes.HeaderedEvent{}
|
||||||
retired := map[string]*gomatrixserverlib.HeaderedEvent{}
|
retired := map[string]*rstypes.HeaderedEvent{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
id types.StreamPosition
|
id types.StreamPosition
|
||||||
@ -162,7 +162,7 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var event *gomatrixserverlib.HeaderedEvent
|
var event *rstypes.HeaderedEvent
|
||||||
if err := json.Unmarshal(eventJSON, &event); err != nil {
|
if err := json.Unmarshal(eventJSON, &event); err != nil {
|
||||||
return nil, nil, lastPos, err
|
return nil, nil, lastPos, err
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,8 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
)
|
)
|
||||||
@ -103,7 +102,7 @@ func NewSqliteMembershipsTable(db *sql.DB) (tables.Memberships, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *membershipsStatements) UpsertMembership(
|
func (s *membershipsStatements) UpsertMembership(
|
||||||
ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent,
|
||||||
streamPos, topologicalPos types.StreamPosition,
|
streamPos, topologicalPos types.StreamPosition,
|
||||||
) error {
|
) error {
|
||||||
membership, err := event.Membership()
|
membership, err := event.Membership()
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -166,7 +167,7 @@ func NewSqliteEventsTable(db *sql.DB, streamID *StreamIDStatements) (tables.Even
|
|||||||
}.Prepare(db)
|
}.Prepare(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent) error {
|
func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent) error {
|
||||||
headeredJSON, err := json.Marshal(event)
|
headeredJSON, err := json.Marshal(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -249,8 +250,8 @@ func (s *outputRoomEventsStatements) SelectStateInRange(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
needSet := stateNeeded[ev.RoomID()]
|
needSet := stateNeeded[ev.RoomID()]
|
||||||
@ -296,7 +297,7 @@ func (s *outputRoomEventsStatements) SelectMaxEventID(
|
|||||||
// of the inserted event.
|
// of the inserted event.
|
||||||
func (s *outputRoomEventsStatements) InsertEvent(
|
func (s *outputRoomEventsStatements) InsertEvent(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
event *gomatrixserverlib.HeaderedEvent, addState, removeState []string,
|
event *rstypes.HeaderedEvent, addState, removeState []string,
|
||||||
transactionID *api.TransactionID, excludeFromSync bool, historyVisibility gomatrixserverlib.HistoryVisibility,
|
transactionID *api.TransactionID, excludeFromSync bool, historyVisibility gomatrixserverlib.HistoryVisibility,
|
||||||
) (types.StreamPosition, error) {
|
) (types.StreamPosition, error) {
|
||||||
var txnID *string
|
var txnID *string
|
||||||
@ -498,8 +499,8 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// TODO: Handle redacted events
|
// TODO: Handle redacted events
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
if err := ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err := json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +524,7 @@ func rowsToStreamEvents(rows *sql.Rows) ([]types.StreamEvent, error) {
|
|||||||
}
|
}
|
||||||
func (s *outputRoomEventsStatements) SelectContextEvent(
|
func (s *outputRoomEventsStatements) SelectContextEvent(
|
||||||
ctx context.Context, txn *sql.Tx, roomID, eventID string,
|
ctx context.Context, txn *sql.Tx, roomID, eventID string,
|
||||||
) (id int, evt gomatrixserverlib.HeaderedEvent, err error) {
|
) (id int, evt rstypes.HeaderedEvent, err error) {
|
||||||
row := sqlutil.TxStmt(txn, s.selectContextEventStmt).QueryRowContext(ctx, roomID, eventID)
|
row := sqlutil.TxStmt(txn, s.selectContextEventStmt).QueryRowContext(ctx, roomID, eventID)
|
||||||
var eventAsString string
|
var eventAsString string
|
||||||
var historyVisibility gomatrixserverlib.HistoryVisibility
|
var historyVisibility gomatrixserverlib.HistoryVisibility
|
||||||
@ -540,7 +541,7 @@ func (s *outputRoomEventsStatements) SelectContextEvent(
|
|||||||
|
|
||||||
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||||
) (evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (evts []*rstypes.HeaderedEvent, err error) {
|
||||||
stmt, params, err := prepareWithFilters(
|
stmt, params, err := prepareWithFilters(
|
||||||
s.db, txn, selectContextBeforeEventSQL,
|
s.db, txn, selectContextBeforeEventSQL,
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -564,7 +565,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
eventBytes []byte
|
eventBytes []byte
|
||||||
evt *gomatrixserverlib.HeaderedEvent
|
evt *rstypes.HeaderedEvent
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility
|
historyVisibility gomatrixserverlib.HistoryVisibility
|
||||||
)
|
)
|
||||||
if err = rows.Scan(&eventBytes, &historyVisibility); err != nil {
|
if err = rows.Scan(&eventBytes, &historyVisibility); err != nil {
|
||||||
@ -582,7 +583,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||||||
|
|
||||||
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||||
) (lastID int, evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
) (lastID int, evts []*rstypes.HeaderedEvent, err error) {
|
||||||
stmt, params, err := prepareWithFilters(
|
stmt, params, err := prepareWithFilters(
|
||||||
s.db, txn, selectContextAfterEventSQL,
|
s.db, txn, selectContextAfterEventSQL,
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -606,7 +607,7 @@ func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
eventBytes []byte
|
eventBytes []byte
|
||||||
evt *gomatrixserverlib.HeaderedEvent
|
evt *rstypes.HeaderedEvent
|
||||||
historyVisibility gomatrixserverlib.HistoryVisibility
|
historyVisibility gomatrixserverlib.HistoryVisibility
|
||||||
)
|
)
|
||||||
if err = rows.Scan(&lastID, &eventBytes, &historyVisibility); err != nil {
|
if err = rows.Scan(&lastID, &eventBytes, &historyVisibility); err != nil {
|
||||||
@ -642,7 +643,7 @@ func (s *outputRoomEventsStatements) PurgeEvents(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, limit, afterID int64, types []string) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
|
func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, limit, afterID int64, types []string) (map[int64]rstypes.HeaderedEvent, error) {
|
||||||
params := make([]interface{}, len(types)+1)
|
params := make([]interface{}, len(types)+1)
|
||||||
params[0] = afterID
|
params[0] = afterID
|
||||||
for i := range types {
|
for i := range types {
|
||||||
@ -664,14 +665,14 @@ func (s *outputRoomEventsStatements) ReIndex(ctx context.Context, txn *sql.Tx, l
|
|||||||
|
|
||||||
var eventID string
|
var eventID string
|
||||||
var id int64
|
var id int64
|
||||||
result := make(map[int64]gomatrixserverlib.HeaderedEvent)
|
result := make(map[int64]rstypes.HeaderedEvent)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var ev gomatrixserverlib.HeaderedEvent
|
var ev rstypes.HeaderedEvent
|
||||||
var eventBytes []byte
|
var eventBytes []byte
|
||||||
if err = rows.Scan(&id, &eventID, &eventBytes); err != nil {
|
if err = rows.Scan(&id, &eventID, &eventBytes); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = ev.UnmarshalJSONWithEventID(eventBytes, eventID); err != nil {
|
if err = json.Unmarshal(eventBytes, &ev); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result[id] = ev
|
result[id] = ev
|
||||||
|
@ -18,9 +18,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
)
|
)
|
||||||
@ -104,7 +103,7 @@ func NewSqliteTopologyTable(db *sql.DB) (tables.Topology, error) {
|
|||||||
// insertEventInTopology inserts the given event in the room's topology, based
|
// insertEventInTopology inserts the given event in the room's topology, based
|
||||||
// on the event's depth.
|
// on the event's depth.
|
||||||
func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
func (s *outputRoomEventsTopologyStatements) InsertEventInTopology(
|
||||||
ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, pos types.StreamPosition,
|
ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition,
|
||||||
) (types.StreamPosition, error) {
|
) (types.StreamPosition, error) {
|
||||||
_, err := sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).ExecContext(
|
_, err := sqlutil.TxStmt(txn, s.insertEventInTopologyStmt).ExecContext(
|
||||||
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
ctx, event.EventID(), event.Depth(), event.RoomID(), pos,
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -34,9 +35,9 @@ func MustCreateDatabase(t *testing.T, dbType test.DBType) (storage.Database, fun
|
|||||||
return db, close
|
return db, close
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustWriteEvents(t *testing.T, db storage.Database, events []*gomatrixserverlib.HeaderedEvent) (positions []types.StreamPosition) {
|
func MustWriteEvents(t *testing.T, db storage.Database, events []*rstypes.HeaderedEvent) (positions []types.StreamPosition) {
|
||||||
for _, ev := range events {
|
for _, ev := range events {
|
||||||
var addStateEvents []*gomatrixserverlib.HeaderedEvent
|
var addStateEvents []*rstypes.HeaderedEvent
|
||||||
var addStateEventIDs []string
|
var addStateEventIDs []string
|
||||||
var removeStateEventIDs []string
|
var removeStateEventIDs []string
|
||||||
if ev.StateKey() != nil {
|
if ev.StateKey() != nil {
|
||||||
@ -106,7 +107,7 @@ func TestRecentEventsPDU(t *testing.T) {
|
|||||||
To types.StreamPosition
|
To types.StreamPosition
|
||||||
Limit int
|
Limit int
|
||||||
ReverseOrder bool
|
ReverseOrder bool
|
||||||
WantEvents []*gomatrixserverlib.HeaderedEvent
|
WantEvents []*rstypes.HeaderedEvent
|
||||||
WantLimited bool
|
WantLimited bool
|
||||||
}{
|
}{
|
||||||
// The purpose of this test is to make sure that incremental syncs are including up to the latest events.
|
// The purpose of this test is to make sure that incremental syncs are including up to the latest events.
|
||||||
@ -316,7 +317,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
db := MustCreateDatabase(t)
|
db := MustCreateDatabase(t)
|
||||||
|
|
||||||
var events []*gomatrixserverlib.HeaderedEvent
|
var events []*types.HeaderedEvent
|
||||||
events = append(events, MustCreateEvent(t, testRoomID, nil, &gomatrixserverlib.EventBuilder{
|
events = append(events, MustCreateEvent(t, testRoomID, nil, &gomatrixserverlib.EventBuilder{
|
||||||
Content: []byte(fmt.Sprintf(`{"room_version":"4","creator":"%s"}`, testUserIDA)),
|
Content: []byte(fmt.Sprintf(`{"room_version":"4","creator":"%s"}`, testUserIDA)),
|
||||||
Type: "m.room.create",
|
Type: "m.room.create",
|
||||||
@ -324,7 +325,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
|
|||||||
Sender: testUserIDA,
|
Sender: testUserIDA,
|
||||||
Depth: int64(len(events) + 1),
|
Depth: int64(len(events) + 1),
|
||||||
}))
|
}))
|
||||||
events = append(events, MustCreateEvent(t, testRoomID, []*gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
events = append(events, MustCreateEvent(t, testRoomID, []*types.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
||||||
Content: []byte(`{"membership":"join"}`),
|
Content: []byte(`{"membership":"join"}`),
|
||||||
Type: "m.room.member",
|
Type: "m.room.member",
|
||||||
StateKey: &testUserIDA,
|
StateKey: &testUserIDA,
|
||||||
@ -332,7 +333,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
|
|||||||
Depth: int64(len(events) + 1),
|
Depth: int64(len(events) + 1),
|
||||||
}))
|
}))
|
||||||
// fork the dag into three, same prev_events and depth
|
// fork the dag into three, same prev_events and depth
|
||||||
parent := []*gomatrixserverlib.HeaderedEvent{events[len(events)-1]}
|
parent := []*types.HeaderedEvent{events[len(events)-1]}
|
||||||
depth := int64(len(events) + 1)
|
depth := int64(len(events) + 1)
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
events = append(events, MustCreateEvent(t, testRoomID, parent, &gomatrixserverlib.EventBuilder{
|
events = append(events, MustCreateEvent(t, testRoomID, parent, &gomatrixserverlib.EventBuilder{
|
||||||
@ -365,7 +366,7 @@ func TestGetEventsInRangeWithEventsSameDepth(t *testing.T) {
|
|||||||
Name string
|
Name string
|
||||||
From types.TopologyToken
|
From types.TopologyToken
|
||||||
Limit int
|
Limit int
|
||||||
Wants []*gomatrixserverlib.HeaderedEvent
|
Wants []*types.HeaderedEvent
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Pagination over the whole fork",
|
Name: "Pagination over the whole fork",
|
||||||
@ -406,7 +407,7 @@ func TestGetEventsInTopologicalRangeMultiRoom(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
db := MustCreateDatabase(t)
|
db := MustCreateDatabase(t)
|
||||||
|
|
||||||
makeEvents := func(roomID string) (events []*gomatrixserverlib.HeaderedEvent) {
|
makeEvents := func(roomID string) (events []*types.HeaderedEvent) {
|
||||||
events = append(events, MustCreateEvent(t, roomID, nil, &gomatrixserverlib.EventBuilder{
|
events = append(events, MustCreateEvent(t, roomID, nil, &gomatrixserverlib.EventBuilder{
|
||||||
Content: []byte(fmt.Sprintf(`{"room_version":"4","creator":"%s"}`, testUserIDA)),
|
Content: []byte(fmt.Sprintf(`{"room_version":"4","creator":"%s"}`, testUserIDA)),
|
||||||
Type: "m.room.create",
|
Type: "m.room.create",
|
||||||
@ -414,7 +415,7 @@ func TestGetEventsInTopologicalRangeMultiRoom(t *testing.T) {
|
|||||||
Sender: testUserIDA,
|
Sender: testUserIDA,
|
||||||
Depth: int64(len(events) + 1),
|
Depth: int64(len(events) + 1),
|
||||||
}))
|
}))
|
||||||
events = append(events, MustCreateEvent(t, roomID, []*gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
events = append(events, MustCreateEvent(t, roomID, []*types.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
||||||
Content: []byte(`{"membership":"join"}`),
|
Content: []byte(`{"membership":"join"}`),
|
||||||
Type: "m.room.member",
|
Type: "m.room.member",
|
||||||
StateKey: &testUserIDA,
|
StateKey: &testUserIDA,
|
||||||
@ -460,14 +461,14 @@ func TestGetEventsInRangeWithEventsInsertedLikeBackfill(t *testing.T) {
|
|||||||
|
|
||||||
// "federation" join
|
// "federation" join
|
||||||
userC := fmt.Sprintf("@radiance:%s", testOrigin)
|
userC := fmt.Sprintf("@radiance:%s", testOrigin)
|
||||||
joinEvent := MustCreateEvent(t, testRoomID, []*gomatrixserverlib.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
joinEvent := MustCreateEvent(t, testRoomID, []*types.HeaderedEvent{events[len(events)-1]}, &gomatrixserverlib.EventBuilder{
|
||||||
Content: []byte(`{"membership":"join"}`),
|
Content: []byte(`{"membership":"join"}`),
|
||||||
Type: "m.room.member",
|
Type: "m.room.member",
|
||||||
StateKey: &userC,
|
StateKey: &userC,
|
||||||
Sender: userC,
|
Sender: userC,
|
||||||
Depth: int64(len(events) + 1),
|
Depth: int64(len(events) + 1),
|
||||||
})
|
})
|
||||||
MustWriteEvents(t, db, []*gomatrixserverlib.HeaderedEvent{joinEvent})
|
MustWriteEvents(t, db, []*types.HeaderedEvent{joinEvent})
|
||||||
|
|
||||||
// Sync will return this for the prev_batch
|
// Sync will return this for the prev_batch
|
||||||
from := topologyTokenBefore(t, db, joinEvent.EventID())
|
from := topologyTokenBefore(t, db, joinEvent.EventID())
|
||||||
@ -638,7 +639,7 @@ func TestInviteBehaviour(t *testing.T) {
|
|||||||
StateKey: &testUserIDA,
|
StateKey: &testUserIDA,
|
||||||
Sender: "@inviteUser2:somewhere",
|
Sender: "@inviteUser2:somewhere",
|
||||||
})
|
})
|
||||||
for _, ev := range []*gomatrixserverlib.HeaderedEvent{inviteEvent1, inviteEvent2} {
|
for _, ev := range []*types.HeaderedEvent{inviteEvent1, inviteEvent2} {
|
||||||
_, err := db.AddInviteEvent(ctx, ev)
|
_, err := db.AddInviteEvent(ctx, ev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to AddInviteEvent: %s", err)
|
t.Fatalf("Failed to AddInviteEvent: %s", err)
|
||||||
@ -695,7 +696,7 @@ func assertInvitedToRooms(t *testing.T, res *types.Response, roomIDs []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertEventsEqual(t *testing.T, msg string, checkRoomID bool, gots []gomatrixserverlib.ClientEvent, wants []*gomatrixserverlib.HeaderedEvent) {
|
func assertEventsEqual(t *testing.T, msg string, checkRoomID bool, gots []gomatrixserverlib.ClientEvent, wants []*types.HeaderedEvent) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if len(gots) != len(wants) {
|
if len(gots) != len(wants) {
|
||||||
t.Fatalf("%s response returned %d events, want %d", msg, len(gots), len(wants))
|
t.Fatalf("%s response returned %d events, want %d", msg, len(gots), len(wants))
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
)
|
)
|
||||||
@ -35,11 +36,11 @@ type AccountData interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Invites interface {
|
type Invites interface {
|
||||||
InsertInviteEvent(ctx context.Context, txn *sql.Tx, inviteEvent *gomatrixserverlib.HeaderedEvent) (streamPos types.StreamPosition, err error)
|
InsertInviteEvent(ctx context.Context, txn *sql.Tx, inviteEvent *rstypes.HeaderedEvent) (streamPos types.StreamPosition, err error)
|
||||||
DeleteInviteEvent(ctx context.Context, txn *sql.Tx, inviteEventID string) (types.StreamPosition, error)
|
DeleteInviteEvent(ctx context.Context, txn *sql.Tx, inviteEventID string) (types.StreamPosition, error)
|
||||||
// SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
|
// SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
|
||||||
// for the room.
|
// for the room.
|
||||||
SelectInviteEventsInRange(ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range) (invites map[string]*gomatrixserverlib.HeaderedEvent, retired map[string]*gomatrixserverlib.HeaderedEvent, maxID types.StreamPosition, err error)
|
SelectInviteEventsInRange(ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range) (invites map[string]*rstypes.HeaderedEvent, retired map[string]*rstypes.HeaderedEvent, maxID types.StreamPosition, err error)
|
||||||
SelectMaxInviteID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
SelectMaxInviteID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
||||||
PurgeInvites(ctx context.Context, txn *sql.Tx, roomID string) error
|
PurgeInvites(ctx context.Context, txn *sql.Tx, roomID string) error
|
||||||
}
|
}
|
||||||
@ -59,7 +60,7 @@ type Events interface {
|
|||||||
SelectMaxEventID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
SelectMaxEventID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
||||||
InsertEvent(
|
InsertEvent(
|
||||||
ctx context.Context, txn *sql.Tx,
|
ctx context.Context, txn *sql.Tx,
|
||||||
event *gomatrixserverlib.HeaderedEvent,
|
event *rstypes.HeaderedEvent,
|
||||||
addState, removeState []string,
|
addState, removeState []string,
|
||||||
transactionID *api.TransactionID,
|
transactionID *api.TransactionID,
|
||||||
excludeFromSync bool,
|
excludeFromSync bool,
|
||||||
@ -70,16 +71,16 @@ type Events interface {
|
|||||||
// Returns up to `limit` events. Returns `limited=true` if there are more events in this range but we hit the `limit`.
|
// Returns up to `limit` events. Returns `limited=true` if there are more events in this range but we hit the `limit`.
|
||||||
SelectRecentEvents(ctx context.Context, txn *sql.Tx, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error)
|
SelectRecentEvents(ctx context.Context, txn *sql.Tx, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error)
|
||||||
SelectEvents(ctx context.Context, txn *sql.Tx, eventIDs []string, filter *synctypes.RoomEventFilter, preserveOrder bool) ([]types.StreamEvent, error)
|
SelectEvents(ctx context.Context, txn *sql.Tx, eventIDs []string, filter *synctypes.RoomEventFilter, preserveOrder bool) ([]types.StreamEvent, error)
|
||||||
UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent) error
|
UpdateEventJSON(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent) error
|
||||||
// DeleteEventsForRoom removes all event information for a room. This should only be done when removing the room entirely.
|
// DeleteEventsForRoom removes all event information for a room. This should only be done when removing the room entirely.
|
||||||
DeleteEventsForRoom(ctx context.Context, txn *sql.Tx, roomID string) (err error)
|
DeleteEventsForRoom(ctx context.Context, txn *sql.Tx, roomID string) (err error)
|
||||||
|
|
||||||
SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (int, rstypes.HeaderedEvent, error)
|
||||||
SelectContextBeforeEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
SelectContextBeforeEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*rstypes.HeaderedEvent, error)
|
||||||
SelectContextAfterEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
SelectContextAfterEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*rstypes.HeaderedEvent, error)
|
||||||
|
|
||||||
PurgeEvents(ctx context.Context, txn *sql.Tx, roomID string) error
|
PurgeEvents(ctx context.Context, txn *sql.Tx, roomID string) error
|
||||||
ReIndex(ctx context.Context, txn *sql.Tx, limit, offset int64, types []string) (map[int64]gomatrixserverlib.HeaderedEvent, error)
|
ReIndex(ctx context.Context, txn *sql.Tx, limit, offset int64, types []string) (map[int64]rstypes.HeaderedEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Topology keeps track of the depths and stream positions for all events.
|
// Topology keeps track of the depths and stream positions for all events.
|
||||||
@ -87,7 +88,7 @@ type Events interface {
|
|||||||
type Topology interface {
|
type Topology interface {
|
||||||
// InsertEventInTopology inserts the given event in the room's topology, based on the event's depth.
|
// InsertEventInTopology inserts the given event in the room's topology, based on the event's depth.
|
||||||
// `pos` is the stream position of this event in the events table, and is used to order events which have the same depth.
|
// `pos` is the stream position of this event in the events table, and is used to order events which have the same depth.
|
||||||
InsertEventInTopology(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, pos types.StreamPosition) (topoPos types.StreamPosition, err error)
|
InsertEventInTopology(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, pos types.StreamPosition) (topoPos types.StreamPosition, err error)
|
||||||
// SelectEventIDsInRange selects the IDs of events whose depths are within a given range in a given room's topological order.
|
// SelectEventIDsInRange selects the IDs of events whose depths are within a given range in a given room's topological order.
|
||||||
// Events with `minDepth` are *exclusive*, as is the event which has exactly `minDepth`,`maxStreamPos`.
|
// Events with `minDepth` are *exclusive*, as is the event which has exactly `minDepth`,`maxStreamPos`.
|
||||||
// `maxStreamPos` is only used when events have the same depth as `maxDepth`, which results in events less than `maxStreamPos` being returned.
|
// `maxStreamPos` is only used when events have the same depth as `maxDepth`, which results in events less than `maxStreamPos` being returned.
|
||||||
@ -101,13 +102,13 @@ type Topology interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CurrentRoomState interface {
|
type CurrentRoomState interface {
|
||||||
SelectStateEvent(ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string) (*gomatrixserverlib.HeaderedEvent, error)
|
SelectStateEvent(ctx context.Context, txn *sql.Tx, roomID, evType, stateKey string) (*rstypes.HeaderedEvent, error)
|
||||||
SelectEventsWithEventIDs(ctx context.Context, txn *sql.Tx, eventIDs []string) ([]types.StreamEvent, error)
|
SelectEventsWithEventIDs(ctx context.Context, txn *sql.Tx, eventIDs []string) ([]types.StreamEvent, error)
|
||||||
UpsertRoomState(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, membership *string, addedAt types.StreamPosition) error
|
UpsertRoomState(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, membership *string, addedAt types.StreamPosition) error
|
||||||
DeleteRoomStateByEventID(ctx context.Context, txn *sql.Tx, eventID string) error
|
DeleteRoomStateByEventID(ctx context.Context, txn *sql.Tx, eventID string) error
|
||||||
DeleteRoomStateForRoom(ctx context.Context, txn *sql.Tx, roomID string) error
|
DeleteRoomStateForRoom(ctx context.Context, txn *sql.Tx, roomID string) error
|
||||||
// SelectCurrentState returns all the current state events for the given room.
|
// SelectCurrentState returns all the current state events for the given room.
|
||||||
SelectCurrentState(ctx context.Context, txn *sql.Tx, roomID string, stateFilter *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
SelectCurrentState(ctx context.Context, txn *sql.Tx, roomID string, stateFilter *synctypes.StateFilter, excludeEventIDs []string) ([]*rstypes.HeaderedEvent, error)
|
||||||
// SelectRoomIDsWithMembership returns the list of room IDs which have the given user in the given membership state.
|
// SelectRoomIDsWithMembership returns the list of room IDs which have the given user in the given membership state.
|
||||||
SelectRoomIDsWithMembership(ctx context.Context, txn *sql.Tx, userID string, membership string) ([]string, error)
|
SelectRoomIDsWithMembership(ctx context.Context, txn *sql.Tx, userID string, membership string) ([]string, error)
|
||||||
// SelectRoomIDsWithAnyMembership returns a map of all memberships for the given user.
|
// SelectRoomIDsWithAnyMembership returns a map of all memberships for the given user.
|
||||||
@ -191,7 +192,7 @@ type Receipts interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Memberships interface {
|
type Memberships interface {
|
||||||
UpsertMembership(ctx context.Context, txn *sql.Tx, event *gomatrixserverlib.HeaderedEvent, streamPos, topologicalPos types.StreamPosition) error
|
UpsertMembership(ctx context.Context, txn *sql.Tx, event *rstypes.HeaderedEvent, streamPos, topologicalPos types.StreamPosition) error
|
||||||
SelectMembershipCount(ctx context.Context, txn *sql.Tx, roomID, membership string, pos types.StreamPosition) (count int, err error)
|
SelectMembershipCount(ctx context.Context, txn *sql.Tx, roomID, membership string, pos types.StreamPosition) (count int, err error)
|
||||||
SelectMembershipForUser(ctx context.Context, txn *sql.Tx, roomID, userID string, pos int64) (membership string, topologicalPos int, err error)
|
SelectMembershipForUser(ctx context.Context, txn *sql.Tx, roomID, userID string, pos int64) (membership string, topologicalPos int, err error)
|
||||||
PurgeMemberships(ctx context.Context, txn *sql.Tx, roomID string) error
|
PurgeMemberships(ctx context.Context, txn *sql.Tx, roomID string) error
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
|
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3"
|
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3"
|
||||||
@ -47,7 +47,7 @@ func TestMembershipsTable(t *testing.T) {
|
|||||||
room := test.NewRoom(t, alice)
|
room := test.NewRoom(t, alice)
|
||||||
|
|
||||||
// Create users
|
// Create users
|
||||||
var userEvents []*gomatrixserverlib.HeaderedEvent
|
var userEvents []*rstypes.HeaderedEvent
|
||||||
users := []string{alice.ID}
|
users := []string{alice.ID}
|
||||||
for _, x := range room.CurrentState() {
|
for _, x := range room.CurrentState() {
|
||||||
if x.StateKeyEquals(alice.ID) {
|
if x.StateKeyEquals(alice.ID) {
|
||||||
@ -114,7 +114,7 @@ func testMembershipCount(t *testing.T, ctx context.Context, table tables.Members
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testUpsert(t *testing.T, ctx context.Context, table tables.Memberships, membershipEvent *gomatrixserverlib.HeaderedEvent, user *test.User, room *test.Room) {
|
func testUpsert(t *testing.T, ctx context.Context, table tables.Memberships, membershipEvent *rstypes.HeaderedEvent, user *test.User, room *test.Room) {
|
||||||
t.Run("upserting works as expected", func(t *testing.T) {
|
t.Run("upserting works as expected", func(t *testing.T) {
|
||||||
if err := table.UpsertMembership(ctx, nil, membershipEvent, 1, 1); err != nil {
|
if err := table.UpsertMembership(ctx, nil, membershipEvent, 1, 1); err != nil {
|
||||||
t.Fatalf("failed to upsert membership: %s", err)
|
t.Fatalf("failed to upsert membership: %s", err)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
"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/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -273,10 +274,21 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
|||||||
recentStreamEvents := dbEvents[delta.RoomID].Events
|
recentStreamEvents := dbEvents[delta.RoomID].Events
|
||||||
limited := dbEvents[delta.RoomID].Limited
|
limited := dbEvents[delta.RoomID].Limited
|
||||||
|
|
||||||
recentEvents := gomatrixserverlib.HeaderedReverseTopologicalOrdering(
|
hisVisMap := map[string]gomatrixserverlib.HistoryVisibility{}
|
||||||
snapshot.StreamEventsToEvents(device, recentStreamEvents),
|
for _, re := range recentStreamEvents {
|
||||||
|
hisVisMap[re.EventID()] = re.Visibility
|
||||||
|
}
|
||||||
|
recEvents := gomatrixserverlib.HeaderedReverseTopologicalOrdering(
|
||||||
|
toEvents(snapshot.StreamEventsToEvents(device, recentStreamEvents)),
|
||||||
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
gomatrixserverlib.TopologicalOrderByPrevEvents,
|
||||||
)
|
)
|
||||||
|
recentEvents := make([]*rstypes.HeaderedEvent, len(recEvents))
|
||||||
|
for i := range recEvents {
|
||||||
|
recentEvents[i] = &rstypes.HeaderedEvent{
|
||||||
|
Event: recEvents[i],
|
||||||
|
Visibility: hisVisMap[recEvents[i].EventID()],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we didn't return any events at all then don't bother doing anything else.
|
// If we didn't return any events at all then don't bother doing anything else.
|
||||||
if len(recentEvents) == 0 && len(delta.StateEvents) == 0 {
|
if len(recentEvents) == 0 && len(delta.StateEvents) == 0 {
|
||||||
@ -341,10 +353,21 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
|||||||
// Now that we've filtered the timeline, work out which state events are still
|
// Now that we've filtered the timeline, work out which state events are still
|
||||||
// left. Anything that appears in the filtered timeline will be removed from the
|
// left. Anything that appears in the filtered timeline will be removed from the
|
||||||
// "state" section and kept in "timeline".
|
// "state" section and kept in "timeline".
|
||||||
delta.StateEvents = gomatrixserverlib.HeaderedReverseTopologicalOrdering(
|
hisVisMap = map[string]gomatrixserverlib.HistoryVisibility{}
|
||||||
removeDuplicates(delta.StateEvents, events),
|
for _, re := range delta.StateEvents {
|
||||||
|
hisVisMap[re.EventID()] = re.Visibility
|
||||||
|
}
|
||||||
|
sEvents := gomatrixserverlib.HeaderedReverseTopologicalOrdering(
|
||||||
|
toEvents(removeDuplicates(delta.StateEvents, events)),
|
||||||
gomatrixserverlib.TopologicalOrderByAuthEvents,
|
gomatrixserverlib.TopologicalOrderByAuthEvents,
|
||||||
)
|
)
|
||||||
|
delta.StateEvents = make([]*rstypes.HeaderedEvent, len(sEvents))
|
||||||
|
for i := range sEvents {
|
||||||
|
delta.StateEvents[i] = &rstypes.HeaderedEvent{
|
||||||
|
Event: sEvents[i],
|
||||||
|
Visibility: hisVisMap[sEvents[i].EventID()],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(delta.StateEvents) > 0 {
|
if len(delta.StateEvents) > 0 {
|
||||||
if last := delta.StateEvents[len(delta.StateEvents)-1]; last != nil {
|
if last := delta.StateEvents[len(delta.StateEvents)-1]; last != nil {
|
||||||
@ -407,8 +430,8 @@ func applyHistoryVisibilityFilter(
|
|||||||
snapshot storage.DatabaseTransaction,
|
snapshot storage.DatabaseTransaction,
|
||||||
rsAPI roomserverAPI.SyncRoomserverAPI,
|
rsAPI roomserverAPI.SyncRoomserverAPI,
|
||||||
roomID, userID string,
|
roomID, userID string,
|
||||||
recentEvents []*gomatrixserverlib.HeaderedEvent,
|
recentEvents []*rstypes.HeaderedEvent,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*rstypes.HeaderedEvent, error) {
|
||||||
// We need to make sure we always include the latest state events, if they are in the timeline.
|
// We need to make sure we always include the latest state events, if they are in the timeline.
|
||||||
alwaysIncludeIDs := make(map[string]struct{})
|
alwaysIncludeIDs := make(map[string]struct{})
|
||||||
var stateTypes []string
|
var stateTypes []string
|
||||||
@ -555,8 +578,8 @@ func (p *PDUStreamProvider) lazyLoadMembers(
|
|||||||
ctx context.Context, snapshot storage.DatabaseTransaction, roomID string,
|
ctx context.Context, snapshot storage.DatabaseTransaction, roomID string,
|
||||||
incremental, limited bool, stateFilter *synctypes.StateFilter,
|
incremental, limited bool, stateFilter *synctypes.StateFilter,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
timelineEvents, stateEvents []*gomatrixserverlib.HeaderedEvent,
|
timelineEvents, stateEvents []*rstypes.HeaderedEvent,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*rstypes.HeaderedEvent, error) {
|
||||||
if len(timelineEvents) == 0 {
|
if len(timelineEvents) == 0 {
|
||||||
return stateEvents, nil
|
return stateEvents, nil
|
||||||
}
|
}
|
||||||
@ -573,7 +596,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Preallocate with the same amount, even if it will end up with fewer values
|
// Preallocate with the same amount, even if it will end up with fewer values
|
||||||
newStateEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, len(stateEvents))
|
newStateEvents := make([]*rstypes.HeaderedEvent, 0, len(stateEvents))
|
||||||
// Remove existing membership events we don't care about, e.g. users not in the timeline.events
|
// Remove existing membership events we don't care about, e.g. users not in the timeline.events
|
||||||
for _, event := range stateEvents {
|
for _, event := range stateEvents {
|
||||||
if event.Type() == spec.MRoomMember && event.StateKey() != nil {
|
if event.Type() == spec.MRoomMember && event.StateKey() != nil {
|
||||||
@ -633,7 +656,7 @@ func (p *PDUStreamProvider) addIgnoredUsersToFilter(ctx context.Context, snapsho
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeDuplicates(stateEvents, recentEvents []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent {
|
func removeDuplicates(stateEvents, recentEvents []*rstypes.HeaderedEvent) []*rstypes.HeaderedEvent {
|
||||||
for _, recentEv := range recentEvents {
|
for _, recentEv := range recentEvents {
|
||||||
if recentEv.StateKey() == nil {
|
if recentEv.StateKey() == nil {
|
||||||
continue // not a state event
|
continue // not a state event
|
||||||
@ -654,3 +677,11 @@ func removeDuplicates(stateEvents, recentEvents []*gomatrixserverlib.HeaderedEve
|
|||||||
}
|
}
|
||||||
return stateEvents
|
return stateEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toEvents(events []*rstypes.HeaderedEvent) []*gomatrixserverlib.Event {
|
||||||
|
result := make([]*gomatrixserverlib.Event, len(events))
|
||||||
|
for i := range events {
|
||||||
|
result[i] = events[i].Event
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/syncapi/routing"
|
"github.com/matrix-org/dendrite/syncapi/routing"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||||
@ -490,7 +491,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
|
|||||||
afterJoinBody := fmt.Sprintf("After join in a %s room", tc.historyVisibility)
|
afterJoinBody := fmt.Sprintf("After join in a %s room", tc.historyVisibility)
|
||||||
msgEv := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": afterJoinBody})
|
msgEv := room.CreateAndInsert(t, alice, "m.room.message", map[string]interface{}{"body": afterJoinBody})
|
||||||
|
|
||||||
eventsToSend = append([]*gomatrixserverlib.HeaderedEvent{}, inviteEv, afterInviteEv, joinEv, msgEv)
|
eventsToSend = append([]*rstypes.HeaderedEvent{}, inviteEv, afterInviteEv, joinEv, msgEv)
|
||||||
|
|
||||||
if err := api.SendEvents(ctx, rsAPI, api.KindNew, eventsToSend, "test", "test", "test", nil, false); err != nil {
|
if err := api.SendEvents(ctx, rsAPI, api.KindNew, eventsToSend, "test", "test", "test", nil, false); err != nil {
|
||||||
t.Fatalf("failed to send events: %v", err)
|
t.Fatalf("failed to send events: %v", err)
|
||||||
@ -523,7 +524,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyEventVisible(t *testing.T, wantVisible bool, wantVisibleEvent *gomatrixserverlib.HeaderedEvent, chunk []synctypes.ClientEvent) {
|
func verifyEventVisible(t *testing.T, wantVisible bool, wantVisibleEvent *rstypes.HeaderedEvent, chunk []synctypes.ClientEvent) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if wantVisible {
|
if wantVisible {
|
||||||
for _, ev := range chunk {
|
for _, ev := range chunk {
|
||||||
@ -1228,7 +1229,7 @@ func syncUntil(t *testing.T,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toNATSMsgs(t *testing.T, cfg *config.Dendrite, input ...*gomatrixserverlib.HeaderedEvent) []*nats.Msg {
|
func toNATSMsgs(t *testing.T, cfg *config.Dendrite, input ...*rstypes.HeaderedEvent) []*nats.Msg {
|
||||||
result := make([]*nats.Msg, len(input))
|
result := make([]*nats.Msg, len(input))
|
||||||
for i, ev := range input {
|
for i, ev := range input {
|
||||||
var addsStateIDs []string
|
var addsStateIDs []string
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user