Skip to content

Commit dabdf5a

Browse files
committed
Override origin_server_ts
1 parent 70036ac commit dabdf5a

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

Diff for: internal/b/blueprints.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ type Room struct {
6969
}
7070

7171
type Event struct {
72-
Type string
73-
Sender string
74-
StateKey *string
75-
PrevEvents []string
76-
Content map[string]interface{}
72+
Type string
73+
Sender string
74+
OriginServerTS uint64
75+
StateKey *string
76+
PrevEvents []string
77+
Content map[string]interface{}
7778
// This field is ignored in blueprints as clients are unable to set it. Used with federation.Server
7879
Unsigned map[string]interface{}
7980
}

Diff for: internal/client/client.go

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func (c *CSAPI) SendEvent(t *testing.T, roomID string, e b.Event) string {
9797
query.Add("prev_event", prevEvent)
9898
}
9999

100+
if e.OriginServerTS != 0 {
101+
query.Add("origin_server_ts", strconv.FormatUint(e.OriginServerTS, 10))
102+
}
103+
100104
b, err := json.Marshal(e.Content)
101105
if err != nil {
102106
t.Fatalf("CSAPI.Do failed to marshal JSON body: %s", err)

Diff for: tests/msc2716_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ package tests
99
import (
1010
"net/url"
1111
"testing"
12+
"time"
1213

1314
"github.com/matrix-org/complement/internal/b"
15+
"github.com/matrix-org/complement/internal/client"
1416
"github.com/matrix-org/complement/internal/must"
1517
"github.com/sirupsen/logrus"
1618
"github.com/tidwall/gjson"
@@ -33,6 +35,13 @@ func TestBackfillingHistory(t *testing.T) {
3335
"body": "Message A",
3436
},
3537
})
38+
39+
insertTime := time.Now()
40+
insertOriginServerTs := uint64(insertTime.UnixNano() / 1000000)
41+
42+
// wait 3ms to ensure that the timestamp changes enough intervals for each message we try to insert later
43+
time.Sleep(3 * time.Millisecond)
44+
3645
// eventB
3746
alice.SendEventSynced(t, roomID, b.Event{
3847
Type: "m.room.message",
@@ -56,6 +65,7 @@ func TestBackfillingHistory(t *testing.T) {
5665
PrevEvents: []string{
5766
eventA,
5867
},
68+
OriginServerTS: insertOriginServerTs,
5969
Content: map[string]interface{}{
6070
"msgtype": "m.text",
6171
"body": "Message 1",
@@ -68,6 +78,7 @@ func TestBackfillingHistory(t *testing.T) {
6878
PrevEvents: []string{
6979
event1,
7080
},
81+
OriginServerTS: insertOriginServerTs + 1,
7182
Content: map[string]interface{}{
7283
"msgtype": "m.text",
7384
"body": "Message 2",
@@ -80,6 +91,7 @@ func TestBackfillingHistory(t *testing.T) {
8091
PrevEvents: []string{
8192
event2,
8293
},
94+
OriginServerTS: insertOriginServerTs + 2,
8395
Content: map[string]interface{}{
8496
"msgtype": "m.text",
8597
"body": "Message 3",
@@ -92,8 +104,11 @@ func TestBackfillingHistory(t *testing.T) {
92104
})
93105

94106
t.Logf("aweawfeefwaweafeafw")
107+
body := client.ParseJSON(t, res)
95108
logrus.WithFields(logrus.Fields{
96-
"res": res,
109+
"insertOriginServerTs": insertOriginServerTs,
110+
"res": res,
111+
"body": string(body),
97112
}).Error("messages res")
98113

99114
t.Run("parallel", func(t *testing.T) {

0 commit comments

Comments
 (0)