aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-04-19 15:50:33 +0100
committerGitHub <noreply@github.com>2023-04-19 15:50:33 +0100
commit72285b2659a31ebd52c91799c17105d81d996f40 (patch)
tree1855395f5efdc3ea6051dd502882bf62aaa57e7c /syncapi
parent9fa39263c0a4a8d349c8715f6ba30cae30b1b73a (diff)
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/consumers/clientapi.go8
-rw-r--r--syncapi/consumers/presence.go8
-rw-r--r--syncapi/consumers/receipts.go4
-rw-r--r--syncapi/consumers/roomserver.go15
-rw-r--r--syncapi/consumers/sendtodevice.go3
-rw-r--r--syncapi/internal/history_visibility.go15
-rw-r--r--syncapi/internal/keychange.go13
-rw-r--r--syncapi/internal/keychange_test.go5
-rw-r--r--syncapi/notifier/notifier.go9
-rw-r--r--syncapi/producers/federationapi_presence.go4
-rw-r--r--syncapi/routing/context.go3
-rw-r--r--syncapi/routing/messages.go5
-rw-r--r--syncapi/routing/routing.go12
-rw-r--r--syncapi/routing/search.go3
-rw-r--r--syncapi/routing/search_test.go3
-rw-r--r--syncapi/storage/interface.go5
-rw-r--r--syncapi/storage/postgres/current_room_state_table.go5
-rw-r--r--syncapi/storage/postgres/presence_table.go6
-rw-r--r--syncapi/storage/postgres/receipt_table.go4
-rw-r--r--syncapi/storage/shared/storage_consumer.go11
-rw-r--r--syncapi/storage/shared/storage_sync.go33
-rw-r--r--syncapi/storage/sqlite3/current_room_state_table.go5
-rw-r--r--syncapi/storage/sqlite3/presence_table.go6
-rw-r--r--syncapi/storage/sqlite3/receipt_table.go4
-rw-r--r--syncapi/storage/storage_test.go39
-rw-r--r--syncapi/storage/tables/current_room_state_test.go4
-rw-r--r--syncapi/storage/tables/interface.go5
-rw-r--r--syncapi/storage/tables/memberships_test.go17
-rw-r--r--syncapi/storage/tables/output_room_events_test.go9
-rw-r--r--syncapi/storage/tables/presence_table_test.go5
-rw-r--r--syncapi/streams/stream_accountdata.go7
-rw-r--r--syncapi/streams/stream_invite.go8
-rw-r--r--syncapi/streams/stream_pdu.go25
-rw-r--r--syncapi/streams/stream_presence.go6
-rw-r--r--syncapi/streams/stream_receipt.go8
-rw-r--r--syncapi/streams/stream_typing.go7
-rw-r--r--syncapi/sync/requestpool.go8
-rw-r--r--syncapi/sync/requestpool_test.go6
-rw-r--r--syncapi/syncapi_test.go19
-rw-r--r--syncapi/synctypes/clientevent.go27
-rw-r--r--syncapi/types/presence.go10
-rw-r--r--syncapi/types/provider.go8
-rw-r--r--syncapi/types/types.go11
43 files changed, 220 insertions, 198 deletions
diff --git a/syncapi/consumers/clientapi.go b/syncapi/consumers/clientapi.go
index 43dc0f51..3ed455e9 100644
--- a/syncapi/consumers/clientapi.go
+++ b/syncapi/consumers/clientapi.go
@@ -21,7 +21,7 @@ import (
"time"
"github.com/getsentry/sentry-go"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
@@ -49,7 +49,7 @@ type OutputClientDataConsumer struct {
db storage.Database
stream streams.StreamProvider
notifier *notifier.Notifier
- serverName gomatrixserverlib.ServerName
+ serverName spec.ServerName
fts fulltext.Indexer
cfg *config.SyncAPI
}
@@ -121,9 +121,9 @@ func (s *OutputClientDataConsumer) Start() error {
switch ev.Type() {
case "m.room.message":
e.Content = gjson.GetBytes(ev.Content(), "body").String()
- case gomatrixserverlib.MRoomName:
+ case spec.MRoomName:
e.Content = gjson.GetBytes(ev.Content(), "name").String()
- case gomatrixserverlib.MRoomTopic:
+ case spec.MRoomTopic:
e.Content = gjson.GetBytes(ev.Content(), "topic").String()
default:
continue
diff --git a/syncapi/consumers/presence.go b/syncapi/consumers/presence.go
index 6e3150c2..c7c0866b 100644
--- a/syncapi/consumers/presence.go
+++ b/syncapi/consumers/presence.go
@@ -26,7 +26,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/streams"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/dendrite/userapi/api"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
"github.com/sirupsen/logrus"
)
@@ -108,7 +108,7 @@ func (s *PresenceConsumer) Start() error {
for i := range deviceRes.Devices {
if int64(presence.LastActiveTS) < deviceRes.Devices[i].LastSeenTS {
- presence.LastActiveTS = gomatrixserverlib.Timestamp(deviceRes.Devices[i].LastSeenTS)
+ presence.LastActiveTS = spec.Timestamp(deviceRes.Devices[i].LastSeenTS)
}
}
@@ -161,11 +161,11 @@ func (s *PresenceConsumer) onMessage(ctx context.Context, msgs []*nats.Msg) bool
// already checked, so no need to check error
p, _ := types.PresenceFromString(presence)
- s.EmitPresence(ctx, userID, p, statusMsg, gomatrixserverlib.Timestamp(ts), fromSync)
+ s.EmitPresence(ctx, userID, p, statusMsg, spec.Timestamp(ts), fromSync)
return true
}
-func (s *PresenceConsumer) EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts gomatrixserverlib.Timestamp, fromSync bool) {
+func (s *PresenceConsumer) EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts spec.Timestamp, fromSync bool) {
pos, err := s.db.UpdatePresence(ctx, userID, presence, statusMsg, ts, fromSync)
if err != nil {
logrus.WithError(err).WithField("user", userID).WithField("presence", presence).Warn("failed to updated presence for user")
diff --git a/syncapi/consumers/receipts.go b/syncapi/consumers/receipts.go
index e39d43f9..69571f90 100644
--- a/syncapi/consumers/receipts.go
+++ b/syncapi/consumers/receipts.go
@@ -19,7 +19,6 @@ import (
"strconv"
"github.com/getsentry/sentry-go"
- "github.com/matrix-org/gomatrixserverlib"
"github.com/nats-io/nats.go"
log "github.com/sirupsen/logrus"
@@ -30,6 +29,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/streams"
"github.com/matrix-org/dendrite/syncapi/types"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
// OutputReceiptEventConsumer consumes events that originated in the EDU server.
@@ -89,7 +89,7 @@ func (s *OutputReceiptEventConsumer) onMessage(ctx context.Context, msgs []*nats
return true
}
- output.Timestamp = gomatrixserverlib.Timestamp(timestamp)
+ output.Timestamp = spec.Timestamp(timestamp)
streamPos, err := s.db.StoreReceipt(
s.ctx,
diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go
index 21f6104d..c842c0c3 100644
--- a/syncapi/consumers/roomserver.go
+++ b/syncapi/consumers/roomserver.go
@@ -22,6 +22,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
@@ -108,7 +109,7 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms
// Ignore redaction events. We will add them to the database when they are
// validated (when we receive OutputTypeRedactedEvent)
event := output.NewRoomEvent.Event
- if event.Type() == gomatrixserverlib.MRoomRedaction && event.StateKey() == nil {
+ if event.Type() == spec.MRoomRedaction && event.StateKey() == nil {
// in the special case where the event redacts itself, just pass the message through because
// we will never see the other part of the pair
if event.Redacts() != event.EventID() {
@@ -362,7 +363,7 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
}
func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *gomatrixserverlib.HeaderedEvent, sp types.StreamPosition) (types.StreamPosition, error) {
- if ev.Type() != gomatrixserverlib.MRoomMember {
+ if ev.Type() != spec.MRoomMember {
return sp, nil
}
membership, err := ev.Membership()
@@ -370,7 +371,7 @@ func (s *OutputRoomEventConsumer) notifyJoinedPeeks(ctx context.Context, ev *gom
return sp, fmt.Errorf("ev.Membership: %w", err)
}
// TODO: check that it's a join and not a profile change (means unmarshalling prev_content)
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
// check it's a local join
if _, _, err := s.cfg.Matrix.SplitLocalID('@', *ev.StateKey()); err != nil {
return sp, nil
@@ -433,7 +434,7 @@ func (s *OutputRoomEventConsumer) onRetireInviteEvent(
// Only notify clients about retired invite events, if the user didn't accept the invite.
// The PDU stream will also receive an event about accepting the invitation, so there should
// be a "smooth" transition from invite -> join, and not invite -> leave -> join
- if msg.Membership == gomatrixserverlib.Join {
+ if msg.Membership == spec.Join {
return
}
@@ -544,11 +545,11 @@ func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent,
switch ev.Type() {
case "m.room.message":
e.Content = gjson.GetBytes(ev.Content(), "body").String()
- case gomatrixserverlib.MRoomName:
+ case spec.MRoomName:
e.Content = gjson.GetBytes(ev.Content(), "name").String()
- case gomatrixserverlib.MRoomTopic:
+ case spec.MRoomTopic:
e.Content = gjson.GetBytes(ev.Content(), "topic").String()
- case gomatrixserverlib.MRoomRedaction:
+ case spec.MRoomRedaction:
log.Tracef("Redacting event: %s", ev.Redacts())
if err := s.fts.Delete(ev.Redacts()); err != nil {
return fmt.Errorf("failed to delete entry from fulltext index: %w", err)
diff --git a/syncapi/consumers/sendtodevice.go b/syncapi/consumers/sendtodevice.go
index 32208c58..7f387dc0 100644
--- a/syncapi/consumers/sendtodevice.go
+++ b/syncapi/consumers/sendtodevice.go
@@ -20,6 +20,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/nats-io/nats.go"
log "github.com/sirupsen/logrus"
@@ -43,7 +44,7 @@ type OutputSendToDeviceEventConsumer struct {
topic string
db storage.Database
userAPI api.SyncKeyAPI
- isLocalServerName func(gomatrixserverlib.ServerName) bool
+ isLocalServerName func(spec.ServerName) bool
stream streams.StreamProvider
notifier *notifier.Notifier
}
diff --git a/syncapi/internal/history_visibility.go b/syncapi/internal/history_visibility.go
index ee695f0f..10d7383b 100644
--- a/syncapi/internal/history_visibility.go
+++ b/syncapi/internal/history_visibility.go
@@ -20,6 +20,7 @@ import (
"time"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@@ -50,7 +51,7 @@ var calculateHistoryVisibilityDuration = prometheus.NewHistogramVec(
)
var historyVisibilityPriority = map[gomatrixserverlib.HistoryVisibility]uint8{
- gomatrixserverlib.WorldReadable: 0,
+ spec.WorldReadable: 0,
gomatrixserverlib.HistoryVisibilityShared: 1,
gomatrixserverlib.HistoryVisibilityInvited: 2,
gomatrixserverlib.HistoryVisibilityJoined: 3,
@@ -72,23 +73,23 @@ func (ev eventVisibility) allowed() (allowed bool) {
return true
case gomatrixserverlib.HistoryVisibilityJoined:
// If the user’s membership was join, allow.
- if ev.membershipAtEvent == gomatrixserverlib.Join {
+ if ev.membershipAtEvent == spec.Join {
return true
}
return false
case gomatrixserverlib.HistoryVisibilityShared:
// If the user’s membership was join, allow.
// If history_visibility was set to shared, and the user joined the room at any point after the event was sent, allow.
- if ev.membershipAtEvent == gomatrixserverlib.Join || ev.membershipCurrent == gomatrixserverlib.Join {
+ if ev.membershipAtEvent == spec.Join || ev.membershipCurrent == spec.Join {
return true
}
return false
case gomatrixserverlib.HistoryVisibilityInvited:
// If the user’s membership was join, allow.
- if ev.membershipAtEvent == gomatrixserverlib.Join {
+ if ev.membershipAtEvent == spec.Join {
return true
}
- if ev.membershipAtEvent == gomatrixserverlib.Invite {
+ if ev.membershipAtEvent == spec.Invite {
return true
}
return false
@@ -132,7 +133,7 @@ func ApplyHistoryVisibilityFilter(
}
}
// NOTSPEC: Always allow user to see their own membership events (spec contains more "rules")
- if ev.Type() == gomatrixserverlib.MRoomMember && ev.StateKeyEquals(userID) {
+ if ev.Type() == spec.MRoomMember && ev.StateKeyEquals(userID) {
eventsFiltered = append(eventsFiltered, ev)
continue
}
@@ -195,7 +196,7 @@ func visibilityForEvents(
for _, event := range events {
eventID := event.EventID()
vis := eventVisibility{
- membershipAtEvent: gomatrixserverlib.Leave, // default to leave, to not expose events by accident
+ membershipAtEvent: spec.Leave, // default to leave, to not expose events by accident
visibility: event.Visibility,
}
ev, ok := membershipResp.Membership[eventID]
diff --git a/syncapi/internal/keychange.go b/syncapi/internal/keychange.go
index 17d63708..ad5935cd 100644
--- a/syncapi/internal/keychange.go
+++ b/syncapi/internal/keychange.go
@@ -20,6 +20,7 @@ import (
keytypes "github.com/matrix-org/dendrite/userapi/types"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@@ -159,7 +160,7 @@ func TrackChangedUsers(
RoomIDs: newlyLeftRooms,
StateTuples: []gomatrixserverlib.StateKeyTuple{
{
- EventType: gomatrixserverlib.MRoomMember,
+ EventType: spec.MRoomMember,
StateKey: "*",
},
},
@@ -170,7 +171,7 @@ func TrackChangedUsers(
}
for _, state := range stateRes.Rooms {
for tuple, membership := range state {
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
continue
}
queryRes.UserIDsToCount[tuple.StateKey]--
@@ -201,7 +202,7 @@ func TrackChangedUsers(
RoomIDs: newlyJoinedRooms,
StateTuples: []gomatrixserverlib.StateKeyTuple{
{
- EventType: gomatrixserverlib.MRoomMember,
+ EventType: spec.MRoomMember,
StateKey: "*",
},
},
@@ -212,7 +213,7 @@ func TrackChangedUsers(
}
for _, state := range stateRes.Rooms {
for tuple, membership := range state {
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
continue
}
// new user who we weren't previously sharing rooms with
@@ -283,7 +284,7 @@ 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.
- if ev.Type == gomatrixserverlib.MRoomMember && ev.StateKey != nil && *ev.StateKey == userID {
+ if ev.Type == spec.MRoomMember && ev.StateKey != nil && *ev.StateKey == userID {
// ignore e.g. join -> join changes
if gjson.GetBytes(ev.Unsigned, "prev_content.membership").Str == gjson.GetBytes(ev.Content, "membership").Str {
continue
@@ -302,7 +303,7 @@ func membershipEventPresent(events []synctypes.ClientEvent, userID string) bool
func membershipEvents(res *types.Response) (joinUserIDs, leaveUserIDs []string) {
for _, room := range res.Rooms.Join {
for _, ev := range room.Timeline.Events {
- if ev.Type == gomatrixserverlib.MRoomMember && ev.StateKey != nil {
+ if ev.Type == spec.MRoomMember && ev.StateKey != nil {
if strings.Contains(string(ev.Content), `"join"`) {
joinUserIDs = append(joinUserIDs, *ev.StateKey)
} else if strings.Contains(string(ev.Content), `"invite"`) {
diff --git a/syncapi/internal/keychange_test.go b/syncapi/internal/keychange_test.go
index f775276f..11954904 100644
--- a/syncapi/internal/keychange_test.go
+++ b/syncapi/internal/keychange_test.go
@@ -7,6 +7,7 @@ import (
"testing"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -76,12 +77,12 @@ func (s *mockRoomserverAPI) QueryRoomsForUser(ctx context.Context, req *api.Quer
// QueryBulkStateContent does a bulk query for state event content in the given rooms.
func (s *mockRoomserverAPI) QueryBulkStateContent(ctx context.Context, req *api.QueryBulkStateContentRequest, res *api.QueryBulkStateContentResponse) error {
res.Rooms = make(map[string]map[gomatrixserverlib.StateKeyTuple]string)
- if req.AllowWildcards && len(req.StateTuples) == 1 && req.StateTuples[0].EventType == gomatrixserverlib.MRoomMember && req.StateTuples[0].StateKey == "*" {
+ if req.AllowWildcards && len(req.StateTuples) == 1 && req.StateTuples[0].EventType == spec.MRoomMember && req.StateTuples[0].StateKey == "*" {
for _, roomID := range req.RoomIDs {
res.Rooms[roomID] = make(map[gomatrixserverlib.StateKeyTuple]string)
for _, userID := range s.roomIDToJoinedMembers[roomID] {
res.Rooms[roomID][gomatrixserverlib.StateKeyTuple{
- EventType: gomatrixserverlib.MRoomMember,
+ EventType: spec.MRoomMember,
StateKey: userID,
}] = "join"
}
diff --git a/syncapi/notifier/notifier.go b/syncapi/notifier/notifier.go
index 27f7c37b..81b0e7f9 100644
--- a/syncapi/notifier/notifier.go
+++ b/syncapi/notifier/notifier.go
@@ -23,6 +23,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
log "github.com/sirupsen/logrus"
)
@@ -112,16 +113,16 @@ func (n *Notifier) OnNewEvent(
} else {
// Keep the joined user map up-to-date
switch membership {
- case gomatrixserverlib.Invite:
+ case spec.Invite:
usersToNotify = append(usersToNotify, targetUserID)
- case gomatrixserverlib.Join:
+ case spec.Join:
// Manually append the new user's ID so they get notified
// along all members in the room
usersToNotify = append(usersToNotify, targetUserID)
n._addJoinedUser(ev.RoomID(), targetUserID)
- case gomatrixserverlib.Leave:
+ case spec.Leave:
fallthrough
- case gomatrixserverlib.Ban:
+ case spec.Ban:
n._removeJoinedUser(ev.RoomID(), targetUserID)
}
}
diff --git a/syncapi/producers/federationapi_presence.go b/syncapi/producers/federationapi_presence.go
index dc03457e..eab1b0b2 100644
--- a/syncapi/producers/federationapi_presence.go
+++ b/syncapi/producers/federationapi_presence.go
@@ -20,7 +20,7 @@ import (
"github.com/matrix-org/dendrite/setup/jetstream"
"github.com/matrix-org/dendrite/syncapi/types"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
)
@@ -37,7 +37,7 @@ func (f *FederationAPIPresenceProducer) SendPresence(
msg.Header.Set(jetstream.UserID, userID)
msg.Header.Set("presence", presence.String())
msg.Header.Set("from_sync", "true") // only update last_active_ts and presence
- msg.Header.Set("last_active_ts", strconv.Itoa(int(gomatrixserverlib.AsTimestamp(time.Now()))))
+ msg.Header.Set("last_active_ts", strconv.Itoa(int(spec.AsTimestamp(time.Now()))))
if statusMsg != nil {
msg.Header.Set("status_msg", *statusMsg)
diff --git a/syncapi/routing/context.go b/syncapi/routing/context.go
index dd42c7ac..afd61eae 100644
--- a/syncapi/routing/context.go
+++ b/syncapi/routing/context.go
@@ -33,6 +33,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/types"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
)
@@ -283,7 +284,7 @@ func applyLazyLoadMembers(
// Query missing membership events
filter := synctypes.DefaultStateFilter()
filter.Senders = &wantUsers
- filter.Types = &[]string{gomatrixserverlib.MRoomMember}
+ filter.Types = &[]string{spec.MRoomMember}
memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter)
if err != nil {
return nil, err
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go
index 3c416627..6e508a92 100644
--- a/syncapi/routing/messages.go
+++ b/syncapi/routing/messages.go
@@ -23,6 +23,7 @@ import (
"time"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
@@ -200,7 +201,7 @@ func OnIncomingMessagesRequest(
}
// If the user already left the room, grep events from before that
- if membershipResp.Membership == gomatrixserverlib.Leave {
+ if membershipResp.Membership == spec.Leave {
var token types.TopologyToken
token, err = snapshot.EventPositionInTopology(req.Context(), membershipResp.EventID)
if err != nil {
@@ -369,7 +370,7 @@ func (r *messagesReq) retrieveEvents() (
func (r *messagesReq) getStartEnd(events []*gomatrixserverlib.HeaderedEvent) (start, end types.TopologyToken, err error) {
if r.backwardOrdering {
start = *r.from
- if events[len(events)-1].Type() == gomatrixserverlib.MRoomCreate {
+ if events[len(events)-1].Type() == spec.MRoomCreate {
// NOTSPEC: We've hit the beginning of the room so there's really nowhere
// else to go. This seems to fix Element iOS from looping on /messages endlessly.
end = types.TopologyToken{}
diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go
index b1283247..9607aa32 100644
--- a/syncapi/routing/routing.go
+++ b/syncapi/routing/routing.go
@@ -18,7 +18,7 @@ import (
"net/http"
"github.com/gorilla/mux"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
@@ -96,7 +96,7 @@ func Setup(
}, httputil.WithAllowGuests())).Methods(http.MethodGet, http.MethodOptions)
v3mux.Handle("/rooms/{roomId}/context/{eventId}",
- httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ httputil.MakeAuthAPI("context", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil {
return util.ErrorResponse(err)
@@ -112,7 +112,7 @@ func Setup(
).Methods(http.MethodGet, http.MethodOptions)
v1unstablemux.Handle("/rooms/{roomId}/relations/{eventId}",
- httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ httputil.MakeAuthAPI("relations", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil {
return util.ErrorResponse(err)
@@ -126,7 +126,7 @@ func Setup(
).Methods(http.MethodGet, http.MethodOptions)
v1unstablemux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}",
- httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ httputil.MakeAuthAPI("relation_type", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil {
return util.ErrorResponse(err)
@@ -140,7 +140,7 @@ func Setup(
).Methods(http.MethodGet, http.MethodOptions)
v1unstablemux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}",
- httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ httputil.MakeAuthAPI("relation_type_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil {
return util.ErrorResponse(err)
@@ -201,7 +201,7 @@ func Setup(
return util.ErrorResponse(err)
}
at := req.URL.Query().Get("at")
- membership := gomatrixserverlib.Join
+ membership := spec.Join
return GetMemberships(req, device, vars["roomID"], syncDB, rsAPI, true, &membership, nil, at)
}),
).Methods(http.MethodGet, http.MethodOptions)
diff --git a/syncapi/routing/search.go b/syncapi/routing/search.go
index 15cb2f9b..224c6807 100644
--- a/syncapi/routing/search.go
+++ b/syncapi/routing/search.go
@@ -23,6 +23,7 @@ import (
"github.com/blevesearch/bleve/v2/search"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
@@ -184,7 +185,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
for _, ev := range append(eventsBefore, eventsAfter...) {
profile, ok := knownUsersProfiles[event.Sender()]
if !ok {
- stateEvent, err := snapshot.GetStateEvent(ctx, ev.RoomID(), gomatrixserverlib.MRoomMember, ev.Sender())
+ stateEvent, err := snapshot.GetStateEvent(ctx, ev.RoomID(), spec.MRoomMember, ev.Sender())
if err != nil {
logrus.WithError(err).WithField("user_id", event.Sender()).Warn("failed to query userprofile")
continue
diff --git a/syncapi/routing/search_test.go b/syncapi/routing/search_test.go
index 716f3bb8..c8b9c604 100644
--- a/syncapi/routing/search_test.go
+++ b/syncapi/routing/search_test.go
@@ -16,6 +16,7 @@ import (
"github.com/matrix-org/dendrite/test/testrig"
userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
@@ -216,7 +217,7 @@ func TestSearch(t *testing.T) {
for _, x := range room.Events() {
var stateEvents []*gomatrixserverlib.HeaderedEvent
var stateEventIDs []string
- if x.Type() == gomatrixserverlib.MRoomMember {
+ if x.Type() == spec.MRoomMember {
stateEvents = append(stateEvents, x)
stateEventIDs = append(stateEventIDs, x.EventID())
}
diff --git a/syncapi/storage/interface.go b/syncapi/storage/interface.go
index 38c04e85..f5c1223a 100644
--- a/syncapi/storage/interface.go
+++ b/syncapi/storage/interface.go
@@ -18,6 +18,7 @@ import (
"context"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/internal/sqlutil"
@@ -174,7 +175,7 @@ type Database interface {
// 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
- StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error)
+ StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error)
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error
ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error)
UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error
@@ -188,7 +189,7 @@ type Database interface {
type Presence interface {
GetPresences(ctx context.Context, userIDs []string) ([]*types.PresenceInternal, error)
- UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS gomatrixserverlib.Timestamp, fromSync bool) (types.StreamPosition, error)
+ UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS spec.Timestamp, fromSync bool) (types.StreamPosition, error)
}
type SharedUsers interface {
diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go
index b0547758..c2a870c0 100644
--- a/syncapi/storage/postgres/current_room_state_table.go
+++ b/syncapi/storage/postgres/current_room_state_table.go
@@ -29,6 +29,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/synctypes"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const currentRoomStateSchema = `
@@ -278,9 +279,9 @@ func (s *currentRoomStateStatements) SelectCurrentState(
senders, notSenders := getSendersStateFilterFilter(stateFilter)
// We're going to query members later, so remove them from this request
if stateFilter.LazyLoadMembers && !stateFilter.IncludeRedundantMembers {
- notTypes := &[]string{gomatrixserverlib.MRoomMember}
+ notTypes := &[]string{spec.MRoomMember}
if stateFilter.NotTypes != nil {
- *stateFilter.NotTypes = append(*stateFilter.NotTypes, gomatrixserverlib.MRoomMember)
+ *stateFilter.NotTypes = append(*stateFilter.NotTypes, spec.MRoomMember)
} else {
stateFilter.NotTypes = notTypes
}
diff --git a/syncapi/storage/postgres/presence_table.go b/syncapi/storage/postgres/presence_table.go
index 3dba7756..f37b5331 100644
--- a/syncapi/storage/postgres/presence_table.go
+++ b/syncapi/storage/postgres/presence_table.go
@@ -20,7 +20,7 @@ import (
"time"
"github.com/lib/pq"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
@@ -109,7 +109,7 @@ func (p *presenceStatements) UpsertPresence(
userID string,
statusMsg *string,
presence types.Presence,
- lastActiveTS gomatrixserverlib.Timestamp,
+ lastActiveTS spec.Timestamp,
fromSync bool,
) (pos types.StreamPosition, err error) {
if fromSync {
@@ -161,7 +161,7 @@ func (p *presenceStatements) GetPresenceAfter(
) (presences map[string]*types.PresenceInternal, err error) {
presences = make(map[string]*types.PresenceInternal)
stmt := sqlutil.TxStmt(txn, p.selectPresenceAfterStmt)
- afterTS := gomatrixserverlib.AsTimestamp(time.Now().Add(time.Minute * -5))
+ afterTS := spec.AsTimestamp(time.Now().Add(time.Minute * -5))
rows, err := stmt.QueryContext(ctx, after, afterTS, filter.Limit)
if err != nil {
return nil, err
diff --git a/syncapi/storage/postgres/receipt_table.go b/syncapi/storage/postgres/receipt_table.go
index 0fcbebfc..9ab8eece 100644
--- a/syncapi/storage/postgres/receipt_table.go
+++ b/syncapi/storage/postgres/receipt_table.go
@@ -26,7 +26,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/storage/postgres/deltas"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
"github.com/matrix-org/dendrite/syncapi/types"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const receiptsSchema = `
@@ -98,7 +98,7 @@ func NewPostgresReceiptsTable(db *sql.DB) (tables.Receipts, error) {
}.Prepare(db)
}
-func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error) {
+func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error) {
stmt := sqlutil.TxStmt(txn, r.upsertReceipt)
err = stmt.QueryRowContext(ctx, roomId, receiptType, userId, eventId, timestamp).Scan(&pos)
return
diff --git a/syncapi/storage/shared/storage_consumer.go b/syncapi/storage/shared/storage_consumer.go
index 1894a094..47490fb0 100644
--- a/syncapi/storage/shared/storage_consumer.go
+++ b/syncapi/storage/shared/storage_consumer.go
@@ -23,6 +23,7 @@ import (
"github.com/tidwall/gjson"
userapi "github.com/matrix-org/dendrite/userapi/api"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
@@ -504,7 +505,7 @@ func getMembershipFromEvent(ev *gomatrixserverlib.Event, userID string) (string,
}
// StoreReceipt stores user receipts
-func (d *Database) StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error) {
+func (d *Database) StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error) {
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
pos, err = d.Receipts.UpsertReceipt(ctx, txn, roomId, receiptType, userId, eventId, timestamp)
return err
@@ -541,7 +542,7 @@ func (d *Database) UpdateIgnoresForUser(ctx context.Context, userID string, igno
})
}
-func (d *Database) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS gomatrixserverlib.Timestamp, fromSync bool) (types.StreamPosition, error) {
+func (d *Database) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS spec.Timestamp, fromSync bool) (types.StreamPosition, error) {
var pos types.StreamPosition
var err error
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
@@ -561,15 +562,15 @@ func (d *Database) SelectMembershipForUser(ctx context.Context, roomID, userID s
func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
return d.OutputEvents.ReIndex(ctx, nil, limit, afterID, []string{
- gomatrixserverlib.MRoomName,
- gomatrixserverlib.MRoomTopic,
+ spec.MRoomName,
+ spec.MRoomTopic,
"m.room.message",
})
}
func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error {
// No need to unmarshal if the event is a redaction
- if event.Type() == gomatrixserverlib.MRoomRedaction {
+ if event.Type() == spec.MRoomRedaction {
return nil
}
var content gomatrixserverlib.RelationContent
diff --git a/syncapi/storage/shared/storage_sync.go b/syncapi/storage/shared/storage_sync.go
index a614544b..f11cbb57 100644
--- a/syncapi/storage/shared/storage_sync.go
+++ b/syncapi/storage/shared/storage_sync.go
@@ -7,6 +7,7 @@ import (
"math"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/gjson"
"github.com/matrix-org/dendrite/internal/eventutil"
@@ -98,11 +99,11 @@ func (d *DatabaseTransaction) MembershipCount(ctx context.Context, roomID, membe
func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID string) (*types.Summary, error) {
summary := &types.Summary{Heroes: []string{}}
- joinCount, err := d.CurrentRoomState.SelectMembershipCount(ctx, d.txn, roomID, gomatrixserverlib.Join)
+ joinCount, err := d.CurrentRoomState.SelectMembershipCount(ctx, d.txn, roomID, spec.Join)
if err != nil {
return summary, err
}
- inviteCount, err := d.CurrentRoomState.SelectMembershipCount(ctx, d.txn, roomID, gomatrixserverlib.Invite)
+ inviteCount, err := d.CurrentRoomState.SelectMembershipCount(ctx, d.txn, roomID, spec.Invite)
if err != nil {
return summary, err
}
@@ -111,7 +112,7 @@ func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID
// Get the room name and canonical alias, if any
filter := synctypes.DefaultStateFilter()
- filterTypes := []string{gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias}
+ filterTypes := []string{spec.MRoomName, spec.MRoomCanonicalAlias}
filterRooms := []string{roomID}
filter.Types = &filterTypes
@@ -123,11 +124,11 @@ func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID
for _, ev := range evs {
switch ev.Type() {
- case gomatrixserverlib.MRoomName:
+ case spec.MRoomName:
if gjson.GetBytes(ev.Content(), "name").Str != "" {
return summary, nil
}
- case gomatrixserverlib.MRoomCanonicalAlias:
+ case spec.MRoomCanonicalAlias:
if gjson.GetBytes(ev.Content(), "alias").Str != "" {
return summary, nil
}
@@ -135,14 +136,14 @@ func (d *DatabaseTransaction) GetRoomSummary(ctx context.Context, roomID, userID
}
// If there's no room name or canonical alias, get the room heroes, excluding the user
- heroes, err := d.CurrentRoomState.SelectRoomHeroes(ctx, d.txn, roomID, userID, []string{gomatrixserverlib.Join, gomatrixserverlib.Invite})
+ heroes, err := d.CurrentRoomState.SelectRoomHeroes(ctx, d.txn, roomID, userID, []string{spec.Join, spec.Invite})
if err != nil {
return summary, err
}
// "When no joined or invited members are available, this should consist of the banned and left users"
if len(heroes) == 0 {
- heroes, err = d.CurrentRoomState.SelectRoomHeroes(ctx, d.txn, roomID, userID, []string{gomatrixserverlib.Leave, gomatrixserverlib.Ban})
+ heroes, err = d.CurrentRoomState.SelectRoomHeroes(ctx, d.txn, roomID, userID, []string{spec.Leave, spec.Ban})
if err != nil {
return summary, err
}
@@ -349,7 +350,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
joinedRoomIDs := make([]string, 0, len(memberships))
for roomID, membership := range memberships {
allRoomIDs = append(allRoomIDs, roomID)
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
joinedRoomIDs = append(joinedRoomIDs, roomID)
}
}
@@ -415,7 +416,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
}
if !peek.Deleted {
deltas = append(deltas, types.StateDelta{
- Membership: gomatrixserverlib.Peek,
+ Membership: spec.Peek,
StateEvents: d.StreamEventsToEvents(device, state[peek.RoomID]),
RoomID: peek.RoomID,
})
@@ -433,7 +434,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
continue
}
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
// If our membership is now join but the previous membership wasn't
// then this is a "join transition", so we'll insert this room.
if prevMembership != membership {
@@ -472,7 +473,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
// join transitions above.
for _, joinedRoomID := range joinedRoomIDs {
deltas = append(deltas, types.StateDelta{
- Membership: gomatrixserverlib.Join,
+ Membership: spec.Join,
StateEvents: d.StreamEventsToEvents(device, stateFiltered[joinedRoomID]),
RoomID: joinedRoomID,
NewlyJoined: newlyJoinedRooms[joinedRoomID],
@@ -505,7 +506,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
joinedRoomIDs := make([]string, 0, len(memberships))
for roomID, membership := range memberships {
allRoomIDs = append(allRoomIDs, roomID)
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
joinedRoomIDs = append(joinedRoomIDs, roomID)
}
}
@@ -529,7 +530,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
return nil, nil, stateErr
}
deltas[peek.RoomID] = types.StateDelta{
- Membership: gomatrixserverlib.Peek,
+ Membership: spec.Peek,
StateEvents: d.StreamEventsToEvents(device, s),
RoomID: peek.RoomID,
}
@@ -555,7 +556,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
for roomID, stateStreamEvents := range state {
for _, ev := range stateStreamEvents {
if membership, _ := getMembershipFromEvent(ev.Event, userID); membership != "" {
- if membership != gomatrixserverlib.Join { // We've already added full state for all joined rooms above.
+ if membership != spec.Join { // We've already added full state for all joined rooms above.
deltas[roomID] = types.StateDelta{
Membership: membership,
MembershipPos: ev.StreamPosition,
@@ -579,7 +580,7 @@ func (d *DatabaseTransaction) GetStateDeltasForFullStateSync(
return nil, nil, stateErr
}
deltas[joinedRoomID] = types.StateDelta{
- Membership: gomatrixserverlib.Join,
+ Membership: spec.Join,
StateEvents: d.StreamEventsToEvents(device, s),
RoomID: joinedRoomID,
}
@@ -636,7 +637,7 @@ func (d *DatabaseTransaction) GetRoomReceipts(ctx context.Context, roomIDs []str
func (d *DatabaseTransaction) GetUserUnreadNotificationCountsForRooms(ctx context.Context, userID string, rooms map[string]string) (map[string]*eventutil.NotificationData, error) {
roomIDs := make([]string, 0, len(rooms))
for roomID, membership := range rooms {
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
continue
}
roomIDs = append(roomIDs, roomID)
diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go
index c681933d..01dcff69 100644
--- a/syncapi/storage/sqlite3/current_room_state_table.go
+++ b/syncapi/storage/sqlite3/current_room_state_table.go
@@ -30,6 +30,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/synctypes"
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const currentRoomStateSchema = `
@@ -270,9 +271,9 @@ func (s *currentRoomStateStatements) SelectCurrentState(
) ([]*gomatrixserverlib.HeaderedEvent, error) {
// We're going to query members later, so remove them from this request
if stateFilter.LazyLoadMembers && !stateFilter.IncludeRedundantMembers {
- notTypes := &[]string{gomatrixserverlib.MRoomMember}
+ notTypes := &[]string{spec.MRoomMember}
if stateFilter.NotTypes != nil {
- *stateFilter.NotTypes = append(*stateFilter.NotTypes, gomatrixserverlib.MRoomMember)
+ *stateFilter.NotTypes = append(*stateFilter.NotTypes, spec.MRoomMember)
} else {
stateFilter.NotTypes = notTypes
}
diff --git a/syncapi/storage/sqlite3/presence_table.go b/syncapi/storage/sqlite3/presence_table.go
index 5f76b370..573fbad6 100644
--- a/syncapi/storage/sqlite3/presence_table.go
+++ b/syncapi/storage/sqlite3/presence_table.go
@@ -20,7 +20,7 @@ import (
"strings"
"time"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
@@ -113,7 +113,7 @@ func (p *presenceStatements) UpsertPresence(
userID string,
statusMsg *string,
presence types.Presence,
- lastActiveTS gomatrixserverlib.Timestamp,
+ lastActiveTS spec.Timestamp,
fromSync bool,
) (pos types.StreamPosition, err error) {
pos, err = p.streamIDStatements.nextPresenceID(ctx, txn)
@@ -185,7 +185,7 @@ func (p *presenceStatements) GetPresenceAfter(
) (presences map[string]*types.PresenceInternal, err error) {
presences = make(map[string]*types.PresenceInternal)
stmt := sqlutil.TxStmt(txn, p.selectPresenceAfterStmt)
- afterTS := gomatrixserverlib.AsTimestamp(time.Now().Add(time.Minute * -5))
+ afterTS := spec.AsTimestamp(time.Now().Add(time.Minute * -5))
rows, err := stmt.QueryContext(ctx, after, afterTS, filter.Limit)
if err != nil {
return nil, err
diff --git a/syncapi/storage/sqlite3/receipt_table.go b/syncapi/storage/sqlite3/receipt_table.go
index ca3d80fb..b973903b 100644
--- a/syncapi/storage/sqlite3/receipt_table.go
+++ b/syncapi/storage/sqlite3/receipt_table.go
@@ -25,7 +25,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/storage/sqlite3/deltas"
"github.com/matrix-org/dendrite/syncapi/storage/tables"
"github.com/matrix-org/dendrite/syncapi/types"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
const receiptsSchema = `
@@ -97,7 +97,7 @@ func NewSqliteReceiptsTable(db *sql.DB, streamID *StreamIDStatements) (tables.Re
}
// UpsertReceipt creates new user receipts
-func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error) {
+func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error) {
pos, err = r.streamIDStatements.nextReceiptID(ctx, txn)
if err != nil {
return
diff --git a/syncapi/storage/storage_test.go b/syncapi/storage/storage_test.go
index fa3f54c0..2cc1378b 100644
--- a/syncapi/storage/storage_test.go
+++ b/syncapi/storage/storage_test.go
@@ -16,6 +16,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/types"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
)
@@ -777,7 +778,7 @@ func TestRoomSummary(t *testing.T) {
name: "invited user",
wantSummary: &types.Summary{JoinedMemberCount: pointer(1), InvitedMemberCount: pointer(1), Heroes: []string{bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
},
@@ -786,10 +787,10 @@ func TestRoomSummary(t *testing.T) {
name: "invited user, but declined",
wantSummary: &types.Summary{JoinedMemberCount: pointer(1), InvitedMemberCount: pointer(0), Heroes: []string{bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(bob.ID))
},
@@ -798,10 +799,10 @@ func TestRoomSummary(t *testing.T) {
name: "joined user after invitation",
wantSummary: &types.Summary{JoinedMemberCount: pointer(2), InvitedMemberCount: pointer(0), Heroes: []string{bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
},
@@ -810,10 +811,10 @@ func TestRoomSummary(t *testing.T) {
name: "multiple joined user",
wantSummary: &types.Summary{JoinedMemberCount: pointer(3), InvitedMemberCount: pointer(0), Heroes: []string{charlie.ID, bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, charlie, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, charlie, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(charlie.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
},
@@ -822,10 +823,10 @@ func TestRoomSummary(t *testing.T) {
name: "multiple joined/invited user",
wantSummary: &types.Summary{JoinedMemberCount: pointer(2), InvitedMemberCount: pointer(1), Heroes: []string{charlie.ID, bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(charlie.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
},
@@ -834,13 +835,13 @@ func TestRoomSummary(t *testing.T) {
name: "multiple joined/invited/left user",
wantSummary: &types.Summary{JoinedMemberCount: pointer(1), InvitedMemberCount: pointer(1), Heroes: []string{charlie.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "invite",
}, test.WithStateKey(charlie.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(bob.ID))
},
@@ -849,10 +850,10 @@ func TestRoomSummary(t *testing.T) {
name: "leaving user after joining",
wantSummary: &types.Summary{JoinedMemberCount: pointer(1), InvitedMemberCount: pointer(0), Heroes: []string{bob.ID}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(bob.ID))
},
@@ -862,7 +863,7 @@ func TestRoomSummary(t *testing.T) {
wantSummary: &types.Summary{JoinedMemberCount: pointer(len(moreUserIDs) + 1), InvitedMemberCount: pointer(0), Heroes: moreUserIDs[:5]},
additionalEvents: func(t *testing.T, room *test.Room) {
for _, x := range moreUsers {
- room.CreateAndInsert(t, x, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, x, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(x.ID))
}
@@ -872,10 +873,10 @@ func TestRoomSummary(t *testing.T) {
name: "canonical alias set",
wantSummary: &types.Summary{JoinedMemberCount: pointer(2), InvitedMemberCount: pointer(0), Heroes: []string{}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomCanonicalAlias, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomCanonicalAlias, map[string]interface{}{
"alias": "myalias",
}, test.WithStateKey(""))
},
@@ -884,10 +885,10 @@ func TestRoomSummary(t *testing.T) {
name: "room name set",
wantSummary: &types.Summary{JoinedMemberCount: pointer(2), InvitedMemberCount: pointer(0), Heroes: []string{}},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomName, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomName, map[string]interface{}{
"name": "my room name",
}, test.WithStateKey(""))
},
diff --git a/syncapi/storage/tables/current_room_state_test.go b/syncapi/storage/tables/current_room_state_test.go
index 5fe06c3c..7d4ec812 100644
--- a/syncapi/storage/tables/current_room_state_test.go
+++ b/syncapi/storage/tables/current_room_state_test.go
@@ -14,7 +14,7 @@ import (
"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"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
func newCurrentRoomStateTable(t *testing.T, dbType test.DBType) (tables.CurrentRoomState, *sql.DB, func()) {
@@ -115,7 +115,7 @@ func testCurrentState(t *testing.T, ctx context.Context, txn *sql.Tx, tab tables
t.Fatalf("expected %d state events, got %d", expectCount, gotCount)
}
// same as above, but with existing NotTypes defined
- notTypes := []string{gomatrixserverlib.MRoomMember}
+ notTypes := []string{spec.MRoomMember}
filter.NotTypes = &notTypes
evs, err = tab.SelectCurrentState(ctx, txn, room.ID, &filter, nil)
if err != nil {
diff --git a/syncapi/storage/tables/interface.go b/syncapi/storage/tables/interface.go
index 94c9c402..6384fb91 100644
--- a/syncapi/storage/tables/interface.go
+++ b/syncapi/storage/tables/interface.go
@@ -19,6 +19,7 @@ import (
"database/sql"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal/eventutil"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -183,7 +184,7 @@ type Filter interface {
}
type Receipts interface {
- UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error)
+ UpsertReceipt(ctx context.Context, txn *sql.Tx, roomId, receiptType, userId, eventId string, timestamp spec.Timestamp) (pos types.StreamPosition, err error)
SelectRoomReceiptsAfter(ctx context.Context, txn *sql.Tx, roomIDs []string, streamPos types.StreamPosition) (types.StreamPosition, []types.OutputReceiptEvent, error)
SelectMaxReceiptID(ctx context.Context, txn *sql.Tx) (id int64, err error)
PurgeReceipts(ctx context.Context, txn *sql.Tx, roomID string) error
@@ -214,7 +215,7 @@ type Ignores interface {
}
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)
+ UpsertPresence(ctx context.Context, txn *sql.Tx, userID string, statusMsg *string, presence types.Presence, lastActiveTS spec.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 synctypes.EventFilter) (presences map[string]*types.PresenceInternal, err error)
diff --git a/syncapi/storage/tables/memberships_test.go b/syncapi/storage/tables/memberships_test.go
index df593ae7..2e8375c3 100644
--- a/syncapi/storage/tables/memberships_test.go
+++ b/syncapi/storage/tables/memberships_test.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/setup/config"
@@ -65,7 +66,7 @@ func TestMembershipsTable(t *testing.T) {
u := test.NewUser(t)
users = append(users, u.ID)
- ev := room.CreateAndInsert(t, u, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ ev := room.CreateAndInsert(t, u, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(u.ID))
userEvents = append(userEvents, ev)
@@ -92,7 +93,7 @@ func TestMembershipsTable(t *testing.T) {
func testMembershipCount(t *testing.T, ctx context.Context, table tables.Memberships, room *test.Room) {
t.Run("membership counts are correct", func(t *testing.T) {
// After 10 events, we should have 6 users (5 create related [incl. one member event], 5 member events = 6 users)
- count, err := table.SelectMembershipCount(ctx, nil, room.ID, gomatrixserverlib.Join, 10)
+ count, err := table.SelectMembershipCount(ctx, nil, room.ID, spec.Join, 10)
if err != nil {
t.Fatalf("failed to get membership count: %s", err)
}
@@ -102,7 +103,7 @@ func testMembershipCount(t *testing.T, ctx context.Context, table tables.Members
}
// After 100 events, we should have all 11 users
- count, err = table.SelectMembershipCount(ctx, nil, room.ID, gomatrixserverlib.Join, 100)
+ count, err = table.SelectMembershipCount(ctx, nil, room.ID, spec.Join, 100)
if err != nil {
t.Fatalf("failed to get membership count: %s", err)
}
@@ -126,12 +127,12 @@ func testUpsert(t *testing.T, ctx context.Context, table tables.Memberships, mem
if pos != expectedPos {
t.Fatalf("expected pos to be %d, got %d", expectedPos, pos)
}
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
t.Fatalf("expected membership to be join, got %s", membership)
}
// Create a new event which gets upserted and should not cause issues
- ev := room.CreateAndInsert(t, user, gomatrixserverlib.MRoomMember, map[string]interface{}{
- "membership": gomatrixserverlib.Join,
+ ev := room.CreateAndInsert(t, user, spec.MRoomMember, map[string]interface{}{
+ "membership": spec.Join,
}, test.WithStateKey(user.ID))
// Insert the same event again, but with different positions, which should get updated
if err = table.UpsertMembership(ctx, nil, ev, 2, 2); err != nil {
@@ -147,7 +148,7 @@ func testUpsert(t *testing.T, ctx context.Context, table tables.Memberships, mem
if pos != expectedPos {
t.Fatalf("expected pos to be %d, got %d", expectedPos, pos)
}
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
t.Fatalf("expected membership to be join, got %s", membership)
}
@@ -155,7 +156,7 @@ func testUpsert(t *testing.T, ctx context.Context, table tables.Memberships, mem
if membership, _, err = table.SelectMembershipForUser(ctx, nil, room.ID, user.ID, 1); err != nil {
t.Fatalf("failed to select membership: %s", err)
}
- if membership != gomatrixserverlib.Leave {
+ if membership != spec.Leave {
t.Fatalf("expected membership to be leave, got %s", membership)
}
})
diff --git a/syncapi/storage/tables/output_room_events_test.go b/syncapi/storage/tables/output_room_events_test.go
index 69587800..9b755dc8 100644
--- a/syncapi/storage/tables/output_room_events_test.go
+++ b/syncapi/storage/tables/output_room_events_test.go
@@ -15,6 +15,7 @@ import (
"github.com/matrix-org/dendrite/syncapi/synctypes"
"github.com/matrix-org/dendrite/test"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
func newOutputRoomEventsTable(t *testing.T, dbType test.DBType) (tables.Events, *sql.DB, func()) {
@@ -110,11 +111,11 @@ func TestReindex(t *testing.T) {
alice := test.NewUser(t)
room := test.NewRoom(t, alice)
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomName, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomName, map[string]interface{}{
"name": "my new room name",
}, test.WithStateKey(""))
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomTopic, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomTopic, map[string]interface{}{
"topic": "my new room topic",
}, test.WithStateKey(""))
@@ -141,8 +142,8 @@ func TestReindex(t *testing.T) {
}
events, err := tab.ReIndex(ctx, nil, 10, 0, []string{
- gomatrixserverlib.MRoomName,
- gomatrixserverlib.MRoomTopic,
+ spec.MRoomName,
+ spec.MRoomTopic,
"m.room.message"})
if err != nil {
t.Fatal(err)
diff --git a/syncapi/storage/tables/presence_table_test.go b/syncapi/storage/tables/presence_table_test.go
index cb7a4dee..d8161836 100644
--- a/syncapi/storage/tables/presence_table_test.go
+++ b/syncapi/storage/tables/presence_table_test.go
@@ -7,8 +7,6 @@ import (
"testing"
"time"
- "github.com/matrix-org/gomatrixserverlib"
-
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/storage/postgres"
@@ -17,6 +15,7 @@ import (
"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/spec"
)
func mustPresenceTable(t *testing.T, dbType test.DBType) (tables.Presence, func()) {
@@ -52,7 +51,7 @@ func TestPresence(t *testing.T) {
ctx := context.Background()
statusMsg := "Hello World!"
- timestamp := gomatrixserverlib.AsTimestamp(time.Now())
+ timestamp := spec.AsTimestamp(time.Now())
var txn *sql.Tx
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
diff --git a/syncapi/streams/stream_accountdata.go b/syncapi/streams/stream_accountdata.go
index 22953b8c..51f2a3d3 100644
--- a/syncapi/streams/stream_accountdata.go
+++ b/syncapi/streams/stream_accountdata.go
@@ -3,12 +3,11 @@ package streams
import (
"context"
- "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"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type AccountDataStreamProvider struct {
@@ -85,7 +84,7 @@ func (p *AccountDataStreamProvider) IncrementalSync(
req.Response.AccountData.Events,
synctypes.ClientEvent{
Type: dataType,
- Content: gomatrixserverlib.RawJSON(globalData),
+ Content: spec.RawJSON(globalData),
},
)
}
@@ -99,7 +98,7 @@ func (p *AccountDataStreamProvider) IncrementalSync(
joinData.AccountData.Events,
synctypes.ClientEvent{
Type: dataType,
- Content: gomatrixserverlib.RawJSON(roomData),
+ Content: spec.RawJSON(roomData),
},
)
req.Response.Rooms.Join[roomID] = joinData
diff --git a/syncapi/streams/stream_invite.go b/syncapi/streams/stream_invite.go
index a4414f31..becd863a 100644
--- a/syncapi/streams/stream_invite.go
+++ b/syncapi/streams/stream_invite.go
@@ -8,7 +8,7 @@ import (
"strconv"
"time"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/synctypes"
@@ -79,7 +79,7 @@ func (p *InviteStreamProvider) IncrementalSync(
membership, _, err := snapshot.SelectMembershipForUser(ctx, roomID, req.Device.UserID, math.MaxInt64)
// Skip if the user is an existing member of the room.
// Otherwise, the NewLeaveResponse will eject the user from the room unintentionally
- if membership == gomatrixserverlib.Join ||
+ if membership == spec.Join ||
err != nil {
continue
}
@@ -89,12 +89,12 @@ func (p *InviteStreamProvider) IncrementalSync(
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()),
+ OriginServerTS: spec.AsTimestamp(time.Now()),
RoomID: roomID,
Sender: req.Device.UserID,
StateKey: &req.Device.UserID,
Type: "m.room.member",
- Content: gomatrixserverlib.RawJSON(`{"membership":"leave"}`),
+ Content: spec.RawJSON(`{"membership":"leave"}`),
})
req.Response.Rooms.Leave[roomID] = lr
}
diff --git a/syncapi/streams/stream_pdu.go b/syncapi/streams/stream_pdu.go
index e29e29f7..41c58481 100644
--- a/syncapi/streams/stream_pdu.go
+++ b/syncapi/streams/stream_pdu.go
@@ -13,6 +13,7 @@ import (
"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/spec"
"github.com/matrix-org/dendrite/syncapi/notifier"
"github.com/matrix-org/gomatrixserverlib"
@@ -70,7 +71,7 @@ func (p *PDUStreamProvider) CompleteSync(
}
// Extract room state and recent events for all rooms the user is joined to.
- joinedRoomIDs, err := snapshot.RoomIDsWithMembership(ctx, req.Device.UserID, gomatrixserverlib.Join)
+ joinedRoomIDs, err := snapshot.RoomIDsWithMembership(ctx, req.Device.UserID, spec.Join)
if err != nil {
req.Log.WithError(err).Error("p.DB.RoomIDsWithMembership failed")
return from
@@ -110,7 +111,7 @@ func (p *PDUStreamProvider) CompleteSync(
continue
}
req.Response.Rooms.Join[roomID] = jr
- req.Rooms[roomID] = gomatrixserverlib.Join
+ req.Rooms[roomID] = spec.Join
}
// Add peeked rooms.
@@ -185,7 +186,7 @@ func (p *PDUStreamProvider) IncrementalSync(
}
for _, roomID := range syncJoinedRooms {
- req.Rooms[roomID] = gomatrixserverlib.Join
+ req.Rooms[roomID] = spec.Join
}
if len(stateDeltas) == 0 {
@@ -312,8 +313,8 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
hasMembershipChange := false
for _, recentEvent := range recentStreamEvents {
- if recentEvent.Type() == gomatrixserverlib.MRoomMember && recentEvent.StateKey() != nil {
- if membership, _ := recentEvent.Membership(); membership == gomatrixserverlib.Join {
+ if recentEvent.Type() == spec.MRoomMember && recentEvent.StateKey() != nil {
+ if membership, _ := recentEvent.Membership(); membership == spec.Join {
req.MembershipChanges[*recentEvent.StateKey()] = struct{}{}
}
hasMembershipChange = true
@@ -357,7 +358,7 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
}
switch delta.Membership {
- case gomatrixserverlib.Join:
+ case spec.Join:
jr := types.NewJoinResponse()
if hasMembershipChange {
jr.Summary, err = snapshot.GetRoomSummary(ctx, delta.RoomID, device.UserID)
@@ -373,7 +374,7 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
req.Response.Rooms.Join[delta.RoomID] = jr
- case gomatrixserverlib.Peek:
+ case spec.Peek:
jr := types.NewJoinResponse()
jr.Timeline.PrevBatch = &prevBatch
// TODO: Apply history visibility on peeked rooms
@@ -382,10 +383,10 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
jr.State.Events = synctypes.HeaderedToClientEvents(delta.StateEvents, synctypes.FormatSync)
req.Response.Rooms.Peek[delta.RoomID] = jr
- case gomatrixserverlib.Leave:
+ case spec.Leave:
fallthrough // transitions to leave are the same as ban
- case gomatrixserverlib.Ban:
+ case spec.Ban:
lr := types.NewLeaveResponse()
lr.Timeline.PrevBatch = &prevBatch
lr.Timeline.Events = synctypes.HeaderedToClientEvents(events, synctypes.FormatSync)
@@ -527,7 +528,7 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
event := events[0]
// If this is the beginning of the room, we can't go back further. We're going to return
// the TopologyToken from the last event instead. (Synapse returns the /sync next_Batch)
- if event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("") {
+ if event.Type() == spec.MRoomCreate && event.StateKeyEquals("") {
event = events[len(events)-1]
}
backwardTopologyPos, backwardStreamPos, err = snapshot.PositionInTopology(ctx, event.EventID())
@@ -575,7 +576,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
newStateEvents := make([]*gomatrixserverlib.HeaderedEvent, 0, len(stateEvents))
// Remove existing membership events we don't care about, e.g. users not in the timeline.events
for _, event := range stateEvents {
- if event.Type() == gomatrixserverlib.MRoomMember && event.StateKey() != nil {
+ if event.Type() == spec.MRoomMember && event.StateKey() != nil {
// If this is a gapped incremental sync, we still want this membership
isGappedIncremental := limited && incremental
// We want this users membership event, keep it in the list
@@ -598,7 +599,7 @@ func (p *PDUStreamProvider) lazyLoadMembers(
// Query missing membership events
filter := synctypes.DefaultStateFilter()
filter.Senders = &wantUsers
- filter.Types = &[]string{gomatrixserverlib.MRoomMember}
+ filter.Types = &[]string{spec.MRoomMember}
memberships, err := snapshot.GetStateEventsForRoom(ctx, roomID, &filter)
if err != nil {
return stateEvents, err
diff --git a/syncapi/streams/stream_presence.go b/syncapi/streams/stream_presence.go
index 81f33207..32424066 100644
--- a/syncapi/streams/stream_presence.go
+++ b/syncapi/streams/stream_presence.go
@@ -20,13 +20,13 @@ import (
"fmt"
"sync"
- "github.com/matrix-org/gomatrixserverlib"
"github.com/tidwall/gjson"
"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"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type PresenceStreamProvider struct {
@@ -134,7 +134,7 @@ func (p *PresenceStreamProvider) IncrementalSync(
req.Response.Presence.Events = append(req.Response.Presence.Events, synctypes.ClientEvent{
Content: content,
Sender: presence.UserID,
- Type: gomatrixserverlib.MPresence,
+ Type: spec.MPresence,
})
if presence.StreamPos > lastPos {
lastPos = presence.StreamPos
@@ -207,7 +207,7 @@ 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.
- if ev.Type == gomatrixserverlib.MRoomMember && ev.StateKey != nil && *ev.StateKey == userID {
+ if ev.Type == spec.MRoomMember && ev.StateKey != nil && *ev.StateKey == userID {
// ignore e.g. join -> join changes
if gjson.GetBytes(ev.Unsigned, "prev_content.membership").Str == gjson.GetBytes(ev.Content, "membership").Str {
continue
diff --git a/syncapi/streams/stream_receipt.go b/syncapi/streams/stream_receipt.go
index 88db0054..ed52dc5c 100644
--- a/syncapi/streams/stream_receipt.go
+++ b/syncapi/streams/stream_receipt.go
@@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/synctypes"
@@ -46,7 +46,7 @@ func (p *ReceiptStreamProvider) IncrementalSync(
) types.StreamPosition {
var joinedRooms []string
for roomID, membership := range req.Rooms {
- if membership == gomatrixserverlib.Join {
+ if membership == spec.Join {
joinedRooms = append(joinedRooms, roomID)
}
}
@@ -88,7 +88,7 @@ func (p *ReceiptStreamProvider) IncrementalSync(
}
ev := synctypes.ClientEvent{
- Type: gomatrixserverlib.MReceipt,
+ Type: spec.MReceipt,
}
content := make(map[string]ReceiptMRead)
for _, receipt := range receipts {
@@ -119,5 +119,5 @@ type ReceiptMRead struct {
}
type ReceiptTS struct {
- TS gomatrixserverlib.Timestamp `json:"ts"`
+ TS spec.Timestamp `json:"ts"`
}
diff --git a/syncapi/streams/stream_typing.go b/syncapi/streams/stream_typing.go
index b0e7d9e7..15500a47 100644
--- a/syncapi/streams/stream_typing.go
+++ b/syncapi/streams/stream_typing.go
@@ -4,12 +4,11 @@ import (
"context"
"encoding/json"
- "github.com/matrix-org/gomatrixserverlib"
-
"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"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type TypingStreamProvider struct {
@@ -33,7 +32,7 @@ func (p *TypingStreamProvider) IncrementalSync(
) types.StreamPosition {
var err error
for roomID, membership := range req.Rooms {
- if membership != gomatrixserverlib.Join {
+ if membership != spec.Join {
continue
}
@@ -53,7 +52,7 @@ func (p *TypingStreamProvider) IncrementalSync(
}
}
ev := synctypes.ClientEvent{
- Type: gomatrixserverlib.MTyping,
+ Type: spec.MTyping,
}
ev.Content, err = json.Marshal(map[string]interface{}{
"user_ids": typingUsers,
diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go
index 68f91387..6baaff3c 100644
--- a/syncapi/sync/requestpool.go
+++ b/syncapi/sync/requestpool.go
@@ -25,7 +25,7 @@ import (
"sync"
"time"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
@@ -61,7 +61,7 @@ type PresencePublisher interface {
}
type PresenceConsumer interface {
- EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts gomatrixserverlib.Timestamp, fromSync bool)
+ EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts spec.Timestamp, fromSync bool)
}
// NewRequestPool makes a new RequestPool
@@ -138,7 +138,7 @@ func (rp *RequestPool) updatePresence(db storage.Presence, presence string, user
newPresence := types.PresenceInternal{
Presence: presenceID,
UserID: userID,
- LastActiveTS: gomatrixserverlib.AsTimestamp(time.Now()),
+ LastActiveTS: spec.AsTimestamp(time.Now()),
}
// ensure we also send the current status_msg to federated servers and not nil
@@ -170,7 +170,7 @@ func (rp *RequestPool) updatePresence(db storage.Presence, presence string, user
// the /sync response else we may not return presence: online immediately.
rp.consumer.EmitPresence(
context.Background(), userID, presenceID, newPresence.ClientFields.StatusMsg,
- gomatrixserverlib.AsTimestamp(time.Now()), true,
+ spec.AsTimestamp(time.Now()), true,
)
}
diff --git a/syncapi/sync/requestpool_test.go b/syncapi/sync/requestpool_test.go
index 7bce0a0c..93be46d0 100644
--- a/syncapi/sync/requestpool_test.go
+++ b/syncapi/sync/requestpool_test.go
@@ -9,7 +9,7 @@ import (
"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"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type dummyPublisher struct {
@@ -26,7 +26,7 @@ func (d *dummyPublisher) SendPresence(userID string, presence types.Presence, st
type dummyDB struct{}
-func (d dummyDB) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS gomatrixserverlib.Timestamp, fromSync bool) (types.StreamPosition, error) {
+func (d dummyDB) UpdatePresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, lastActiveTS spec.Timestamp, fromSync bool) (types.StreamPosition, error) {
return 0, nil
}
@@ -44,7 +44,7 @@ func (d dummyDB) MaxStreamPositionForPresence(ctx context.Context) (types.Stream
type dummyConsumer struct{}
-func (d dummyConsumer) EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts gomatrixserverlib.Timestamp, fromSync bool) {
+func (d dummyConsumer) EmitPresence(ctx context.Context, userID string, presence types.Presence, statusMsg *string, ts spec.Timestamp, fromSync bool) {
}
diff --git a/syncapi/syncapi_test.go b/syncapi/syncapi_test.go
index 6496a607..c120f882 100644
--- a/syncapi/syncapi_test.go
+++ b/syncapi/syncapi_test.go
@@ -15,6 +15,7 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/nats-io/nats.go"
"github.com/tidwall/gjson"
@@ -612,10 +613,10 @@ func TestGetMembership(t *testing.T) {
}))
},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(alice.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
},
@@ -631,10 +632,10 @@ func TestGetMembership(t *testing.T) {
}))
},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(alice.ID))
},
@@ -650,7 +651,7 @@ func TestGetMembership(t *testing.T) {
}))
},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(alice.ID))
},
@@ -666,7 +667,7 @@ func TestGetMembership(t *testing.T) {
}))
},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
},
@@ -706,10 +707,10 @@ func TestGetMembership(t *testing.T) {
}))
},
additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "join",
}, test.WithStateKey(bob.ID))
- room.CreateAndInsert(t, bob, gomatrixserverlib.MRoomMember, map[string]interface{}{
+ room.CreateAndInsert(t, bob, spec.MRoomMember, map[string]interface{}{
"membership": "leave",
}, test.WithStateKey(bob.ID))
},
@@ -1141,7 +1142,7 @@ func TestUpdateRelations(t *testing.T) {
},
{
name: "redactions are ignored",
- eventType: gomatrixserverlib.MRoomRedaction,
+ eventType: spec.MRoomRedaction,
eventContent: map[string]interface{}{
"m.relates_to": map[string]interface{}{
"event_id": "$randomEventID",
diff --git a/syncapi/synctypes/clientevent.go b/syncapi/synctypes/clientevent.go
index 0d1e85bc..0bf04cdb 100644
--- a/syncapi/synctypes/clientevent.go
+++ b/syncapi/synctypes/clientevent.go
@@ -15,7 +15,10 @@
package synctypes
-import "github.com/matrix-org/gomatrixserverlib"
+import (
+ "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
+)
type ClientEventFormat int
@@ -29,15 +32,15 @@ const (
// 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"`
+ Content spec.RawJSON `json:"content"`
+ EventID string `json:"event_id,omitempty"` // EventID is omitted on receipt events
+ OriginServerTS spec.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 spec.RawJSON `json:"unsigned,omitempty"`
+ Redacts string `json:"redacts,omitempty"`
}
// ToClientEvents converts server events to client events.
@@ -67,11 +70,11 @@ func HeaderedToClientEvents(serverEvs []*gomatrixserverlib.HeaderedEvent, format
// 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()),
+ Content: spec.RawJSON(se.Content()),
Sender: se.Sender(),
Type: se.Type(),
StateKey: se.StateKey(),
- Unsigned: gomatrixserverlib.RawJSON(se.Unsigned()),
+ Unsigned: spec.RawJSON(se.Unsigned()),
OriginServerTS: se.OriginServerTS(),
EventID: se.EventID(),
Redacts: se.Redacts(),
diff --git a/syncapi/types/presence.go b/syncapi/types/presence.go
index 30e025b9..a9c5e3a4 100644
--- a/syncapi/types/presence.go
+++ b/syncapi/types/presence.go
@@ -18,7 +18,7 @@ import (
"strings"
"time"
- "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type Presence uint8
@@ -60,10 +60,10 @@ func PresenceFromString(input string) (Presence, bool) {
type PresenceInternal struct {
ClientFields PresenceClientResponse
- StreamPos StreamPosition `json:"-"`
- UserID string `json:"-"`
- LastActiveTS gomatrixserverlib.Timestamp `json:"-"`
- Presence Presence `json:"-"`
+ StreamPos StreamPosition `json:"-"`
+ UserID string `json:"-"`
+ LastActiveTS spec.Timestamp `json:"-"`
+ Presence Presence `json:"-"`
}
// Equals compares p1 with p2.
diff --git a/syncapi/types/provider.go b/syncapi/types/provider.go
index f77f8342..a0fcec0f 100644
--- a/syncapi/types/provider.go
+++ b/syncapi/types/provider.go
@@ -4,11 +4,11 @@ import (
"context"
"time"
- "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/syncapi/synctypes"
userapi "github.com/matrix-org/dendrite/userapi/api"
+ "github.com/matrix-org/gomatrixserverlib/spec"
)
type SyncRequest struct {
@@ -35,11 +35,11 @@ func (r *SyncRequest) IsRoomPresent(roomID string) bool {
return false
}
switch membership {
- case gomatrixserverlib.Join:
+ case spec.Join:
return true
- case gomatrixserverlib.Invite:
+ case spec.Invite:
return true
- case gomatrixserverlib.Peek:
+ case spec.Peek:
return true
default:
return false
diff --git a/syncapi/types/types.go b/syncapi/types/types.go
index 0c522fc3..ed17eb56 100644
--- a/syncapi/types/types.go
+++ b/syncapi/types/types.go
@@ -22,6 +22,7 @@ import (
"strings"
"github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/gjson"
"github.com/matrix-org/dendrite/roomserver/api"
@@ -606,11 +607,11 @@ type Peek struct {
// OutputReceiptEvent is an entry in the receipt output kafka log
type OutputReceiptEvent struct {
- UserID string `json:"user_id"`
- RoomID string `json:"room_id"`
- EventID string `json:"event_id"`
- Type string `json:"type"`
- Timestamp gomatrixserverlib.Timestamp `json:"timestamp"`
+ UserID string `json:"user_id"`
+ RoomID string `json:"room_id"`
+ EventID string `json:"event_id"`
+ Type string `json:"type"`
+ Timestamp spec.Timestamp `json:"timestamp"`
}
// OutputSendToDeviceEvent is an entry in the send-to-device output kafka log.