mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 06:11:55 -06:00
Move GMSL client types to Dendrite (#3045)
GMSL is intended for Federation only. Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/357
This commit is contained in:
parent
985298cfc4
commit
3691423626
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/appservice"
|
||||
"github.com/matrix-org/dendrite/appservice/api"
|
||||
"github.com/matrix-org/dendrite/appservice/consumers"
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver"
|
||||
|
@ -338,7 +339,7 @@ func TestRoomserverConsumerOneInvite(t *testing.T) {
|
|||
evChan := make(chan struct{})
|
||||
// create a dummy AS url, handling the events
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var txn gomatrixserverlib.ApplicationServiceTransaction
|
||||
var txn consumers.ApplicationServiceTransaction
|
||||
err := json.NewDecoder(r.Body).Decode(&txn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -32,10 +32,17 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ApplicationServiceTransaction is the transaction that is sent off to an
|
||||
// application service.
|
||||
type ApplicationServiceTransaction struct {
|
||||
Events []synctypes.ClientEvent `json:"events"`
|
||||
}
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
type OutputRoomEventConsumer struct {
|
||||
ctx context.Context
|
||||
|
@ -171,8 +178,8 @@ func (s *OutputRoomEventConsumer) sendEvents(
|
|||
) error {
|
||||
// Create the transaction body.
|
||||
transaction, err := json.Marshal(
|
||||
gomatrixserverlib.ApplicationServiceTransaction{
|
||||
Events: gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatAll),
|
||||
ApplicationServiceTransaction{
|
||||
Events: synctypes.HeaderedToClientEvents(events, synctypes.FormatAll),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -29,7 +30,7 @@ import (
|
|||
)
|
||||
|
||||
type stateEventInStateResp struct {
|
||||
gomatrixserverlib.ClientEvent
|
||||
synctypes.ClientEvent
|
||||
PrevContent json.RawMessage `json:"prev_content,omitempty"`
|
||||
ReplacesState string `json:"replaces_state,omitempty"`
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
|
|||
"state_at_event": !wantLatestState,
|
||||
}).Info("Fetching all state")
|
||||
|
||||
stateEvents := []gomatrixserverlib.ClientEvent{}
|
||||
stateEvents := []synctypes.ClientEvent{}
|
||||
if wantLatestState {
|
||||
// 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
|
||||
|
@ -131,7 +132,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
|
|||
for _, ev := range stateRes.StateEvents {
|
||||
stateEvents = append(
|
||||
stateEvents,
|
||||
gomatrixserverlib.HeaderedToClientEvent(ev, gomatrixserverlib.FormatAll),
|
||||
synctypes.HeaderedToClientEvent(ev, synctypes.FormatAll),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
@ -150,7 +151,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
|
|||
for _, ev := range stateAfterRes.StateEvents {
|
||||
stateEvents = append(
|
||||
stateEvents,
|
||||
gomatrixserverlib.HeaderedToClientEvent(ev, gomatrixserverlib.FormatAll),
|
||||
synctypes.HeaderedToClientEvent(ev, synctypes.FormatAll),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +310,7 @@ func OnIncomingStateTypeRequest(
|
|||
}
|
||||
|
||||
stateEvent := stateEventInStateResp{
|
||||
ClientEvent: gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatAll),
|
||||
ClientEvent: synctypes.HeaderedToClientEvent(event, synctypes.FormatAll),
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
)
|
||||
|
||||
// QueryLatestEventsAndStateRequest is a request to QueryLatestEventsAndState
|
||||
|
@ -146,7 +147,7 @@ type QueryMembershipsForRoomRequest struct {
|
|||
// QueryMembershipsForRoomResponse is a response to QueryMembershipsForRoom
|
||||
type QueryMembershipsForRoomResponse struct {
|
||||
// The "m.room.member" events (of "join" membership) in the client format
|
||||
JoinEvents []gomatrixserverlib.ClientEvent `json:"join_events"`
|
||||
JoinEvents []synctypes.ClientEvent `json:"join_events"`
|
||||
// True if the user has been in room before and has either stayed in it or
|
||||
// left it.
|
||||
HasBeenInRoom bool `json:"has_been_in_room"`
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
|
@ -345,7 +346,7 @@ func (r *Queryer) QueryMembershipsForRoom(
|
|||
return fmt.Errorf("r.DB.Events: %w", err)
|
||||
}
|
||||
for _, event := range events {
|
||||
clientEvent := gomatrixserverlib.ToClientEvent(event.Event, gomatrixserverlib.FormatAll)
|
||||
clientEvent := synctypes.ToClientEvent(event.Event, synctypes.FormatAll)
|
||||
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
||||
}
|
||||
return nil
|
||||
|
@ -365,7 +366,7 @@ func (r *Queryer) QueryMembershipsForRoom(
|
|||
}
|
||||
|
||||
response.HasBeenInRoom = true
|
||||
response.JoinEvents = []gomatrixserverlib.ClientEvent{}
|
||||
response.JoinEvents = []synctypes.ClientEvent{}
|
||||
|
||||
var events []types.Event
|
||||
var stateEntries []types.StateEntry
|
||||
|
@ -394,7 +395,7 @@ func (r *Queryer) QueryMembershipsForRoom(
|
|||
}
|
||||
|
||||
for _, event := range events {
|
||||
clientEvent := gomatrixserverlib.ToClientEvent(event.Event, gomatrixserverlib.FormatAll)
|
||||
clientEvent := synctypes.ToClientEvent(event.Event, synctypes.FormatAll)
|
||||
response.JoinEvents = append(response.JoinEvents, clientEvent)
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -78,9 +79,9 @@ func (r *EventRelationshipRequest) Defaults() {
|
|||
}
|
||||
|
||||
type EventRelationshipResponse struct {
|
||||
Events []gomatrixserverlib.ClientEvent `json:"events"`
|
||||
NextBatch string `json:"next_batch"`
|
||||
Limited bool `json:"limited"`
|
||||
Events []synctypes.ClientEvent `json:"events"`
|
||||
NextBatch string `json:"next_batch"`
|
||||
Limited bool `json:"limited"`
|
||||
}
|
||||
|
||||
type MSC2836EventRelationshipsResponse struct {
|
||||
|
@ -91,7 +92,7 @@ type MSC2836EventRelationshipsResponse struct {
|
|||
|
||||
func toClientResponse(res *MSC2836EventRelationshipsResponse) *EventRelationshipResponse {
|
||||
out := &EventRelationshipResponse{
|
||||
Events: gomatrixserverlib.ToClientEvents(res.ParsedEvents, gomatrixserverlib.FormatAll),
|
||||
Events: synctypes.ToClientEvents(res.ParsedEvents, synctypes.FormatAll),
|
||||
Limited: res.Limited,
|
||||
NextBatch: res.NextBatch,
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/hooks"
|
||||
|
@ -462,7 +463,7 @@ func assertContains(t *testing.T, result *msc2836.EventRelationshipResponse, wan
|
|||
}
|
||||
}
|
||||
|
||||
func assertUnsignedChildren(t *testing.T, ev gomatrixserverlib.ClientEvent, relType string, wantCount int, childrenEventIDs []string) {
|
||||
func assertUnsignedChildren(t *testing.T, ev synctypes.ClientEvent, relType string, wantCount int, childrenEventIDs []string) {
|
||||
t.Helper()
|
||||
unsigned := struct {
|
||||
Children map[string]int `json:"children"`
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -278,7 +279,7 @@ func leftRooms(res *types.Response) []string {
|
|||
return roomIDs
|
||||
}
|
||||
|
||||
func membershipEventPresent(events []gomatrixserverlib.ClientEvent, userID string) bool {
|
||||
func membershipEventPresent(events []synctypes.ClientEvent, userID string) bool {
|
||||
for _, ev := range events {
|
||||
// it's enough to know that we have our member event here, don't need to check membership content
|
||||
// as it's implied by being in the respective section of the sync response.
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/matrix-org/util"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -159,7 +160,7 @@ func assertCatchup(t *testing.T, hasNew bool, syncResponse *types.Response, want
|
|||
|
||||
func joinResponseWithRooms(syncResponse *types.Response, userID string, roomIDs []string) *types.Response {
|
||||
for _, roomID := range roomIDs {
|
||||
roomEvents := []gomatrixserverlib.ClientEvent{
|
||||
roomEvents := []synctypes.ClientEvent{
|
||||
{
|
||||
Type: "m.room.member",
|
||||
StateKey: &userID,
|
||||
|
@ -182,7 +183,7 @@ func joinResponseWithRooms(syncResponse *types.Response, userID string, roomIDs
|
|||
|
||||
func leaveResponseWithRooms(syncResponse *types.Response, userID string, roomIDs []string) *types.Response {
|
||||
for _, roomID := range roomIDs {
|
||||
roomEvents := []gomatrixserverlib.ClientEvent{
|
||||
roomEvents := []synctypes.ClientEvent{
|
||||
{
|
||||
Type: "m.room.member",
|
||||
StateKey: &userID,
|
||||
|
@ -299,7 +300,7 @@ func TestKeyChangeCatchupNoNewJoinsButMessages(t *testing.T) {
|
|||
roomID := "!TestKeyChangeCatchupNoNewJoinsButMessages:bar"
|
||||
syncResponse := types.NewResponse()
|
||||
empty := ""
|
||||
roomStateEvents := []gomatrixserverlib.ClientEvent{
|
||||
roomStateEvents := []synctypes.ClientEvent{
|
||||
{
|
||||
Type: "m.room.name",
|
||||
StateKey: &empty,
|
||||
|
@ -309,7 +310,7 @@ func TestKeyChangeCatchupNoNewJoinsButMessages(t *testing.T) {
|
|||
Content: []byte(`{"name":"The Room Name"}`),
|
||||
},
|
||||
}
|
||||
roomTimelineEvents := []gomatrixserverlib.ClientEvent{
|
||||
roomTimelineEvents := []synctypes.ClientEvent{
|
||||
{
|
||||
Type: "m.room.message",
|
||||
EventID: "$something1:here",
|
||||
|
@ -402,7 +403,7 @@ func TestKeyChangeCatchupChangeAndLeftSameRoom(t *testing.T) {
|
|||
newShareUser2 := "@bobby:localhost"
|
||||
roomID := "!join:bar"
|
||||
syncResponse := types.NewResponse()
|
||||
roomEvents := []gomatrixserverlib.ClientEvent{
|
||||
roomEvents := []synctypes.ClientEvent{
|
||||
{
|
||||
Type: "m.room.member",
|
||||
StateKey: &syncingUser,
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
roomserver "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -37,12 +38,12 @@ import (
|
|||
)
|
||||
|
||||
type ContextRespsonse struct {
|
||||
End string `json:"end"`
|
||||
Event *gomatrixserverlib.ClientEvent `json:"event,omitempty"`
|
||||
EventsAfter []gomatrixserverlib.ClientEvent `json:"events_after,omitempty"`
|
||||
EventsBefore []gomatrixserverlib.ClientEvent `json:"events_before,omitempty"`
|
||||
Start string `json:"start"`
|
||||
State []gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||
End string `json:"end"`
|
||||
Event *synctypes.ClientEvent `json:"event,omitempty"`
|
||||
EventsAfter []synctypes.ClientEvent `json:"events_after,omitempty"`
|
||||
EventsBefore []synctypes.ClientEvent `json:"events_before,omitempty"`
|
||||
Start string `json:"start"`
|
||||
State []synctypes.ClientEvent `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
func Context(
|
||||
|
@ -94,7 +95,7 @@ func Context(
|
|||
}
|
||||
}
|
||||
|
||||
stateFilter := gomatrixserverlib.StateFilter{
|
||||
stateFilter := synctypes.StateFilter{
|
||||
NotSenders: filter.NotSenders,
|
||||
NotTypes: filter.NotTypes,
|
||||
Senders: filter.Senders,
|
||||
|
@ -167,14 +168,14 @@ func Context(
|
|||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
eventsBeforeClient := gomatrixserverlib.HeaderedToClientEvents(eventsBeforeFiltered, gomatrixserverlib.FormatAll)
|
||||
eventsAfterClient := gomatrixserverlib.HeaderedToClientEvents(eventsAfterFiltered, gomatrixserverlib.FormatAll)
|
||||
eventsBeforeClient := synctypes.HeaderedToClientEvents(eventsBeforeFiltered, synctypes.FormatAll)
|
||||
eventsAfterClient := synctypes.HeaderedToClientEvents(eventsAfterFiltered, synctypes.FormatAll)
|
||||
|
||||
newState := state
|
||||
if filter.LazyLoadMembers {
|
||||
allEvents := append(eventsBeforeFiltered, eventsAfterFiltered...)
|
||||
allEvents = append(allEvents, &requestedEvent)
|
||||
evs := gomatrixserverlib.HeaderedToClientEvents(allEvents, gomatrixserverlib.FormatAll)
|
||||
evs := synctypes.HeaderedToClientEvents(allEvents, synctypes.FormatAll)
|
||||
newState, err = applyLazyLoadMembers(ctx, device, snapshot, roomID, evs, lazyLoadCache)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("unable to load membership events")
|
||||
|
@ -182,12 +183,12 @@ func Context(
|
|||
}
|
||||
}
|
||||
|
||||
ev := gomatrixserverlib.HeaderedToClientEvent(&requestedEvent, gomatrixserverlib.FormatAll)
|
||||
ev := synctypes.HeaderedToClientEvent(&requestedEvent, synctypes.FormatAll)
|
||||
response := ContextRespsonse{
|
||||
Event: &ev,
|
||||
EventsAfter: eventsAfterClient,
|
||||
EventsBefore: eventsBeforeClient,
|
||||
State: gomatrixserverlib.HeaderedToClientEvents(newState, gomatrixserverlib.FormatAll),
|
||||
State: synctypes.HeaderedToClientEvents(newState, synctypes.FormatAll),
|
||||
}
|
||||
|
||||
if len(response.State) > filter.Limit {
|
||||
|
@ -261,7 +262,7 @@ func applyLazyLoadMembers(
|
|||
device *userapi.Device,
|
||||
snapshot storage.DatabaseTransaction,
|
||||
roomID string,
|
||||
events []gomatrixserverlib.ClientEvent,
|
||||
events []synctypes.ClientEvent,
|
||||
lazyLoadCache caching.LazyLoadCache,
|
||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
eventSenders := make(map[string]struct{})
|
||||
|
@ -280,7 +281,7 @@ func applyLazyLoadMembers(
|
|||
}
|
||||
|
||||
// Query missing membership events
|
||||
filter := gomatrixserverlib.DefaultStateFilter()
|
||||
filter := synctypes.DefaultStateFilter()
|
||||
filter.Senders = &wantUsers
|
||||
filter.Types = &[]string{gomatrixserverlib.MRoomMember}
|
||||
memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter)
|
||||
|
@ -296,9 +297,9 @@ func applyLazyLoadMembers(
|
|||
return memberships, nil
|
||||
}
|
||||
|
||||
func parseRoomEventFilter(req *http.Request) (*gomatrixserverlib.RoomEventFilter, error) {
|
||||
func parseRoomEventFilter(req *http.Request) (*synctypes.RoomEventFilter, error) {
|
||||
// Default room filter
|
||||
filter := &gomatrixserverlib.RoomEventFilter{Limit: 10}
|
||||
filter := &synctypes.RoomEventFilter{Limit: 10}
|
||||
|
||||
l := req.URL.Query().Get("limit")
|
||||
f := req.URL.Query().Get("filter")
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
)
|
||||
|
||||
func Test_parseContextParams(t *testing.T) {
|
||||
|
@ -19,28 +19,28 @@ func Test_parseContextParams(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
req *http.Request
|
||||
wantFilter *gomatrixserverlib.RoomEventFilter
|
||||
wantFilter *synctypes.RoomEventFilter
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "no params set",
|
||||
req: noParamsReq,
|
||||
wantFilter: &gomatrixserverlib.RoomEventFilter{Limit: 10},
|
||||
wantFilter: &synctypes.RoomEventFilter{Limit: 10},
|
||||
},
|
||||
{
|
||||
name: "limit 2 param set",
|
||||
req: limit2Req,
|
||||
wantFilter: &gomatrixserverlib.RoomEventFilter{Limit: 2},
|
||||
wantFilter: &synctypes.RoomEventFilter{Limit: 2},
|
||||
},
|
||||
{
|
||||
name: "limit 10000 param set",
|
||||
req: limit10000Req,
|
||||
wantFilter: &gomatrixserverlib.RoomEventFilter{Limit: 100},
|
||||
wantFilter: &synctypes.RoomEventFilter{Limit: 100},
|
||||
},
|
||||
{
|
||||
name: "filter lazy_load_members param set",
|
||||
req: lazyLoadReq,
|
||||
wantFilter: &gomatrixserverlib.RoomEventFilter{Limit: 2, LazyLoadMembers: true},
|
||||
wantFilter: &synctypes.RoomEventFilter{Limit: 2, LazyLoadMembers: true},
|
||||
},
|
||||
{
|
||||
name: "invalid limit req",
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/sync"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
|
@ -45,7 +46,7 @@ func GetFilter(
|
|||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
filter := gomatrixserverlib.DefaultFilter()
|
||||
filter := synctypes.DefaultFilter()
|
||||
if err := syncDB.GetFilter(req.Context(), &filter, localpart, filterID); err != nil {
|
||||
//TODO better error handling. This error message is *probably* right,
|
||||
// but if there are obscure db errors, this will also be returned,
|
||||
|
@ -85,7 +86,7 @@ func PutFilter(
|
|||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var filter gomatrixserverlib.Filter
|
||||
var filter synctypes.Filter
|
||||
|
||||
defer req.Body.Close() // nolint:errcheck
|
||||
body, err := io.ReadAll(req.Body)
|
||||
|
|
|
@ -17,7 +17,6 @@ package routing
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -26,6 +25,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
|
@ -97,6 +97,6 @@ func GetEvent(
|
|||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: gomatrixserverlib.HeaderedToClientEvent(events[0], gomatrixserverlib.FormatAll),
|
||||
JSON: synctypes.HeaderedToClientEvent(events[0], synctypes.FormatAll),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ import (
|
|||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
type getMembershipResponse struct {
|
||||
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
||||
Chunk []synctypes.ClientEvent `json:"chunk"`
|
||||
}
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members
|
||||
|
@ -134,6 +134,6 @@ func GetMemberships(
|
|||
}
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: getMembershipResponse{gomatrixserverlib.HeaderedToClientEvents(result, gomatrixserverlib.FormatAll)},
|
||||
JSON: getMembershipResponse{synctypes.HeaderedToClientEvents(result, synctypes.FormatAll)},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/sync"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -50,15 +51,15 @@ type messagesReq struct {
|
|||
device *userapi.Device
|
||||
wasToProvided bool
|
||||
backwardOrdering bool
|
||||
filter *gomatrixserverlib.RoomEventFilter
|
||||
filter *synctypes.RoomEventFilter
|
||||
}
|
||||
|
||||
type messagesResp struct {
|
||||
Start string `json:"start"`
|
||||
StartStream string `json:"start_stream,omitempty"` // NOTSPEC: used by Cerulean, so clients can hit /messages then immediately /sync with a latest sync token
|
||||
End string `json:"end,omitempty"`
|
||||
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
||||
State []gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||
Start string `json:"start"`
|
||||
StartStream string `json:"start_stream,omitempty"` // NOTSPEC: used by Cerulean, so clients can hit /messages then immediately /sync with a latest sync token
|
||||
End string `json:"end,omitempty"`
|
||||
Chunk []synctypes.ClientEvent `json:"chunk"`
|
||||
State []synctypes.ClientEvent `json:"state,omitempty"`
|
||||
}
|
||||
|
||||
// OnIncomingMessagesRequest implements the /messages endpoint from the
|
||||
|
@ -253,7 +254,7 @@ func OnIncomingMessagesRequest(
|
|||
util.GetLogger(req.Context()).WithError(err).Error("failed to apply lazy loading")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
res.State = append(res.State, gomatrixserverlib.HeaderedToClientEvents(membershipEvents, gomatrixserverlib.FormatAll)...)
|
||||
res.State = append(res.State, synctypes.HeaderedToClientEvents(membershipEvents, synctypes.FormatAll)...)
|
||||
}
|
||||
|
||||
// If we didn't return any events, set the end to an empty string, so it will be omitted
|
||||
|
@ -291,7 +292,7 @@ func getMembershipForUser(ctx context.Context, roomID, userID string, rsAPI api.
|
|||
// Returns an error if there was an issue talking to the database or with the
|
||||
// remote homeserver.
|
||||
func (r *messagesReq) retrieveEvents() (
|
||||
clientEvents []gomatrixserverlib.ClientEvent, start,
|
||||
clientEvents []synctypes.ClientEvent, start,
|
||||
end types.TopologyToken, err error,
|
||||
) {
|
||||
// Retrieve the events from the local database.
|
||||
|
@ -323,7 +324,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||
|
||||
// If we didn't get any event, we don't need to proceed any further.
|
||||
if len(events) == 0 {
|
||||
return []gomatrixserverlib.ClientEvent{}, *r.from, *r.to, nil
|
||||
return []synctypes.ClientEvent{}, *r.from, *r.to, nil
|
||||
}
|
||||
|
||||
// Get the position of the first and the last event in the room's topology.
|
||||
|
@ -334,7 +335,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||
// only have to change it in one place, i.e. the database.
|
||||
start, end, err = r.getStartEnd(events)
|
||||
if err != nil {
|
||||
return []gomatrixserverlib.ClientEvent{}, *r.from, *r.to, err
|
||||
return []synctypes.ClientEvent{}, *r.from, *r.to, err
|
||||
}
|
||||
|
||||
// Sort the events to ensure we send them in the right order.
|
||||
|
@ -350,7 +351,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||
events = reversed(events)
|
||||
}
|
||||
if len(events) == 0 {
|
||||
return []gomatrixserverlib.ClientEvent{}, *r.from, *r.to, nil
|
||||
return []synctypes.ClientEvent{}, *r.from, *r.to, nil
|
||||
}
|
||||
|
||||
// Apply room history visibility filter
|
||||
|
@ -362,7 +363,7 @@ func (r *messagesReq) retrieveEvents() (
|
|||
"events_before": len(events),
|
||||
"events_after": len(filteredEvents),
|
||||
}).Debug("applied history visibility (messages)")
|
||||
return gomatrixserverlib.HeaderedToClientEvents(filteredEvents, gomatrixserverlib.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) {
|
||||
|
|
|
@ -27,14 +27,15 @@ import (
|
|||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
type RelationsResponse struct {
|
||||
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
||||
NextBatch string `json:"next_batch,omitempty"`
|
||||
PrevBatch string `json:"prev_batch,omitempty"`
|
||||
Chunk []synctypes.ClientEvent `json:"chunk"`
|
||||
NextBatch string `json:"next_batch,omitempty"`
|
||||
PrevBatch string `json:"prev_batch,omitempty"`
|
||||
}
|
||||
|
||||
// nolint:gocyclo
|
||||
|
@ -85,7 +86,7 @@ func Relations(
|
|||
defer sqlutil.EndTransactionWithCheck(snapshot, &succeeded, &err)
|
||||
|
||||
res := &RelationsResponse{
|
||||
Chunk: []gomatrixserverlib.ClientEvent{},
|
||||
Chunk: []synctypes.ClientEvent{},
|
||||
}
|
||||
var events []types.StreamEvent
|
||||
events, res.PrevBatch, res.NextBatch, err = snapshot.RelationsFor(
|
||||
|
@ -108,11 +109,11 @@ func Relations(
|
|||
|
||||
// Convert the events into client events, and optionally filter based on the event
|
||||
// type if it was specified.
|
||||
res.Chunk = make([]gomatrixserverlib.ClientEvent, 0, len(filteredEvents))
|
||||
res.Chunk = make([]synctypes.ClientEvent, 0, len(filteredEvents))
|
||||
for _, event := range filteredEvents {
|
||||
res.Chunk = append(
|
||||
res.Chunk,
|
||||
gomatrixserverlib.ToClientEvent(event.Event, gomatrixserverlib.FormatAll),
|
||||
synctypes.ToClientEvent(event.Event, synctypes.FormatAll),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
|
@ -145,7 +146,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
// Filter on m.room.message, as otherwise we also get events like m.reaction
|
||||
// which "breaks" displaying results in Element Web.
|
||||
types := []string{"m.room.message"}
|
||||
roomFilter := &gomatrixserverlib.RoomEventFilter{
|
||||
roomFilter := &synctypes.RoomEventFilter{
|
||||
Rooms: &rooms,
|
||||
Types: &types,
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
})
|
||||
}
|
||||
|
||||
stateForRooms := make(map[string][]gomatrixserverlib.ClientEvent)
|
||||
stateForRooms := make(map[string][]synctypes.ClientEvent)
|
||||
for _, event := range evs {
|
||||
eventsBefore, eventsAfter, err := contextEvents(ctx, snapshot, event, roomFilter, searchReq)
|
||||
if err != nil {
|
||||
|
@ -204,24 +205,24 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
Context: SearchContextResponse{
|
||||
Start: startToken.String(),
|
||||
End: endToken.String(),
|
||||
EventsAfter: gomatrixserverlib.HeaderedToClientEvents(eventsAfter, gomatrixserverlib.FormatSync),
|
||||
EventsBefore: gomatrixserverlib.HeaderedToClientEvents(eventsBefore, gomatrixserverlib.FormatSync),
|
||||
EventsAfter: synctypes.HeaderedToClientEvents(eventsAfter, synctypes.FormatSync),
|
||||
EventsBefore: synctypes.HeaderedToClientEvents(eventsBefore, synctypes.FormatSync),
|
||||
ProfileInfo: profileInfos,
|
||||
},
|
||||
Rank: eventScore[event.EventID()].Score,
|
||||
Result: gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatAll),
|
||||
Result: synctypes.HeaderedToClientEvent(event, synctypes.FormatAll),
|
||||
})
|
||||
roomGroup := groups[event.RoomID()]
|
||||
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
||||
groups[event.RoomID()] = roomGroup
|
||||
if _, ok := stateForRooms[event.RoomID()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
|
||||
stateFilter := gomatrixserverlib.DefaultStateFilter()
|
||||
stateFilter := synctypes.DefaultStateFilter()
|
||||
state, err := snapshot.CurrentState(ctx, event.RoomID(), &stateFilter, nil)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("unable to get current state")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
stateForRooms[event.RoomID()] = gomatrixserverlib.HeaderedToClientEvents(state, gomatrixserverlib.FormatSync)
|
||||
stateForRooms[event.RoomID()] = synctypes.HeaderedToClientEvents(state, synctypes.FormatSync)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -262,7 +263,7 @@ func contextEvents(
|
|||
ctx context.Context,
|
||||
snapshot storage.DatabaseTransaction,
|
||||
event *gomatrixserverlib.HeaderedEvent,
|
||||
roomFilter *gomatrixserverlib.RoomEventFilter,
|
||||
roomFilter *synctypes.RoomEventFilter,
|
||||
searchReq SearchRequest,
|
||||
) ([]*gomatrixserverlib.HeaderedEvent, []*gomatrixserverlib.HeaderedEvent, error) {
|
||||
id, _, err := snapshot.SelectContextEvent(ctx, event.RoomID(), event.EventID())
|
||||
|
@ -300,13 +301,13 @@ type Groupings struct {
|
|||
}
|
||||
|
||||
type RoomEvents struct {
|
||||
EventContext EventContext `json:"event_context"`
|
||||
Filter gomatrixserverlib.RoomEventFilter `json:"filter"`
|
||||
Groupings Groupings `json:"groupings"`
|
||||
IncludeState bool `json:"include_state"`
|
||||
Keys []string `json:"keys"`
|
||||
OrderBy string `json:"order_by"`
|
||||
SearchTerm string `json:"search_term"`
|
||||
EventContext EventContext `json:"event_context"`
|
||||
Filter synctypes.RoomEventFilter `json:"filter"`
|
||||
Groupings Groupings `json:"groupings"`
|
||||
IncludeState bool `json:"include_state"`
|
||||
Keys []string `json:"keys"`
|
||||
OrderBy string `json:"order_by"`
|
||||
SearchTerm string `json:"search_term"`
|
||||
}
|
||||
|
||||
type SearchCategories struct {
|
||||
|
@ -331,17 +332,17 @@ type Groups struct {
|
|||
}
|
||||
|
||||
type Result struct {
|
||||
Context SearchContextResponse `json:"context"`
|
||||
Rank float64 `json:"rank"`
|
||||
Result gomatrixserverlib.ClientEvent `json:"result"`
|
||||
Context SearchContextResponse `json:"context"`
|
||||
Rank float64 `json:"rank"`
|
||||
Result synctypes.ClientEvent `json:"result"`
|
||||
}
|
||||
|
||||
type SearchContextResponse struct {
|
||||
End string `json:"end"`
|
||||
EventsAfter []gomatrixserverlib.ClientEvent `json:"events_after"`
|
||||
EventsBefore []gomatrixserverlib.ClientEvent `json:"events_before"`
|
||||
Start string `json:"start"`
|
||||
ProfileInfo map[string]ProfileInfoResponse `json:"profile_info"`
|
||||
End string `json:"end"`
|
||||
EventsAfter []synctypes.ClientEvent `json:"events_after"`
|
||||
EventsBefore []synctypes.ClientEvent `json:"events_before"`
|
||||
Start string `json:"start"`
|
||||
ProfileInfo map[string]ProfileInfoResponse `json:"profile_info"`
|
||||
}
|
||||
|
||||
type ProfileInfoResponse struct {
|
||||
|
@ -350,12 +351,12 @@ type ProfileInfoResponse struct {
|
|||
}
|
||||
|
||||
type RoomEventsResponse struct {
|
||||
Count int `json:"count"`
|
||||
Groups Groups `json:"groups"`
|
||||
Highlights []string `json:"highlights"`
|
||||
NextBatch *string `json:"next_batch,omitempty"`
|
||||
Results []Result `json:"results"`
|
||||
State map[string][]gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||
Count int `json:"count"`
|
||||
Groups Groups `json:"groups"`
|
||||
Highlights []string `json:"highlights"`
|
||||
NextBatch *string `json:"next_batch,omitempty"`
|
||||
Results []Result `json:"results"`
|
||||
State map[string][]synctypes.ClientEvent `json:"state,omitempty"`
|
||||
}
|
||||
type SearchCategoriesResponse struct {
|
||||
RoomEvents RoomEventsResponse `json:"room_events"`
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/dendrite/test/testrig"
|
||||
|
@ -96,7 +97,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilter,
|
||||
},
|
||||
},
|
||||
|
@ -111,7 +112,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilterUnknown,
|
||||
},
|
||||
},
|
||||
|
@ -126,7 +127,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilter,
|
||||
},
|
||||
IncludeState: true,
|
||||
|
@ -143,7 +144,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilter,
|
||||
},
|
||||
},
|
||||
|
@ -160,7 +161,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilter,
|
||||
},
|
||||
},
|
||||
|
@ -176,7 +177,7 @@ func TestSearch(t *testing.T) {
|
|||
SearchCategories: SearchCategories{
|
||||
RoomEvents: RoomEvents{
|
||||
SearchTerm: "hello",
|
||||
Filter: gomatrixserverlib.RoomEventFilter{
|
||||
Filter: synctypes.RoomEventFilter{
|
||||
Rooms: &roomsFilter,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/shared"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -40,13 +41,13 @@ type DatabaseTransaction interface {
|
|||
MaxStreamPositionForPresence(ctx context.Context) (types.StreamPosition, error)
|
||||
MaxStreamPositionForRelations(ctx context.Context) (types.StreamPosition, error)
|
||||
|
||||
CurrentState(ctx context.Context, roomID string, stateFilterPart *gomatrixserverlib.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
GetStateDeltasForFullStateSync(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *gomatrixserverlib.StateFilter) ([]types.StateDelta, []string, error)
|
||||
GetStateDeltas(ctx context.Context, device *userapi.Device, r types.Range, userID string, stateFilter *gomatrixserverlib.StateFilter) ([]types.StateDelta, []string, error)
|
||||
CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, 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)
|
||||
RoomIDsWithMembership(ctx context.Context, userID string, membership string) ([]string, 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)
|
||||
RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *gomatrixserverlib.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)
|
||||
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)
|
||||
|
@ -71,15 +72,15 @@ type DatabaseTransaction interface {
|
|||
// 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 error if there was an issue with the retrieval.
|
||||
GetStateEventsForRoom(ctx context.Context, roomID string, stateFilterPart *gomatrixserverlib.StateFilter) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error)
|
||||
GetStateEventsForRoom(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error)
|
||||
// GetAccountDataInRange returns all account data for a given user inserted or
|
||||
// updated between two given positions
|
||||
// Returns a map following the format data[roomID] = []dataTypes
|
||||
// If no data is retrieved, returns an empty map
|
||||
// If there was an issue with the retrieval, returns an error
|
||||
GetAccountDataInRange(ctx context.Context, userID string, r types.Range, accountDataFilterPart *gomatrixserverlib.EventFilter) (map[string][]string, types.StreamPosition, error)
|
||||
GetAccountDataInRange(ctx context.Context, userID string, r types.Range, accountDataFilterPart *synctypes.EventFilter) (map[string][]string, types.StreamPosition, error)
|
||||
// GetEventsInTopologicalRange retrieves all of the events on a given ordering using the given extremities and limit. If backwardsOrdering is true, the most recent event must be first, else last.
|
||||
GetEventsInTopologicalRange(ctx context.Context, from, to *types.TopologyToken, roomID string, filter *gomatrixserverlib.RoomEventFilter, backwardOrdering bool) (events []types.StreamEvent, err error)
|
||||
GetEventsInTopologicalRange(ctx context.Context, from, to *types.TopologyToken, roomID string, filter *synctypes.RoomEventFilter, backwardOrdering bool) (events []types.StreamEvent, err error)
|
||||
// EventPositionInTopology returns the depth and stream position of the given event.
|
||||
EventPositionInTopology(ctx context.Context, eventID string) (types.TopologyToken, error)
|
||||
// BackwardExtremitiesForRoom returns a map of backwards extremity event ID to a list of its prev_events.
|
||||
|
@ -94,8 +95,8 @@ type DatabaseTransaction interface {
|
|||
// GetRoomReceipts gets all receipts for a given roomID
|
||||
GetRoomReceipts(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) ([]types.OutputReceiptEvent, error)
|
||||
SelectContextEvent(ctx context.Context, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
||||
StreamToTopologicalPosition(ctx context.Context, roomID string, streamPos types.StreamPosition, backwardOrdering bool) (types.TopologyToken, 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
|
||||
|
@ -105,7 +106,7 @@ type DatabaseTransaction interface {
|
|||
// getUserUnreadNotificationCountsForRooms returns the unread notifications for the given rooms
|
||||
GetUserUnreadNotificationCountsForRooms(ctx context.Context, userID string, roomIDs map[string]string) (map[string]*eventutil.NotificationData, error)
|
||||
GetPresences(ctx context.Context, userID []string) ([]*types.PresenceInternal, error)
|
||||
PresenceAfter(ctx context.Context, after types.StreamPosition, filter gomatrixserverlib.EventFilter) (map[string]*types.PresenceInternal, error)
|
||||
PresenceAfter(ctx context.Context, after types.StreamPosition, filter synctypes.EventFilter) (map[string]*types.PresenceInternal, error)
|
||||
RelationsFor(ctx context.Context, roomID, eventID, relType, eventType string, from, to types.StreamPosition, backwards bool, limit int) (events []types.StreamEvent, prevBatch, nextBatch string, err error)
|
||||
}
|
||||
|
||||
|
@ -165,11 +166,11 @@ type Database interface {
|
|||
// GetFilter looks up the filter associated with a given local user and filter ID
|
||||
// and populates the target filter. Otherwise returns an error if no such filter exists
|
||||
// or if there was an error talking to the database.
|
||||
GetFilter(ctx context.Context, target *gomatrixserverlib.Filter, localpart string, filterID string) error
|
||||
GetFilter(ctx context.Context, target *synctypes.Filter, localpart string, filterID string) error
|
||||
// PutFilter puts the passed filter into the database.
|
||||
// Returns the filterID as a string. Otherwise returns an error if something
|
||||
// goes wrong.
|
||||
PutFilter(ctx context.Context, localpart string, filter *gomatrixserverlib.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(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) error
|
||||
// StoreReceipt stores new receipt events
|
||||
|
|
|
@ -23,8 +23,8 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
const accountDataSchema = `
|
||||
|
@ -97,7 +97,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
|
|||
ctx context.Context, txn *sql.Tx,
|
||||
userID string,
|
||||
r types.Range,
|
||||
accountDataEventFilter *gomatrixserverlib.EventFilter,
|
||||
accountDataEventFilter *synctypes.EventFilter,
|
||||
) (data map[string][]string, pos types.StreamPosition, err error) {
|
||||
data = make(map[string][]string)
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -270,7 +271,7 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithAnyMembership(
|
|||
// SelectCurrentState returns all the current state events for the given room.
|
||||
func (s *currentRoomStateStatements) SelectCurrentState(
|
||||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
excludeEventIDs []string,
|
||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
stmt := sqlutil.TxStmt(txn, s.selectCurrentStateStmt)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -69,7 +70,7 @@ func NewPostgresFilterTable(db *sql.DB) (tables.Filter, error) {
|
|||
}
|
||||
|
||||
func (s *filterStatements) SelectFilter(
|
||||
ctx context.Context, txn *sql.Tx, target *gomatrixserverlib.Filter, localpart string, filterID string,
|
||||
ctx context.Context, txn *sql.Tx, target *synctypes.Filter, localpart string, filterID string,
|
||||
) error {
|
||||
// Retrieve filter from database (stored as canonical JSON)
|
||||
var filterData []byte
|
||||
|
@ -86,7 +87,7 @@ func (s *filterStatements) SelectFilter(
|
|||
}
|
||||
|
||||
func (s *filterStatements) InsertFilter(
|
||||
ctx context.Context, txn *sql.Tx, filter *gomatrixserverlib.Filter, localpart string,
|
||||
ctx context.Context, txn *sql.Tx, filter *synctypes.Filter, localpart string,
|
||||
) (filterID string, err error) {
|
||||
var existingFilterID string
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ package postgres
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
)
|
||||
|
||||
// filterConvertWildcardToSQL converts wildcards as defined in
|
||||
|
@ -39,7 +39,7 @@ func filterConvertTypeWildcardToSQL(values *[]string) []string {
|
|||
}
|
||||
|
||||
// TODO: Replace when Dendrite uses Go 1.18
|
||||
func getSendersRoomEventFilter(filter *gomatrixserverlib.RoomEventFilter) (senders []string, notSenders []string) {
|
||||
func getSendersRoomEventFilter(filter *synctypes.RoomEventFilter) (senders []string, notSenders []string) {
|
||||
if filter.Senders != nil {
|
||||
senders = *filter.Senders
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func getSendersRoomEventFilter(filter *gomatrixserverlib.RoomEventFilter) (sende
|
|||
return senders, notSenders
|
||||
}
|
||||
|
||||
func getSendersStateFilterFilter(filter *gomatrixserverlib.StateFilter) (senders []string, notSenders []string) {
|
||||
func getSendersStateFilterFilter(filter *synctypes.StateFilter) (senders []string, notSenders []string) {
|
||||
if filter.Senders != nil {
|
||||
senders = *filter.Senders
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -288,7 +289,7 @@ func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *s
|
|||
// two positions, only the most recent state is returned.
|
||||
func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||
ctx context.Context, txn *sql.Tx, r types.Range,
|
||||
stateFilter *gomatrixserverlib.StateFilter, roomIDs []string,
|
||||
stateFilter *synctypes.StateFilter, roomIDs []string,
|
||||
) (map[string]map[string]bool, map[string]types.StreamEvent, error) {
|
||||
var rows *sql.Rows
|
||||
var err error
|
||||
|
@ -433,7 +434,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
|
|||
// from sync.
|
||||
func (s *outputRoomEventsStatements) SelectRecentEvents(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomIDs []string, ra types.Range, eventFilter *gomatrixserverlib.RoomEventFilter,
|
||||
roomIDs []string, ra types.Range, eventFilter *synctypes.RoomEventFilter,
|
||||
chronologicalOrder bool, onlySyncEvents bool,
|
||||
) (map[string]types.RecentEvents, error) {
|
||||
var stmt *sql.Stmt
|
||||
|
@ -533,7 +534,7 @@ func (s *outputRoomEventsStatements) SelectRecentEvents(
|
|||
// from a given position, up to a maximum of 'limit'.
|
||||
func (s *outputRoomEventsStatements) SelectEarlyEvents(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomID string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter,
|
||||
roomID string, r types.Range, eventFilter *synctypes.RoomEventFilter,
|
||||
) ([]types.StreamEvent, error) {
|
||||
senders, notSenders := getSendersRoomEventFilter(eventFilter)
|
||||
stmt := sqlutil.TxStmt(txn, s.selectEarlyEventsStmt)
|
||||
|
@ -565,7 +566,7 @@ func (s *outputRoomEventsStatements) SelectEarlyEvents(
|
|||
// selectEvents returns the events for the given event IDs. If an event is
|
||||
// missing from the database, it will be omitted.
|
||||
func (s *outputRoomEventsStatements) SelectEvents(
|
||||
ctx context.Context, txn *sql.Tx, eventIDs []string, filter *gomatrixserverlib.RoomEventFilter, preserveOrder bool,
|
||||
ctx context.Context, txn *sql.Tx, eventIDs []string, filter *synctypes.RoomEventFilter, preserveOrder bool,
|
||||
) ([]types.StreamEvent, error) {
|
||||
var (
|
||||
stmt *sql.Stmt
|
||||
|
@ -637,7 +638,7 @@ func (s *outputRoomEventsStatements) SelectContextEvent(ctx context.Context, txn
|
|||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter,
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||
) (evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
senders, notSenders := getSendersRoomEventFilter(filter)
|
||||
rows, err := sqlutil.TxStmt(txn, s.selectContextBeforeEventStmt).QueryContext(
|
||||
|
@ -672,7 +673,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter,
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||
) (lastID int, evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
senders, notSenders := getSendersRoomEventFilter(filter)
|
||||
rows, err := sqlutil.TxStmt(txn, s.selectContextAfterEventStmt).QueryContext(
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -156,7 +157,7 @@ func (p *presenceStatements) GetMaxPresenceID(ctx context.Context, txn *sql.Tx)
|
|||
func (p *presenceStatements) GetPresenceAfter(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
after types.StreamPosition,
|
||||
filter gomatrixserverlib.EventFilter,
|
||||
filter synctypes.EventFilter,
|
||||
) (presences map[string]*types.PresenceInternal, err error) {
|
||||
presences = make(map[string]*types.PresenceInternal)
|
||||
stmt := sqlutil.TxStmt(txn, p.selectPresenceAfterStmt)
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -323,13 +324,13 @@ func (d *Database) updateRoomState(
|
|||
}
|
||||
|
||||
func (d *Database) GetFilter(
|
||||
ctx context.Context, target *gomatrixserverlib.Filter, localpart string, filterID string,
|
||||
ctx context.Context, target *synctypes.Filter, localpart string, filterID string,
|
||||
) error {
|
||||
return d.Filter.SelectFilter(ctx, nil, target, localpart, filterID)
|
||||
}
|
||||
|
||||
func (d *Database) PutFilter(
|
||||
ctx context.Context, localpart string, filter *gomatrixserverlib.Filter,
|
||||
ctx context.Context, localpart string, filter *synctypes.Filter,
|
||||
) (string, error) {
|
||||
var filterID string
|
||||
var err error
|
||||
|
@ -523,10 +524,10 @@ func (d *Database) SelectContextEvent(ctx context.Context, roomID, eventID strin
|
|||
return d.OutputEvents.SelectContextEvent(ctx, nil, roomID, eventID)
|
||||
}
|
||||
|
||||
func (d *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
func (d *Database) SelectContextBeforeEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
return d.OutputEvents.SelectContextBeforeEvent(ctx, nil, id, roomID, filter)
|
||||
}
|
||||
func (d *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error) {
|
||||
func (d *Database) SelectContextAfterEvent(ctx context.Context, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error) {
|
||||
return d.OutputEvents.SelectContextAfterEvent(ctx, nil, id, roomID, filter)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -82,7 +83,7 @@ func (d *DatabaseTransaction) MaxStreamPositionForNotificationData(ctx context.C
|
|||
return types.StreamPosition(id), nil
|
||||
}
|
||||
|
||||
func (d *DatabaseTransaction) CurrentState(ctx context.Context, roomID string, stateFilterPart *gomatrixserverlib.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
func (d *DatabaseTransaction) CurrentState(ctx context.Context, roomID string, stateFilterPart *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
return d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilterPart, excludeEventIDs)
|
||||
}
|
||||
|
||||
|
@ -109,7 +110,7 @@ func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID
|
|||
summary.JoinedMemberCount = &joinCount
|
||||
|
||||
// Get the room name and canonical alias, if any
|
||||
filter := gomatrixserverlib.DefaultStateFilter()
|
||||
filter := synctypes.DefaultStateFilter()
|
||||
filterTypes := []string{gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias}
|
||||
filterRooms := []string{roomID}
|
||||
|
||||
|
@ -151,7 +152,7 @@ func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID
|
|||
return summary, nil
|
||||
}
|
||||
|
||||
func (d *DatabaseTransaction) RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error) {
|
||||
func (d *DatabaseTransaction) RecentEvents(ctx context.Context, roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter, chronologicalOrder bool, onlySyncEvents bool) (map[string]types.RecentEvents, error) {
|
||||
return d.OutputEvents.SelectRecentEvents(ctx, d.txn, roomIDs, r, eventFilter, chronologicalOrder, onlySyncEvents)
|
||||
}
|
||||
|
||||
|
@ -210,7 +211,7 @@ func (d *DatabaseTransaction) GetStateEvent(
|
|||
}
|
||||
|
||||
func (d *DatabaseTransaction) GetStateEventsForRoom(
|
||||
ctx context.Context, roomID string, stateFilter *gomatrixserverlib.StateFilter,
|
||||
ctx context.Context, roomID string, stateFilter *synctypes.StateFilter,
|
||||
) (stateEvents []*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
stateEvents, err = d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilter, nil)
|
||||
return
|
||||
|
@ -223,7 +224,7 @@ func (d *DatabaseTransaction) GetStateEventsForRoom(
|
|||
// If there was an issue with the retrieval, returns an error
|
||||
func (d *DatabaseTransaction) GetAccountDataInRange(
|
||||
ctx context.Context, userID string, r types.Range,
|
||||
accountDataFilterPart *gomatrixserverlib.EventFilter,
|
||||
accountDataFilterPart *synctypes.EventFilter,
|
||||
) (map[string][]string, types.StreamPosition, error) {
|
||||
return d.AccountData.SelectAccountDataInRange(ctx, d.txn, userID, r, accountDataFilterPart)
|
||||
}
|
||||
|
@ -232,7 +233,7 @@ func (d *DatabaseTransaction) GetEventsInTopologicalRange(
|
|||
ctx context.Context,
|
||||
from, to *types.TopologyToken,
|
||||
roomID string,
|
||||
filter *gomatrixserverlib.RoomEventFilter,
|
||||
filter *synctypes.RoomEventFilter,
|
||||
backwardOrdering bool,
|
||||
) (events []types.StreamEvent, err error) {
|
||||
var minDepth, maxDepth, maxStreamPosForMaxDepth types.StreamPosition
|
||||
|
@ -323,7 +324,7 @@ func (d *DatabaseTransaction) GetBackwardTopologyPos(
|
|||
func (d *DatabaseTransaction) GetStateDeltas(
|
||||
ctx context.Context, device *userapi.Device,
|
||||
r types.Range, userID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
) (deltas []types.StateDelta, joinedRoomsIDs []string, err error) {
|
||||
// Implement membership change algorithm: https://github.com/matrix-org/synapse/blob/v0.19.3/synapse/handlers/sync.py#L821
|
||||
// - Get membership list changes for this user in this sync response
|
||||
|
@ -488,7 +489,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
|
||||
ctx context.Context, device *userapi.Device,
|
||||
r types.Range, userID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
) ([]types.StateDelta, []string, error) {
|
||||
// Look up all memberships for the user. We only care about rooms that a
|
||||
// user has ever interacted with — joined to, kicked/banned from, left.
|
||||
|
@ -597,7 +598,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
|
|||
|
||||
func (d *DatabaseTransaction) currentStateStreamEventsForRoom(
|
||||
ctx context.Context, roomID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
) ([]types.StreamEvent, error) {
|
||||
allState, err := d.CurrentRoomState.SelectCurrentState(ctx, d.txn, roomID, stateFilter, nil)
|
||||
if err != nil {
|
||||
|
@ -647,7 +648,7 @@ func (d *DatabaseTransaction) GetPresences(ctx context.Context, userIDs []string
|
|||
return d.Presence.GetPresenceForUsers(ctx, d.txn, userIDs)
|
||||
}
|
||||
|
||||
func (d *DatabaseTransaction) PresenceAfter(ctx context.Context, after types.StreamPosition, filter gomatrixserverlib.EventFilter) (map[string]*types.PresenceInternal, error) {
|
||||
func (d *DatabaseTransaction) PresenceAfter(ctx context.Context, after types.StreamPosition, filter synctypes.EventFilter) (map[string]*types.PresenceInternal, error) {
|
||||
return d.Presence.GetPresenceAfter(ctx, d.txn, after, filter)
|
||||
}
|
||||
|
||||
|
@ -707,7 +708,7 @@ func (d *DatabaseTransaction) MaxStreamPositionForRelations(ctx context.Context)
|
|||
return types.StreamPosition(id), err
|
||||
}
|
||||
|
||||
func isStatefilterEmpty(filter *gomatrixserverlib.StateFilter) bool {
|
||||
func isStatefilterEmpty(filter *synctypes.StateFilter) bool {
|
||||
if filter == nil {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package shared
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
)
|
||||
|
||||
func Test_isStatefilterEmpty(t *testing.T) {
|
||||
|
@ -12,7 +12,7 @@ func Test_isStatefilterEmpty(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
name string
|
||||
filter *gomatrixserverlib.StateFilter
|
||||
filter *synctypes.StateFilter
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
|
@ -22,42 +22,42 @@ func Test_isStatefilterEmpty(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "Empty filter is empty",
|
||||
filter: &gomatrixserverlib.StateFilter{},
|
||||
filter: &synctypes.StateFilter{},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "NotTypes is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
NotTypes: &filterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Types is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
Types: &filterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Senders is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
Senders: &filterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NotSenders is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
NotSenders: &filterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NotRooms is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
NotRooms: &filterSet,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ContainsURL is set",
|
||||
filter: &gomatrixserverlib.StateFilter{
|
||||
filter: &synctypes.StateFilter{
|
||||
ContainsURL: &boolValue,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -22,8 +22,8 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
const accountDataSchema = `
|
||||
|
@ -89,7 +89,7 @@ func (s *accountDataStatements) SelectAccountDataInRange(
|
|||
ctx context.Context, txn *sql.Tx,
|
||||
userID string,
|
||||
r types.Range,
|
||||
filter *gomatrixserverlib.EventFilter,
|
||||
filter *synctypes.EventFilter,
|
||||
) (data map[string][]string, pos types.StreamPosition, err error) {
|
||||
data = make(map[string][]string)
|
||||
stmt, params, err := prepareWithFilters(
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -264,7 +265,7 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithAnyMembership(
|
|||
// CurrentState returns all the current state events for the given room.
|
||||
func (s *currentRoomStateStatements) SelectCurrentState(
|
||||
ctx context.Context, txn *sql.Tx, roomID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
excludeEventIDs []string,
|
||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
// We're going to query members later, so remove them from this request
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -73,7 +74,7 @@ func NewSqliteFilterTable(db *sql.DB) (tables.Filter, error) {
|
|||
}
|
||||
|
||||
func (s *filterStatements) SelectFilter(
|
||||
ctx context.Context, txn *sql.Tx, target *gomatrixserverlib.Filter, localpart string, filterID string,
|
||||
ctx context.Context, txn *sql.Tx, target *synctypes.Filter, localpart string, filterID string,
|
||||
) error {
|
||||
// Retrieve filter from database (stored as canonical JSON)
|
||||
var filterData []byte
|
||||
|
@ -90,7 +91,7 @@ func (s *filterStatements) SelectFilter(
|
|||
}
|
||||
|
||||
func (s *filterStatements) InsertFilter(
|
||||
ctx context.Context, txn *sql.Tx, filter *gomatrixserverlib.Filter, localpart string,
|
||||
ctx context.Context, txn *sql.Tx, filter *synctypes.Filter, localpart string,
|
||||
) (filterID string, err error) {
|
||||
var existingFilterID string
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -186,7 +187,7 @@ func (s *outputRoomEventsStatements) UpdateEventJSON(ctx context.Context, txn *s
|
|||
// two positions, only the most recent state is returned.
|
||||
func (s *outputRoomEventsStatements) SelectStateInRange(
|
||||
ctx context.Context, txn *sql.Tx, r types.Range,
|
||||
stateFilter *gomatrixserverlib.StateFilter, roomIDs []string,
|
||||
stateFilter *synctypes.StateFilter, roomIDs []string,
|
||||
) (map[string]map[string]bool, map[string]types.StreamEvent, error) {
|
||||
stmtSQL := strings.Replace(selectStateInRangeSQL, "($3)", sqlutil.QueryVariadicOffset(len(roomIDs), 2), 1)
|
||||
inputParams := []interface{}{
|
||||
|
@ -368,7 +369,7 @@ func (s *outputRoomEventsStatements) InsertEvent(
|
|||
|
||||
func (s *outputRoomEventsStatements) SelectRecentEvents(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomIDs []string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter,
|
||||
roomIDs []string, r types.Range, eventFilter *synctypes.RoomEventFilter,
|
||||
chronologicalOrder bool, onlySyncEvents bool,
|
||||
) (map[string]types.RecentEvents, error) {
|
||||
var query string
|
||||
|
@ -431,7 +432,7 @@ func (s *outputRoomEventsStatements) SelectRecentEvents(
|
|||
|
||||
func (s *outputRoomEventsStatements) SelectEarlyEvents(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
roomID string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter,
|
||||
roomID string, r types.Range, eventFilter *synctypes.RoomEventFilter,
|
||||
) ([]types.StreamEvent, error) {
|
||||
stmt, params, err := prepareWithFilters(
|
||||
s.db, txn, selectEarlyEventsSQL,
|
||||
|
@ -468,7 +469,7 @@ func (s *outputRoomEventsStatements) SelectEarlyEvents(
|
|||
// selectEvents returns the events for the given event IDs. If an event is
|
||||
// missing from the database, it will be omitted.
|
||||
func (s *outputRoomEventsStatements) SelectEvents(
|
||||
ctx context.Context, txn *sql.Tx, eventIDs []string, filter *gomatrixserverlib.RoomEventFilter, preserveOrder bool,
|
||||
ctx context.Context, txn *sql.Tx, eventIDs []string, filter *synctypes.RoomEventFilter, preserveOrder bool,
|
||||
) ([]types.StreamEvent, error) {
|
||||
iEventIDs := make([]interface{}, len(eventIDs))
|
||||
for i := range eventIDs {
|
||||
|
@ -477,7 +478,7 @@ func (s *outputRoomEventsStatements) SelectEvents(
|
|||
selectSQL := strings.Replace(selectEventsSQL, "($1)", sqlutil.QueryVariadic(len(eventIDs)), 1)
|
||||
|
||||
if filter == nil {
|
||||
filter = &gomatrixserverlib.RoomEventFilter{Limit: 20}
|
||||
filter = &synctypes.RoomEventFilter{Limit: 20}
|
||||
}
|
||||
stmt, params, err := prepareWithFilters(
|
||||
s.db, txn, selectSQL, iEventIDs,
|
||||
|
@ -581,7 +582,7 @@ func (s *outputRoomEventsStatements) SelectContextEvent(
|
|||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter,
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||
) (evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
stmt, params, err := prepareWithFilters(
|
||||
s.db, txn, selectContextBeforeEventSQL,
|
||||
|
@ -623,7 +624,7 @@ func (s *outputRoomEventsStatements) SelectContextBeforeEvent(
|
|||
}
|
||||
|
||||
func (s *outputRoomEventsStatements) SelectContextAfterEvent(
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter,
|
||||
ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter,
|
||||
) (lastID int, evts []*gomatrixserverlib.HeaderedEvent, err error) {
|
||||
stmt, params, err := prepareWithFilters(
|
||||
s.db, txn, selectContextAfterEventSQL,
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -180,7 +181,7 @@ func (p *presenceStatements) GetMaxPresenceID(ctx context.Context, txn *sql.Tx)
|
|||
// GetPresenceAfter returns the changes presences after a given stream id
|
||||
func (p *presenceStatements) GetPresenceAfter(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
after types.StreamPosition, filter gomatrixserverlib.EventFilter,
|
||||
after types.StreamPosition, filter synctypes.EventFilter,
|
||||
) (presences map[string]*types.PresenceInternal, err error) {
|
||||
presences = make(map[string]*types.PresenceInternal)
|
||||
stmt := sqlutil.TxStmt(txn, p.selectPresenceAfterStmt)
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -153,7 +154,7 @@ func TestRecentEventsPDU(t *testing.T) {
|
|||
for i := range testCases {
|
||||
tc := testCases[i]
|
||||
t.Run(tc.Name, func(st *testing.T) {
|
||||
var filter gomatrixserverlib.RoomEventFilter
|
||||
var filter synctypes.RoomEventFilter
|
||||
var gotEvents map[string]types.RecentEvents
|
||||
var limited bool
|
||||
filter.Limit = tc.Limit
|
||||
|
@ -206,7 +207,7 @@ func TestGetEventsInRangeWithTopologyToken(t *testing.T) {
|
|||
to := types.TopologyToken{}
|
||||
|
||||
// backpaginate 5 messages starting at the latest position.
|
||||
filter := &gomatrixserverlib.RoomEventFilter{Limit: 5}
|
||||
filter := &synctypes.RoomEventFilter{Limit: 5}
|
||||
paginatedEvents, err := snapshot.GetEventsInTopologicalRange(ctx, &from, &to, r.ID, filter, true)
|
||||
if err != nil {
|
||||
t.Fatalf("GetEventsInTopologicalRange returned an error: %s", err)
|
||||
|
@ -932,7 +933,7 @@ func TestRecentEvents(t *testing.T) {
|
|||
}
|
||||
|
||||
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||
filter := gomatrixserverlib.DefaultRoomEventFilter()
|
||||
filter := synctypes.DefaultRoomEventFilter()
|
||||
db, close := MustCreateDatabase(t, dbType)
|
||||
t.Cleanup(close)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
@ -94,7 +95,7 @@ func TestCurrentRoomStateTable(t *testing.T) {
|
|||
func testCurrentState(t *testing.T, ctx context.Context, txn *sql.Tx, tab tables.CurrentRoomState, room *test.Room) {
|
||||
t.Run("test currentState", func(t *testing.T) {
|
||||
// returns the complete state of the room with a default filter
|
||||
filter := gomatrixserverlib.DefaultStateFilter()
|
||||
filter := synctypes.DefaultStateFilter()
|
||||
evs, err := tab.SelectCurrentState(ctx, txn, room.ID, &filter, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -22,13 +22,14 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
type AccountData interface {
|
||||
InsertAccountData(ctx context.Context, txn *sql.Tx, userID, roomID, dataType string) (pos types.StreamPosition, err error)
|
||||
// SelectAccountDataInRange returns a map of room ID to a list of `dataType`.
|
||||
SelectAccountDataInRange(ctx context.Context, txn *sql.Tx, userID string, r types.Range, accountDataEventFilter *gomatrixserverlib.EventFilter) (data map[string][]string, pos types.StreamPosition, err error)
|
||||
SelectAccountDataInRange(ctx context.Context, txn *sql.Tx, userID string, r types.Range, accountDataEventFilter *synctypes.EventFilter) (data map[string][]string, pos types.StreamPosition, err error)
|
||||
SelectMaxAccountDataID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
||||
}
|
||||
|
||||
|
@ -53,7 +54,7 @@ type Peeks interface {
|
|||
}
|
||||
|
||||
type Events interface {
|
||||
SelectStateInRange(ctx context.Context, txn *sql.Tx, r types.Range, stateFilter *gomatrixserverlib.StateFilter, roomIDs []string) (map[string]map[string]bool, map[string]types.StreamEvent, error)
|
||||
SelectStateInRange(ctx context.Context, txn *sql.Tx, r types.Range, stateFilter *synctypes.StateFilter, roomIDs []string) (map[string]map[string]bool, map[string]types.StreamEvent, error)
|
||||
SelectMaxEventID(ctx context.Context, txn *sql.Tx) (id int64, err error)
|
||||
InsertEvent(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
|
@ -66,17 +67,17 @@ type Events interface {
|
|||
// SelectRecentEvents returns events between the two stream positions: exclusive of low and inclusive of high.
|
||||
// If onlySyncEvents has a value of true, only returns the events that aren't marked as to exclude from sync.
|
||||
// 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 *gomatrixserverlib.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)
|
||||
// SelectEarlyEvents returns the earliest events in the given room.
|
||||
SelectEarlyEvents(ctx context.Context, txn *sql.Tx, roomID string, r types.Range, eventFilter *gomatrixserverlib.RoomEventFilter) ([]types.StreamEvent, error)
|
||||
SelectEvents(ctx context.Context, txn *sql.Tx, eventIDs []string, filter *gomatrixserverlib.RoomEventFilter, preserveOrder bool) ([]types.StreamEvent, error)
|
||||
SelectEarlyEvents(ctx context.Context, txn *sql.Tx, roomID string, r types.Range, eventFilter *synctypes.RoomEventFilter) ([]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
|
||||
// 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)
|
||||
|
||||
SelectContextEvent(ctx context.Context, txn *sql.Tx, roomID, eventID string) (int, gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *gomatrixserverlib.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextBeforeEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectContextAfterEvent(ctx context.Context, txn *sql.Tx, id int, roomID string, filter *synctypes.RoomEventFilter) (int, []*gomatrixserverlib.HeaderedEvent, 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)
|
||||
|
@ -107,7 +108,7 @@ type CurrentRoomState interface {
|
|||
DeleteRoomStateByEventID(ctx context.Context, txn *sql.Tx, eventID string) error
|
||||
DeleteRoomStateForRoom(ctx context.Context, txn *sql.Tx, roomID string) error
|
||||
// SelectCurrentState returns all the current state events for the given room.
|
||||
SelectCurrentState(ctx context.Context, txn *sql.Tx, roomID string, stateFilter *gomatrixserverlib.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
SelectCurrentState(ctx context.Context, txn *sql.Tx, roomID string, stateFilter *synctypes.StateFilter, excludeEventIDs []string) ([]*gomatrixserverlib.HeaderedEvent, error)
|
||||
// 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)
|
||||
// SelectRoomIDsWithAnyMembership returns a map of all memberships for the given user.
|
||||
|
@ -179,8 +180,8 @@ type SendToDevice interface {
|
|||
}
|
||||
|
||||
type Filter interface {
|
||||
SelectFilter(ctx context.Context, txn *sql.Tx, target *gomatrixserverlib.Filter, localpart string, filterID string) error
|
||||
InsertFilter(ctx context.Context, txn *sql.Tx, filter *gomatrixserverlib.Filter, localpart string) (filterID string, err error)
|
||||
SelectFilter(ctx context.Context, txn *sql.Tx, target *synctypes.Filter, localpart string, filterID string) error
|
||||
InsertFilter(ctx context.Context, txn *sql.Tx, filter *synctypes.Filter, localpart string) (filterID string, err error)
|
||||
}
|
||||
|
||||
type Receipts interface {
|
||||
|
@ -218,7 +219,7 @@ type Presence interface {
|
|||
UpsertPresence(ctx context.Context, txn *sql.Tx, userID string, statusMsg *string, presence types.Presence, lastActiveTS gomatrixserverlib.Timestamp, fromSync bool) (pos types.StreamPosition, err error)
|
||||
GetPresenceForUsers(ctx context.Context, txn *sql.Tx, userIDs []string) (presence []*types.PresenceInternal, err error)
|
||||
GetMaxPresenceID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error)
|
||||
GetPresenceAfter(ctx context.Context, txn *sql.Tx, after types.StreamPosition, filter gomatrixserverlib.EventFilter) (presences map[string]*types.PresenceInternal, err error)
|
||||
GetPresenceAfter(ctx context.Context, txn *sql.Tx, after types.StreamPosition, filter synctypes.EventFilter) (presences map[string]*types.PresenceInternal, err error)
|
||||
}
|
||||
|
||||
type Relations interface {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -84,7 +85,7 @@ func TestOutputRoomEventsTable(t *testing.T) {
|
|||
}
|
||||
wantEventID := []string{urlEv.EventID()}
|
||||
t := true
|
||||
gotEvents, err = tab.SelectEvents(ctx, txn, wantEventID, &gomatrixserverlib.RoomEventFilter{Limit: 1, ContainsURL: &t}, true)
|
||||
gotEvents, err = tab.SelectEvents(ctx, txn, wantEventID, &synctypes.RoomEventFilter{Limit: 1, ContainsURL: &t}, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to SelectEvents: %s", err)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
)
|
||||
|
@ -96,7 +97,7 @@ func TestPresence(t *testing.T) {
|
|||
}
|
||||
|
||||
// This should return only Bobs status
|
||||
presences, err := tab.GetPresenceAfter(ctx, txn, maxPos, gomatrixserverlib.EventFilter{Limit: 10})
|
||||
presences, err := tab.GetPresenceAfter(ctx, txn, maxPos, synctypes.EventFilter{Limit: 10})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -82,7 +83,7 @@ func (p *AccountDataStreamProvider) IncrementalSync(
|
|||
if globalData, ok := dataRes.GlobalAccountData[dataType]; ok {
|
||||
req.Response.AccountData.Events = append(
|
||||
req.Response.AccountData.Events,
|
||||
gomatrixserverlib.ClientEvent{
|
||||
synctypes.ClientEvent{
|
||||
Type: dataType,
|
||||
Content: gomatrixserverlib.RawJSON(globalData),
|
||||
},
|
||||
|
@ -96,7 +97,7 @@ func (p *AccountDataStreamProvider) IncrementalSync(
|
|||
}
|
||||
joinData.AccountData.Events = append(
|
||||
joinData.AccountData.Events,
|
||||
gomatrixserverlib.ClientEvent{
|
||||
synctypes.ClientEvent{
|
||||
Type: dataType,
|
||||
Content: gomatrixserverlib.RawJSON(roomData),
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -85,7 +86,7 @@ func (p *InviteStreamProvider) IncrementalSync(
|
|||
|
||||
lr := types.NewLeaveResponse()
|
||||
h := sha256.Sum256(append([]byte(roomID), []byte(strconv.FormatInt(int64(to), 10))...))
|
||||
lr.Timeline.Events = append(lr.Timeline.Events, gomatrixserverlib.ClientEvent{
|
||||
lr.Timeline.Events = append(lr.Timeline.Events, synctypes.ClientEvent{
|
||||
// fake event ID which muxes in the to position
|
||||
EventID: "$" + base64.RawURLEncoding.EncodeToString(h[:]),
|
||||
OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()),
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/internal"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
|
||||
|
@ -242,8 +243,8 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
|||
device *userapi.Device,
|
||||
r types.Range,
|
||||
delta types.StateDelta,
|
||||
eventFilter *gomatrixserverlib.RoomEventFilter,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
eventFilter *synctypes.RoomEventFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
req *types.SyncRequest,
|
||||
) (types.StreamPosition, error) {
|
||||
var err error
|
||||
|
@ -365,20 +366,20 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
|||
}
|
||||
}
|
||||
jr.Timeline.PrevBatch = &prevBatch
|
||||
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatSync)
|
||||
jr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
|
||||
// If we are limited by the filter AND the history visibility filter
|
||||
// didn't "remove" events, return that the response is limited.
|
||||
jr.Timeline.Limited = (limited && len(events) == len(recentEvents)) || delta.NewlyJoined
|
||||
jr.State.Events = gomatrixserverlib.HeaderedToClientEvents(delta.StateEvents, gomatrixserverlib.FormatSync)
|
||||
jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
|
||||
req.Response.Rooms.Join[delta.RoomID] = jr
|
||||
|
||||
case gomatrixserverlib.Peek:
|
||||
jr := types.NewJoinResponse()
|
||||
jr.Timeline.PrevBatch = &prevBatch
|
||||
// TODO: Apply history visibility on peeked rooms
|
||||
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(recentEvents, gomatrixserverlib.FormatSync)
|
||||
jr.Timeline.Events = synctypes.HeaderedToClientEvents(recentEvents, synctypes.FormatSync)
|
||||
jr.Timeline.Limited = limited
|
||||
jr.State.Events = gomatrixserverlib.HeaderedToClientEvents(delta.StateEvents, gomatrixserverlib.FormatSync)
|
||||
jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
|
||||
req.Response.Rooms.Peek[delta.RoomID] = jr
|
||||
|
||||
case gomatrixserverlib.Leave:
|
||||
|
@ -387,11 +388,11 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
|||
case gomatrixserverlib.Ban:
|
||||
lr := types.NewLeaveResponse()
|
||||
lr.Timeline.PrevBatch = &prevBatch
|
||||
lr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatSync)
|
||||
lr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
|
||||
// If we are limited by the filter AND the history visibility filter
|
||||
// didn't "remove" events, return that the response is limited.
|
||||
lr.Timeline.Limited = limited && len(events) == len(recentEvents)
|
||||
lr.State.Events = gomatrixserverlib.HeaderedToClientEvents(delta.StateEvents, gomatrixserverlib.FormatSync)
|
||||
lr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
|
||||
req.Response.Rooms.Leave[delta.RoomID] = lr
|
||||
}
|
||||
|
||||
|
@ -420,7 +421,7 @@ func applyHistoryVisibilityFilter(
|
|||
|
||||
// Only get the state again if there are state events in the timeline
|
||||
if len(stateTypes) > 0 {
|
||||
filter := gomatrixserverlib.DefaultStateFilter()
|
||||
filter := synctypes.DefaultStateFilter()
|
||||
filter.Types = &stateTypes
|
||||
filter.Senders = &senders
|
||||
stateEvents, err := snapshot.CurrentState(ctx, roomID, &filter, nil)
|
||||
|
@ -451,7 +452,7 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
|
|||
ctx context.Context,
|
||||
snapshot storage.DatabaseTransaction,
|
||||
roomID string,
|
||||
stateFilter *gomatrixserverlib.StateFilter,
|
||||
stateFilter *synctypes.StateFilter,
|
||||
wantFullState bool,
|
||||
device *userapi.Device,
|
||||
isPeek bool,
|
||||
|
@ -541,17 +542,17 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
|
|||
}
|
||||
|
||||
jr.Timeline.PrevBatch = prevBatch
|
||||
jr.Timeline.Events = gomatrixserverlib.HeaderedToClientEvents(events, gomatrixserverlib.FormatSync)
|
||||
jr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
|
||||
// If we are limited by the filter AND the history visibility filter
|
||||
// didn't "remove" events, return that the response is limited.
|
||||
jr.Timeline.Limited = limited && len(events) == len(recentEvents)
|
||||
jr.State.Events = gomatrixserverlib.HeaderedToClientEvents(stateEvents, gomatrixserverlib.FormatSync)
|
||||
jr.State.Events = synctypes.HeaderedToClientEvents(stateEvents, synctypes.FormatSync)
|
||||
return jr, nil
|
||||
}
|
||||
|
||||
func (p *PDUStreamProvider) lazyLoadMembers(
|
||||
ctx context.Context, snapshot storage.DatabaseTransaction, roomID string,
|
||||
incremental, limited bool, stateFilter *gomatrixserverlib.StateFilter,
|
||||
incremental, limited bool, stateFilter *synctypes.StateFilter,
|
||||
device *userapi.Device,
|
||||
timelineEvents, stateEvents []*gomatrixserverlib.HeaderedEvent,
|
||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||
|
@ -595,7 +596,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
|
|||
wantUsers = append(wantUsers, userID)
|
||||
}
|
||||
// Query missing membership events
|
||||
filter := gomatrixserverlib.DefaultStateFilter()
|
||||
filter := synctypes.DefaultStateFilter()
|
||||
filter.Senders = &wantUsers
|
||||
filter.Types = &[]string{gomatrixserverlib.MRoomMember}
|
||||
memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter)
|
||||
|
@ -612,7 +613,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
|
|||
|
||||
// addIgnoredUsersToFilter adds ignored users to the eventfilter and
|
||||
// the syncreq itself for further use in streams.
|
||||
func (p *PDUStreamProvider) addIgnoredUsersToFilter(ctx context.Context, snapshot storage.DatabaseTransaction, req *types.SyncRequest, eventFilter *gomatrixserverlib.RoomEventFilter) error {
|
||||
func (p *PDUStreamProvider) addIgnoredUsersToFilter(ctx context.Context, snapshot storage.DatabaseTransaction, req *types.SyncRequest, eventFilter *synctypes.RoomEventFilter) error {
|
||||
ignores, err := snapshot.IgnoresForUser(ctx, req.Device.UserID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/syncapi/notifier"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -65,7 +66,7 @@ func (p *PresenceStreamProvider) IncrementalSync(
|
|||
from, to types.StreamPosition,
|
||||
) types.StreamPosition {
|
||||
// We pull out a larger number than the filter asks for, since we're filtering out events later
|
||||
presences, err := snapshot.PresenceAfter(ctx, from, gomatrixserverlib.EventFilter{Limit: 1000})
|
||||
presences, err := snapshot.PresenceAfter(ctx, from, synctypes.EventFilter{Limit: 1000})
|
||||
if err != nil {
|
||||
req.Log.WithError(err).Error("p.DB.PresenceAfter failed")
|
||||
return from
|
||||
|
@ -130,7 +131,7 @@ func (p *PresenceStreamProvider) IncrementalSync(
|
|||
return from
|
||||
}
|
||||
|
||||
req.Response.Presence.Events = append(req.Response.Presence.Events, gomatrixserverlib.ClientEvent{
|
||||
req.Response.Presence.Events = append(req.Response.Presence.Events, synctypes.ClientEvent{
|
||||
Content: content,
|
||||
Sender: presence.UserID,
|
||||
Type: gomatrixserverlib.MPresence,
|
||||
|
@ -202,7 +203,7 @@ func joinedRooms(res *types.Response, userID string) []string {
|
|||
return roomIDs
|
||||
}
|
||||
|
||||
func membershipEventPresent(events []gomatrixserverlib.ClientEvent, userID string) bool {
|
||||
func membershipEventPresent(events []synctypes.ClientEvent, userID string) bool {
|
||||
for _, ev := range events {
|
||||
// it's enough to know that we have our member event here, don't need to check membership content
|
||||
// as it's implied by being in the respective section of the sync response.
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -86,7 +87,7 @@ func (p *ReceiptStreamProvider) IncrementalSync(
|
|||
jr = types.NewJoinResponse()
|
||||
}
|
||||
|
||||
ev := gomatrixserverlib.ClientEvent{
|
||||
ev := synctypes.ClientEvent{
|
||||
Type: gomatrixserverlib.MReceipt,
|
||||
}
|
||||
content := make(map[string]ReceiptMRead)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/internal/caching"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
)
|
||||
|
||||
|
@ -51,7 +52,7 @@ func (p *TypingStreamProvider) IncrementalSync(
|
|||
typingUsers = append(typingUsers, users[i])
|
||||
}
|
||||
}
|
||||
ev := gomatrixserverlib.ClientEvent{
|
||||
ev := synctypes.ClientEvent{
|
||||
Type: gomatrixserverlib.MTyping,
|
||||
}
|
||||
ev.Content, err = json.Marshal(map[string]interface{}{
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
@ -49,7 +50,7 @@ func newSyncRequest(req *http.Request, device userapi.Device, syncDB storage.Dat
|
|||
}
|
||||
|
||||
// Create a default filter and apply a stored filter on top of it (if specified)
|
||||
filter := gomatrixserverlib.DefaultFilter()
|
||||
filter := synctypes.DefaultFilter()
|
||||
filterQuery := req.URL.Query().Get("filter")
|
||||
if filterQuery != "" {
|
||||
if filterQuery[0] == '{' {
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -33,7 +34,7 @@ func (d dummyDB) GetPresences(ctx context.Context, userID []string) ([]*types.Pr
|
|||
return []*types.PresenceInternal{}, nil
|
||||
}
|
||||
|
||||
func (d dummyDB) PresenceAfter(ctx context.Context, after types.StreamPosition, filter gomatrixserverlib.EventFilter) (map[string]*types.PresenceInternal, error) {
|
||||
func (d dummyDB) PresenceAfter(ctx context.Context, after types.StreamPosition, filter synctypes.EventFilter) (map[string]*types.PresenceInternal, error) {
|
||||
return map[string]*types.PresenceInternal{}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/syncapi/routing"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/roomserver"
|
||||
|
@ -473,7 +474,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
|
|||
}
|
||||
// We only care about the returned events at this point
|
||||
var res struct {
|
||||
Chunk []gomatrixserverlib.ClientEvent `json:"chunk"`
|
||||
Chunk []synctypes.ClientEvent `json:"chunk"`
|
||||
}
|
||||
if err := json.NewDecoder(w.Body).Decode(&res); err != nil {
|
||||
t.Errorf("failed to decode response body: %s", err)
|
||||
|
@ -521,7 +522,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
|
|||
}
|
||||
}
|
||||
|
||||
func verifyEventVisible(t *testing.T, wantVisible bool, wantVisibleEvent *gomatrixserverlib.HeaderedEvent, chunk []gomatrixserverlib.ClientEvent) {
|
||||
func verifyEventVisible(t *testing.T, wantVisible bool, wantVisibleEvent *gomatrixserverlib.HeaderedEvent, chunk []synctypes.ClientEvent) {
|
||||
t.Helper()
|
||||
if wantVisible {
|
||||
for _, ev := range chunk {
|
||||
|
|
88
syncapi/synctypes/clientevent.go
Normal file
88
syncapi/synctypes/clientevent.go
Normal file
|
@ -0,0 +1,88 @@
|
|||
/* Copyright 2017 Vector Creations Ltd
|
||||
*
|
||||
* 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 synctypes
|
||||
|
||||
import "github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
type ClientEventFormat int
|
||||
|
||||
const (
|
||||
// FormatAll will include all client event keys
|
||||
FormatAll ClientEventFormat = iota
|
||||
// FormatSync will include only the event keys required by the /sync API. Notably, this
|
||||
// means the 'room_id' will be missing from the events.
|
||||
FormatSync
|
||||
)
|
||||
|
||||
// ClientEvent is an event which is fit for consumption by clients, in accordance with the specification.
|
||||
type ClientEvent struct {
|
||||
Content gomatrixserverlib.RawJSON `json:"content"`
|
||||
EventID string `json:"event_id,omitempty"` // EventID is omitted on receipt events
|
||||
OriginServerTS gomatrixserverlib.Timestamp `json:"origin_server_ts,omitempty"` // OriginServerTS is omitted on receipt events
|
||||
RoomID string `json:"room_id,omitempty"` // RoomID is omitted on /sync responses
|
||||
Sender string `json:"sender,omitempty"` // Sender is omitted on receipt events
|
||||
StateKey *string `json:"state_key,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Unsigned gomatrixserverlib.RawJSON `json:"unsigned,omitempty"`
|
||||
Redacts string `json:"redacts,omitempty"`
|
||||
}
|
||||
|
||||
// ToClientEvents converts server events to client events.
|
||||
func ToClientEvents(serverEvs []*gomatrixserverlib.Event, format ClientEventFormat) []ClientEvent {
|
||||
evs := make([]ClientEvent, 0, len(serverEvs))
|
||||
for _, se := range serverEvs {
|
||||
if se == nil {
|
||||
continue // TODO: shouldn't happen?
|
||||
}
|
||||
evs = append(evs, ToClientEvent(se, format))
|
||||
}
|
||||
return evs
|
||||
}
|
||||
|
||||
// HeaderedToClientEvents converts headered server events to client events.
|
||||
func HeaderedToClientEvents(serverEvs []*gomatrixserverlib.HeaderedEvent, format ClientEventFormat) []ClientEvent {
|
||||
evs := make([]ClientEvent, 0, len(serverEvs))
|
||||
for _, se := range serverEvs {
|
||||
if se == nil {
|
||||
continue // TODO: shouldn't happen?
|
||||
}
|
||||
evs = append(evs, HeaderedToClientEvent(se, format))
|
||||
}
|
||||
return evs
|
||||
}
|
||||
|
||||
// ToClientEvent converts a single server event to a client event.
|
||||
func ToClientEvent(se *gomatrixserverlib.Event, format ClientEventFormat) ClientEvent {
|
||||
ce := ClientEvent{
|
||||
Content: gomatrixserverlib.RawJSON(se.Content()),
|
||||
Sender: se.Sender(),
|
||||
Type: se.Type(),
|
||||
StateKey: se.StateKey(),
|
||||
Unsigned: gomatrixserverlib.RawJSON(se.Unsigned()),
|
||||
OriginServerTS: se.OriginServerTS(),
|
||||
EventID: se.EventID(),
|
||||
Redacts: se.Redacts(),
|
||||
}
|
||||
if format == FormatAll {
|
||||
ce.RoomID = se.RoomID()
|
||||
}
|
||||
return ce
|
||||
}
|
||||
|
||||
// HeaderedToClientEvent converts a single headered server event to a client event.
|
||||
func HeaderedToClientEvent(se *gomatrixserverlib.HeaderedEvent, format ClientEventFormat) ClientEvent {
|
||||
return ToClientEvent(se.Event, format)
|
||||
}
|
105
syncapi/synctypes/clientevent_test.go
Normal file
105
syncapi/synctypes/clientevent_test.go
Normal file
|
@ -0,0 +1,105 @@
|
|||
/* Copyright 2017 Vector Creations Ltd
|
||||
*
|
||||
* 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 synctypes
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
func TestToClientEvent(t *testing.T) { // nolint: gocyclo
|
||||
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{
|
||||
"type": "m.room.name",
|
||||
"state_key": "",
|
||||
"event_id": "$test:localhost",
|
||||
"room_id": "!test:localhost",
|
||||
"sender": "@test:localhost",
|
||||
"content": {
|
||||
"name": "Hello World"
|
||||
},
|
||||
"origin_server_ts": 123456,
|
||||
"unsigned": {
|
||||
"prev_content": {
|
||||
"name": "Goodbye World"
|
||||
}
|
||||
}
|
||||
}`), false, gomatrixserverlib.RoomVersionV1)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create Event: %s", err)
|
||||
}
|
||||
ce := ToClientEvent(ev, FormatAll)
|
||||
if ce.EventID != ev.EventID() {
|
||||
t.Errorf("ClientEvent.EventID: wanted %s, got %s", ev.EventID(), ce.EventID)
|
||||
}
|
||||
if ce.OriginServerTS != ev.OriginServerTS() {
|
||||
t.Errorf("ClientEvent.OriginServerTS: wanted %d, got %d", ev.OriginServerTS(), ce.OriginServerTS)
|
||||
}
|
||||
if ce.StateKey == nil || *ce.StateKey != "" {
|
||||
t.Errorf("ClientEvent.StateKey: wanted '', got %v", ce.StateKey)
|
||||
}
|
||||
if ce.Type != ev.Type() {
|
||||
t.Errorf("ClientEvent.Type: wanted %s, got %s", ev.Type(), ce.Type)
|
||||
}
|
||||
if !bytes.Equal(ce.Content, ev.Content()) {
|
||||
t.Errorf("ClientEvent.Content: wanted %s, got %s", string(ev.Content()), string(ce.Content))
|
||||
}
|
||||
if !bytes.Equal(ce.Unsigned, ev.Unsigned()) {
|
||||
t.Errorf("ClientEvent.Unsigned: wanted %s, got %s", string(ev.Unsigned()), string(ce.Unsigned))
|
||||
}
|
||||
if ce.Sender != ev.Sender() {
|
||||
t.Errorf("ClientEvent.Sender: wanted %s, got %s", ev.Sender(), ce.Sender)
|
||||
}
|
||||
j, err := json.Marshal(ce)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to Marshal ClientEvent: %s", err)
|
||||
}
|
||||
// Marshal sorts keys in structs by the order they are defined in the struct, which is alphabetical
|
||||
out := `{"content":{"name":"Hello World"},"event_id":"$test:localhost","origin_server_ts":123456,` +
|
||||
`"room_id":"!test:localhost","sender":"@test:localhost","state_key":"","type":"m.room.name",` +
|
||||
`"unsigned":{"prev_content":{"name":"Goodbye World"}}}`
|
||||
if !bytes.Equal([]byte(out), j) {
|
||||
t.Errorf("ClientEvent marshalled to wrong bytes: wanted %s, got %s", out, string(j))
|
||||
}
|
||||
}
|
||||
|
||||
func TestToClientFormatSync(t *testing.T) {
|
||||
ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{
|
||||
"type": "m.room.name",
|
||||
"state_key": "",
|
||||
"event_id": "$test:localhost",
|
||||
"room_id": "!test:localhost",
|
||||
"sender": "@test:localhost",
|
||||
"content": {
|
||||
"name": "Hello World"
|
||||
},
|
||||
"origin_server_ts": 123456,
|
||||
"unsigned": {
|
||||
"prev_content": {
|
||||
"name": "Goodbye World"
|
||||
}
|
||||
}
|
||||
}`), false, gomatrixserverlib.RoomVersionV1)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create Event: %s", err)
|
||||
}
|
||||
ce := ToClientEvent(ev, FormatSync)
|
||||
if ce.RoomID != "" {
|
||||
t.Errorf("ClientEvent.RoomID: wanted '', got %s", ce.RoomID)
|
||||
}
|
||||
}
|
152
syncapi/synctypes/filter.go
Normal file
152
syncapi/synctypes/filter.go
Normal file
|
@ -0,0 +1,152 @@
|
|||
// Copyright 2017 Jan Christian Grünhage
|
||||
//
|
||||
// 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 synctypes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Filter is used by clients to specify how the server should filter responses to e.g. sync requests
|
||||
// Specified by: https://spec.matrix.org/v1.6/client-server-api/#filtering
|
||||
type Filter struct {
|
||||
EventFields []string `json:"event_fields,omitempty"`
|
||||
EventFormat string `json:"event_format,omitempty"`
|
||||
Presence EventFilter `json:"presence,omitempty"`
|
||||
AccountData EventFilter `json:"account_data,omitempty"`
|
||||
Room RoomFilter `json:"room,omitempty"`
|
||||
}
|
||||
|
||||
// EventFilter is used to define filtering rules for events
|
||||
type EventFilter struct {
|
||||
Limit int `json:"limit,omitempty"`
|
||||
NotSenders *[]string `json:"not_senders,omitempty"`
|
||||
NotTypes *[]string `json:"not_types,omitempty"`
|
||||
Senders *[]string `json:"senders,omitempty"`
|
||||
Types *[]string `json:"types,omitempty"`
|
||||
}
|
||||
|
||||
// RoomFilter is used to define filtering rules for room-related events
|
||||
type RoomFilter struct {
|
||||
NotRooms *[]string `json:"not_rooms,omitempty"`
|
||||
Rooms *[]string `json:"rooms,omitempty"`
|
||||
Ephemeral RoomEventFilter `json:"ephemeral,omitempty"`
|
||||
IncludeLeave bool `json:"include_leave,omitempty"`
|
||||
State StateFilter `json:"state,omitempty"`
|
||||
Timeline RoomEventFilter `json:"timeline,omitempty"`
|
||||
AccountData RoomEventFilter `json:"account_data,omitempty"`
|
||||
}
|
||||
|
||||
// StateFilter is used to define filtering rules for state events
|
||||
type StateFilter struct {
|
||||
NotSenders *[]string `json:"not_senders,omitempty"`
|
||||
NotTypes *[]string `json:"not_types,omitempty"`
|
||||
Senders *[]string `json:"senders,omitempty"`
|
||||
Types *[]string `json:"types,omitempty"`
|
||||
LazyLoadMembers bool `json:"lazy_load_members,omitempty"`
|
||||
IncludeRedundantMembers bool `json:"include_redundant_members,omitempty"`
|
||||
NotRooms *[]string `json:"not_rooms,omitempty"`
|
||||
Rooms *[]string `json:"rooms,omitempty"`
|
||||
Limit int `json:"limit,omitempty"`
|
||||
UnreadThreadNotifications bool `json:"unread_thread_notifications,omitempty"`
|
||||
ContainsURL *bool `json:"contains_url,omitempty"`
|
||||
}
|
||||
|
||||
// RoomEventFilter is used to define filtering rules for events in rooms
|
||||
type RoomEventFilter struct {
|
||||
Limit int `json:"limit,omitempty"`
|
||||
NotSenders *[]string `json:"not_senders,omitempty"`
|
||||
NotTypes *[]string `json:"not_types,omitempty"`
|
||||
Senders *[]string `json:"senders,omitempty"`
|
||||
Types *[]string `json:"types,omitempty"`
|
||||
LazyLoadMembers bool `json:"lazy_load_members,omitempty"`
|
||||
IncludeRedundantMembers bool `json:"include_redundant_members,omitempty"`
|
||||
NotRooms *[]string `json:"not_rooms,omitempty"`
|
||||
Rooms *[]string `json:"rooms,omitempty"`
|
||||
UnreadThreadNotifications bool `json:"unread_thread_notifications,omitempty"`
|
||||
ContainsURL *bool `json:"contains_url,omitempty"`
|
||||
}
|
||||
|
||||
// Validate checks if the filter contains valid property values
|
||||
func (filter *Filter) Validate() error {
|
||||
if filter.EventFormat != "" && filter.EventFormat != "client" && filter.EventFormat != "federation" {
|
||||
return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultFilter returns the default filter used by the Matrix server if no filter is provided in
|
||||
// the request
|
||||
func DefaultFilter() Filter {
|
||||
return Filter{
|
||||
AccountData: DefaultEventFilter(),
|
||||
EventFields: nil,
|
||||
EventFormat: "client",
|
||||
Presence: DefaultEventFilter(),
|
||||
Room: RoomFilter{
|
||||
AccountData: DefaultRoomEventFilter(),
|
||||
Ephemeral: DefaultRoomEventFilter(),
|
||||
IncludeLeave: false,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
State: DefaultStateFilter(),
|
||||
Timeline: DefaultRoomEventFilter(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultEventFilter returns the default event filter used by the Matrix server if no filter is
|
||||
// provided in the request
|
||||
func DefaultEventFilter() EventFilter {
|
||||
return EventFilter{
|
||||
// parity with synapse: https://github.com/matrix-org/synapse/blob/v1.80.0/synapse/api/filtering.py#L336
|
||||
Limit: 10,
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultStateFilter returns the default state event filter used by the Matrix server if no filter
|
||||
// is provided in the request
|
||||
func DefaultStateFilter() StateFilter {
|
||||
return StateFilter{
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: nil,
|
||||
LazyLoadMembers: false,
|
||||
IncludeRedundantMembers: false,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
ContainsURL: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultRoomEventFilter returns the default room event filter used by the Matrix server if no
|
||||
// filter is provided in the request
|
||||
func DefaultRoomEventFilter() RoomEventFilter {
|
||||
return RoomEventFilter{
|
||||
// parity with synapse: https://github.com/matrix-org/synapse/blob/v1.80.0/synapse/api/filtering.py#L336
|
||||
Limit: 10,
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: nil,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
ContainsURL: nil,
|
||||
}
|
||||
}
|
60
syncapi/synctypes/filter_test.go
Normal file
60
syncapi/synctypes/filter_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package synctypes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Filter(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
want RoomEventFilter
|
||||
}{
|
||||
{
|
||||
name: "empty types filter",
|
||||
input: []byte(`{ "types": [] }`),
|
||||
want: RoomEventFilter{
|
||||
Limit: 0,
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: &[]string{},
|
||||
LazyLoadMembers: false,
|
||||
IncludeRedundantMembers: false,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
ContainsURL: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "absent types filter",
|
||||
input: []byte(`{}`),
|
||||
want: RoomEventFilter{
|
||||
Limit: 0,
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: nil,
|
||||
LazyLoadMembers: false,
|
||||
IncludeRedundantMembers: false,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
ContainsURL: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var f RoomEventFilter
|
||||
if err := json.Unmarshal(tt.input, &f); err != nil {
|
||||
t.Fatalf("unable to parse filter: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(f, tt.want) {
|
||||
t.Fatalf("Expected %+v\ngot %+v", tt.want, f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
)
|
||||
|
||||
|
@ -15,7 +16,7 @@ type SyncRequest struct {
|
|||
Log *logrus.Entry
|
||||
Device *userapi.Device
|
||||
Response *Response
|
||||
Filter gomatrixserverlib.Filter
|
||||
Filter synctypes.Filter
|
||||
Since StreamingToken
|
||||
Timeout time.Duration
|
||||
WantFullState bool
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -451,13 +452,13 @@ type UnreadNotifications struct {
|
|||
}
|
||||
|
||||
type ClientEvents struct {
|
||||
Events []gomatrixserverlib.ClientEvent `json:"events,omitempty"`
|
||||
Events []synctypes.ClientEvent `json:"events,omitempty"`
|
||||
}
|
||||
|
||||
type Timeline struct {
|
||||
Events []gomatrixserverlib.ClientEvent `json:"events"`
|
||||
Limited bool `json:"limited"`
|
||||
PrevBatch *TopologyToken `json:"prev_batch,omitempty"`
|
||||
Events []synctypes.ClientEvent `json:"events"`
|
||||
Limited bool `json:"limited"`
|
||||
PrevBatch *TopologyToken `json:"prev_batch,omitempty"`
|
||||
}
|
||||
|
||||
type Summary struct {
|
||||
|
@ -549,7 +550,7 @@ func NewInviteResponse(event *gomatrixserverlib.HeaderedEvent) *InviteResponse {
|
|||
|
||||
// Then we'll see if we can create a partial of the invite event itself.
|
||||
// This is needed for clients to work out *who* sent the invite.
|
||||
inviteEvent := gomatrixserverlib.ToClientEvent(event.Unwrap(), gomatrixserverlib.FormatSync)
|
||||
inviteEvent := synctypes.ToClientEvent(event.Unwrap(), synctypes.FormatSync)
|
||||
inviteEvent.Unsigned = nil
|
||||
if ev, err := json.Marshal(inviteEvent); err == nil {
|
||||
res.InviteState.Events = append(res.InviteState.Events, ev)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -125,7 +126,7 @@ func TestJoinResponse_MarshalJSON(t *testing.T) {
|
|||
{
|
||||
name: "unread notifications are NOT removed, if state is set",
|
||||
fields: fields{
|
||||
State: &ClientEvents{Events: []gomatrixserverlib.ClientEvent{{Content: []byte("{}")}}},
|
||||
State: &ClientEvents{Events: []synctypes.ClientEvent{{Content: []byte("{}")}}},
|
||||
UnreadNotifications: &UnreadNotifications{NotificationCount: 1},
|
||||
},
|
||||
want: []byte(`{"state":{"events":[{"content":{},"type":""}]},"unread_notifications":{"highlight_count":0,"notification_count":1}}`),
|
||||
|
@ -134,7 +135,7 @@ func TestJoinResponse_MarshalJSON(t *testing.T) {
|
|||
name: "roomID is removed from EDUs",
|
||||
fields: fields{
|
||||
Ephemeral: &ClientEvents{
|
||||
Events: []gomatrixserverlib.ClientEvent{
|
||||
Events: []synctypes.ClientEvent{
|
||||
{RoomID: "!someRandomRoomID:test", Content: []byte("{}")},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/userapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
|
@ -580,12 +581,12 @@ type QueryNotificationsResponse struct {
|
|||
}
|
||||
|
||||
type Notification struct {
|
||||
Actions []*pushrules.Action `json:"actions"` // Required.
|
||||
Event gomatrixserverlib.ClientEvent `json:"event"` // Required.
|
||||
ProfileTag string `json:"profile_tag"` // Required by Sytest, but actually optional.
|
||||
Read bool `json:"read"` // Required.
|
||||
RoomID string `json:"room_id"` // Required.
|
||||
TS gomatrixserverlib.Timestamp `json:"ts"` // Required.
|
||||
Actions []*pushrules.Action `json:"actions"` // Required.
|
||||
Event synctypes.ClientEvent `json:"event"` // Required.
|
||||
ProfileTag string `json:"profile_tag"` // Required by Sytest, but actually optional.
|
||||
Read bool `json:"read"` // Required.
|
||||
RoomID string `json:"room_id"` // Required.
|
||||
TS gomatrixserverlib.Timestamp `json:"ts"` // Required.
|
||||
}
|
||||
|
||||
type QueryNumericLocalpartRequest struct {
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||
"github.com/matrix-org/dendrite/setup/process"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/dendrite/userapi/producers"
|
||||
|
@ -298,7 +299,7 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *gom
|
|||
|
||||
switch {
|
||||
case event.Type() == gomatrixserverlib.MRoomMember:
|
||||
cevent := gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatAll)
|
||||
cevent := synctypes.HeaderedToClientEvent(event, synctypes.FormatAll)
|
||||
var member *localMembership
|
||||
member, err = newLocalMembership(&cevent)
|
||||
if err != nil {
|
||||
|
@ -358,7 +359,7 @@ type localMembership struct {
|
|||
Domain gomatrixserverlib.ServerName
|
||||
}
|
||||
|
||||
func newLocalMembership(event *gomatrixserverlib.ClientEvent) (*localMembership, error) {
|
||||
func newLocalMembership(event *synctypes.ClientEvent) (*localMembership, error) {
|
||||
if event.StateKey == nil {
|
||||
return nil, fmt.Errorf("missing state_key")
|
||||
}
|
||||
|
@ -531,7 +532,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *gomatr
|
|||
// UNSPEC: the spec doesn't say this is a ClientEvent, but the
|
||||
// fields seem to match. room_id should be missing, which
|
||||
// matches the behaviour of FormatSync.
|
||||
Event: gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatSync),
|
||||
Event: synctypes.HeaderedToClientEvent(event, synctypes.FormatSync),
|
||||
// TODO: this is per-device, but it's not part of the primary
|
||||
// key. So inserting one notification per profile tag doesn't
|
||||
// make sense. What is this supposed to be? Sytests require it
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/dendrite/userapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -356,12 +357,12 @@ func Test_OpenID(t *testing.T) {
|
|||
expiresAtMS := time.Now().UnixNano()/int64(time.Millisecond) + openIDLifetimeMS
|
||||
expires, err := db.CreateOpenIDToken(ctx, token, alice.ID)
|
||||
assert.NoError(t, err, "unable to create OpenID token")
|
||||
assert.Equal(t, expiresAtMS, expires)
|
||||
assert.InDelta(t, expiresAtMS, expires, 2) // 2ms leeway
|
||||
|
||||
attributes, err := db.GetOpenIDTokenAttributes(ctx, token)
|
||||
assert.NoError(t, err, "unable to get OpenID token attributes")
|
||||
assert.Equal(t, alice.ID, attributes.UserID)
|
||||
assert.Equal(t, expiresAtMS, attributes.ExpiresAtMS)
|
||||
assert.InDelta(t, expiresAtMS, attributes.ExpiresAtMS, 2) // 2ms leeway
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -526,7 +527,7 @@ func Test_Notification(t *testing.T) {
|
|||
Actions: []*pushrules.Action{
|
||||
{},
|
||||
},
|
||||
Event: gomatrixserverlib.ClientEvent{
|
||||
Event: synctypes.ClientEvent{
|
||||
Content: gomatrixserverlib.RawJSON("{}"),
|
||||
},
|
||||
Read: false,
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/synctypes"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
@ -99,7 +100,7 @@ func TestNotifyUserCountsAsync(t *testing.T) {
|
|||
|
||||
// Insert a dummy event
|
||||
if err := db.InsertNotification(ctx, aliceLocalpart, serverName, dummyEvent.EventID(), 0, nil, &api.Notification{
|
||||
Event: gomatrixserverlib.HeaderedToClientEvent(dummyEvent, gomatrixserverlib.FormatAll),
|
||||
Event: synctypes.HeaderedToClientEvent(dummyEvent, synctypes.FormatAll),
|
||||
}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue