aboutsummaryrefslogtreecommitdiff
path: root/userapi
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2023-04-04 18:16:53 +0100
committerGitHub <noreply@github.com>2023-04-04 17:16:53 +0000
commit3691423626c94418388c48c1a91ac69dcd8b196b (patch)
treeab93bff2fe0ad7ba8c0417c55832abc57e14b167 /userapi
parent985298cfc46cb6b33ab44d32a63a933d03e16429 (diff)
Move GMSL client types to Dendrite (#3045)
GMSL is intended for Federation only. Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/357
Diffstat (limited to 'userapi')
-rw-r--r--userapi/api/api.go13
-rw-r--r--userapi/consumers/roomserver.go7
-rw-r--r--userapi/storage/storage_test.go7
-rw-r--r--userapi/util/notify_test.go3
4 files changed, 17 insertions, 13 deletions
diff --git a/userapi/api/api.go b/userapi/api/api.go
index 5fd7992c..f65f81ad 100644
--- a/userapi/api/api.go
+++ b/userapi/api/api.go
@@ -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 {
diff --git a/userapi/consumers/roomserver.go b/userapi/consumers/roomserver.go
index 47d33095..6704658d 100644
--- a/userapi/consumers/roomserver.go
+++ b/userapi/consumers/roomserver.go
@@ -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
diff --git a/userapi/storage/storage_test.go b/userapi/storage/storage_test.go
index cf7c5144..7afcda6e 100644
--- a/userapi/storage/storage_test.go
+++ b/userapi/storage/storage_test.go
@@ -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,
diff --git a/userapi/util/notify_test.go b/userapi/util/notify_test.go
index 69461ddd..d6cbad7d 100644
--- a/userapi/util/notify_test.go
+++ b/userapi/util/notify_test.go
@@ -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)
}