From 72651514977fd6dd9799599e4d5bf8462fc4c098 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 12 Oct 2022 10:24:40 -0400 Subject: [PATCH 1/3] Ensure threaded receipts come down sync properly. --- tests/csapi/thread_notifications_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index cbfd3515..85fd8f41 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -29,6 +29,20 @@ func syncHasUnreadNotifs(roomID string, check func(gjson.Result, gjson.Result) b } } +func syncHasUnthreadedReadReceipt(roomID, userID, eventID string) client.SyncCheckOpt { + return client.SyncEphemeralHas(roomID, func(result gjson.Result) bool { + userReceipt := result.Get("content").Get(eventID).Get(`m\.read`).Get(userID) + return result.Get("type").Str == "m.receipt" && userReceipt.Exists() && !userReceipt.Get("thread_id").Exists() + }) +} + +func syncHasThreadedReadReceipt(roomID, userID, eventID, threadID string) client.SyncCheckOpt { + return client.SyncEphemeralHas(roomID, func(result gjson.Result) bool { + userReceipt := result.Get("content").Get(eventID).Get(`m\.read`).Get(userID) + return result.Get("type").Str == "m.receipt" && userReceipt.Exists() && userReceipt.Get("thread_id").Str == threadID + }) +} + // Test behavior of threaded receipts and notifications. // // 1. Send a series of messages, some of which are in threads. @@ -138,6 +152,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 2 && r.Get("notification_count").Num == 3 && !t.Exists() }), @@ -148,6 +163,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && @@ -163,6 +179,8 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstThreadEventID, firstEventID), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 2 && r.Get("notification_count").Num == 2 && !t.Exists() }), @@ -173,6 +191,8 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, firstThreadEventID, firstEventID), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && @@ -188,6 +208,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasUnthreadedReadReceipt(roomID, bob.UserID, secondEventID), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 0 && r.Get("notification_count").Num == 0 && !t.Exists() }), @@ -198,6 +219,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), + syncHasUnthreadedReadReceipt(roomID, bob.UserID, secondEventID), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 0 && r.Get("notification_count").Num == 0 && !t.Exists() }), From b93449904fe98ab38b8d848ce4da2db6e35f533e Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 27 Oct 2022 10:31:15 -0400 Subject: [PATCH 2/3] Add some comments & fix event references. --- tests/csapi/thread_notifications_test.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index 85fd8f41..2c92432d 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -29,6 +29,8 @@ func syncHasUnreadNotifs(roomID string, check func(gjson.Result, gjson.Result) b } } +// Builds a `SyncCheckOpt` which enforces that a sync result has an unthreaded read +// receipt for the given user in the the given room at the expected event. func syncHasUnthreadedReadReceipt(roomID, userID, eventID string) client.SyncCheckOpt { return client.SyncEphemeralHas(roomID, func(result gjson.Result) bool { userReceipt := result.Get("content").Get(eventID).Get(`m\.read`).Get(userID) @@ -36,6 +38,9 @@ func syncHasUnthreadedReadReceipt(roomID, userID, eventID string) client.SyncChe }) } +// Builds a `SyncCheckOpt` which enforces that a sync result has an threaded read +// receipt for the given user in the the given room at the expected event for the +// given thread. func syncHasThreadedReadReceipt(roomID, userID, eventID, threadID string) client.SyncCheckOpt { return client.SyncEphemeralHas(roomID, func(result gjson.Result) bool { userReceipt := result.Get("content").Get(eventID).Get(`m\.read`).Get(userID) @@ -70,7 +75,7 @@ func TestThreadedReceipts(t *testing.T) { roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.JoinRoom(t, roomID, nil) - // A next batch token which is past the initial room creation. + // A next batch token which is past the initial room creation. bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Send an initial message as alice. @@ -152,7 +157,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventA, "main"), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 2 && r.Get("notification_count").Num == 3 && !t.Exists() }), @@ -163,7 +168,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventA, "main"), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && @@ -179,8 +184,8 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstThreadEventID, firstEventID), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventA, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventB, eventA), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 2 && r.Get("notification_count").Num == 2 && !t.Exists() }), @@ -191,8 +196,8 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstEventID, "main"), - syncHasThreadedReadReceipt(roomID, bob.UserID, firstThreadEventID, firstEventID), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventA, "main"), + syncHasThreadedReadReceipt(roomID, bob.UserID, eventB, eventA), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && @@ -208,7 +213,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasUnthreadedReadReceipt(roomID, bob.UserID, secondEventID), + syncHasUnthreadedReadReceipt(roomID, bob.UserID, eventD), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 0 && r.Get("notification_count").Num == 0 && !t.Exists() }), @@ -219,7 +224,7 @@ func TestThreadedReceipts(t *testing.T) { client.SyncTimelineHas(roomID, func(r gjson.Result) bool { return r.Get("event_id").Str == eventD }), - syncHasUnthreadedReadReceipt(roomID, bob.UserID, secondEventID), + syncHasUnthreadedReadReceipt(roomID, bob.UserID, eventD), syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { return r.Get("highlight_count").Num == 0 && r.Get("notification_count").Num == 0 && !t.Exists() }), From e400d063a039630e9305b4aa657822d70baec834 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 27 Oct 2022 10:31:49 -0400 Subject: [PATCH 3/3] Run gofmt. --- tests/csapi/thread_notifications_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index 2c92432d..3df8dcdd 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -144,7 +144,7 @@ func TestThreadedReceipts(t *testing.T) { syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 2 && - threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 2 + threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 2 }), ) @@ -172,7 +172,7 @@ func TestThreadedReceipts(t *testing.T) { syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && - threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 2 + threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 2 }), ) @@ -201,7 +201,7 @@ func TestThreadedReceipts(t *testing.T) { syncHasUnreadNotifs(roomID, func(r gjson.Result, t gjson.Result) bool { threadNotifications := t.Get(client.GjsonEscape(eventA)) return r.Get("highlight_count").Num == 1 && r.Get("notification_count").Num == 1 && - threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 1 + threadNotifications.Get("highlight_count").Num == 1 && threadNotifications.Get("notification_count").Num == 1 }), )