aboutsummaryrefslogtreecommitdiff
path: root/syncapi/sync
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-03-19 12:07:01 +0000
committerGitHub <noreply@github.com>2020-03-19 12:07:01 +0000
commitad5849d2224245e1277b8bc7d3e2104ed6061a99 (patch)
tree8551c3d1096a650ecca0cba0e5edf6ad91d078e0 /syncapi/sync
parentbfbf96eec9152f61cb3e54154f1ed82148d82a8a (diff)
HeaderedEvents in sync API (#922)
* Use HeaderedEvent in syncapi * Update notifier test * Fix persisting headered event * Clean up unused API function * Fix overshadowed err from linter * Write headered JSON to invites table too * Rename event_json to headered_event_json in syncapi database schemae * Fix invites_table queries * Update QueryRoomVersionCapabilitiesResponse comment * Fix syncapi SQLite
Diffstat (limited to 'syncapi/sync')
-rw-r--r--syncapi/sync/notifier.go2
-rw-r--r--syncapi/sync/notifier_test.go25
2 files changed, 17 insertions, 10 deletions
diff --git a/syncapi/sync/notifier.go b/syncapi/sync/notifier.go
index aaee49d3..0d805011 100644
--- a/syncapi/sync/notifier.go
+++ b/syncapi/sync/notifier.go
@@ -67,7 +67,7 @@ func NewNotifier(pos types.PaginationToken) *Notifier {
// Typically a consumer supplies a posUpdate with the latest sync position for the
// event type it handles, leaving other fields as 0.
func (n *Notifier) OnNewEvent(
- ev *gomatrixserverlib.Event, roomID string, userIDs []string,
+ ev *gomatrixserverlib.HeaderedEvent, roomID string, userIDs []string,
posUpdate types.PaginationToken,
) {
// update the current position then notify relevant /sync streams.
diff --git a/syncapi/sync/notifier_test.go b/syncapi/sync/notifier_test.go
index 350f8559..350d757c 100644
--- a/syncapi/sync/notifier_test.go
+++ b/syncapi/sync/notifier_test.go
@@ -16,6 +16,7 @@ package sync
import (
"context"
+ "encoding/json"
"fmt"
"sync"
"testing"
@@ -29,9 +30,9 @@ import (
)
var (
- randomMessageEvent gomatrixserverlib.Event
- aliceInviteBobEvent gomatrixserverlib.Event
- bobLeaveEvent gomatrixserverlib.Event
+ randomMessageEvent gomatrixserverlib.HeaderedEvent
+ aliceInviteBobEvent gomatrixserverlib.HeaderedEvent
+ bobLeaveEvent gomatrixserverlib.HeaderedEvent
syncPositionVeryOld types.PaginationToken
syncPositionBefore types.PaginationToken
syncPositionAfter types.PaginationToken
@@ -67,7 +68,8 @@ func init() {
syncPositionAfter2.PDUPosition = 13
var err error
- randomMessageEvent, err = gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{
+ err = json.Unmarshal([]byte(`{
+ "_room_version": "1",
"type": "m.room.message",
"content": {
"body": "Hello World",
@@ -75,13 +77,15 @@ func init() {
},
"sender": "@noone:localhost",
"room_id": "`+roomID+`",
+ "origin": "localhost",
"origin_server_ts": 12345,
"event_id": "$randomMessageEvent:localhost"
- }`), false)
+ }`), &randomMessageEvent)
if err != nil {
panic(err)
}
- aliceInviteBobEvent, err = gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{
+ err = json.Unmarshal([]byte(`{
+ "_room_version": "1",
"type": "m.room.member",
"state_key": "`+bob+`",
"content": {
@@ -89,13 +93,15 @@ func init() {
},
"sender": "`+alice+`",
"room_id": "`+roomID+`",
+ "origin": "localhost",
"origin_server_ts": 12345,
"event_id": "$aliceInviteBobEvent:localhost"
- }`), false)
+ }`), &aliceInviteBobEvent)
if err != nil {
panic(err)
}
- bobLeaveEvent, err = gomatrixserverlib.NewEventFromTrustedJSON([]byte(`{
+ err = json.Unmarshal([]byte(`{
+ "_room_version": "1",
"type": "m.room.member",
"state_key": "`+bob+`",
"content": {
@@ -103,9 +109,10 @@ func init() {
},
"sender": "`+bob+`",
"room_id": "`+roomID+`",
+ "origin": "localhost",
"origin_server_ts": 12345,
"event_id": "$bobLeaveEvent:localhost"
- }`), false)
+ }`), &bobLeaveEvent)
if err != nil {
panic(err)
}