@@ -97,41 +97,56 @@ async fn test_update_read_marker() {
97
97
let f = & timeline. factory ;
98
98
timeline. handle_live_event ( f. text_msg ( "A" ) . sender ( & own_user) ) . await ;
99
99
100
+ // Timeline: [A].
101
+ // No read marker.
100
102
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
101
103
let event_id1 = item. as_event ( ) . unwrap ( ) . event_id ( ) . unwrap ( ) . to_owned ( ) ;
102
104
105
+ // Timeline: [day-divider, A].
103
106
let day_divider = assert_next_matches ! ( stream, VectorDiff :: PushFront { value } => value) ;
104
107
assert ! ( day_divider. is_day_divider( ) ) ;
105
108
106
- timeline. controller . handle_fully_read_marker ( event_id1. to_owned ( ) ) . await ;
109
+ timeline. controller . handle_fully_read_marker ( event_id1. clone ( ) ) . await ;
107
110
108
111
// Nothing should happen, the marker cannot be added at the end.
112
+ // Timeline: [A].
113
+ // ^-- fully read
114
+ assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
109
115
116
+ // Timeline: [day-divider, A, B].
110
117
timeline. handle_live_event ( f. text_msg ( "B" ) . sender ( & BOB ) ) . await ;
111
118
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
112
119
let event_id2 = item. as_event ( ) . unwrap ( ) . event_id ( ) . unwrap ( ) . to_owned ( ) ;
113
120
114
121
// Now the read marker appears after the first event.
122
+ // Timeline: [day-divider, A, read-marker, B].
123
+ // fully read --^
115
124
let item = assert_next_matches ! ( stream, VectorDiff :: Insert { index: 2 , value } => value) ;
116
125
assert_matches ! ( item. as_virtual( ) , Some ( VirtualTimelineItem :: ReadMarker ) ) ;
117
126
118
127
timeline. controller . handle_fully_read_marker ( event_id2. clone ( ) ) . await ;
119
128
120
129
// The read marker is removed but not reinserted, because it cannot be added at
121
130
// the end.
131
+ // Timeline: [day-divider, A, B].
132
+ // ^-- fully read
122
133
assert_next_matches ! ( stream, VectorDiff :: Remove { index: 2 } ) ;
123
134
135
+ // Timeline: [day-divider, A, B, C].
136
+ // ^-- fully read
124
137
timeline. handle_live_event ( f. text_msg ( "C" ) . sender ( & BOB ) ) . await ;
125
138
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
126
139
let event_id3 = item. as_event ( ) . unwrap ( ) . event_id ( ) . unwrap ( ) . to_owned ( ) ;
127
140
128
141
// Now the read marker is reinserted after the second event.
142
+ // Timeline: [day-divider, A, B, read-marker, C].
143
+ // ^-- fully read
129
144
let marker = assert_next_matches ! ( stream, VectorDiff :: Insert { index: 3 , value } => value) ;
130
145
assert ! ( marker. is_read_marker( ) ) ;
131
146
132
147
// Nothing should happen if the fully read event is set back to an older event
133
148
// sent by another user.
134
- timeline. controller . handle_fully_read_marker ( event_id1. to_owned ( ) ) . await ;
149
+ timeline. controller . handle_fully_read_marker ( event_id1) . await ;
135
150
assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
136
151
137
152
// Nothing should happen if the fully read event isn't found.
@@ -143,18 +158,27 @@ async fn test_update_read_marker() {
143
158
timeline. controller . handle_fully_read_marker ( event_id2) . await ;
144
159
assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
145
160
161
+ // Timeline: [day-divider, A, B, read-marker, C, D].
162
+ // ^-- fully read
146
163
timeline. handle_live_event ( f. text_msg ( "D" ) . sender ( & BOB ) ) . await ;
147
164
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
148
165
let event_id4 = item. as_event ( ) . unwrap ( ) . event_id ( ) . unwrap ( ) . to_owned ( ) ;
149
166
150
167
timeline. controller . handle_fully_read_marker ( event_id3) . await ;
151
168
152
169
// The read marker is moved after the third event (sent by another user).
170
+ // Timeline: [day-divider, A, B, C, D].
171
+ // fully read --^
153
172
assert_next_matches ! ( stream, VectorDiff :: Remove { index: 3 } ) ;
173
+
174
+ // Timeline: [day-divider, A, B, C, read-marker, D].
175
+ // fully read --^
154
176
let marker = assert_next_matches ! ( stream, VectorDiff :: Insert { index: 4 , value } => value) ;
155
177
assert ! ( marker. is_read_marker( ) ) ;
156
178
157
179
// If the current user sends an event afterwards, the read marker doesn't move.
180
+ // Timeline: [day-divider, A, B, C, read-marker, D, E].
181
+ // fully read --^
158
182
timeline. handle_live_event ( f. text_msg ( "E" ) . sender ( & own_user) ) . await ;
159
183
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
160
184
item. as_event ( ) . unwrap ( ) ;
@@ -163,28 +187,43 @@ async fn test_update_read_marker() {
163
187
164
188
// If the marker moved forward to another user's event, and there's no other
165
189
// event sent from another user, then it will be removed.
190
+ // Timeline: [day-divider, A, B, C, D, E].
191
+ // fully read --^
166
192
timeline. controller . handle_fully_read_marker ( event_id4) . await ;
167
193
assert_next_matches ! ( stream, VectorDiff :: Remove { index: 4 } ) ;
168
194
169
195
assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
170
196
171
197
// When a last event is inserted by ourselves, still no read marker.
198
+ // Timeline: [day-divider, A, B, C, D, E, F].
199
+ // fully read --^
172
200
timeline. handle_live_event ( f. text_msg ( "F" ) . sender ( & own_user) ) . await ;
173
201
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
174
202
item. as_event ( ) . unwrap ( ) ;
175
203
204
+ // Timeline: [day-divider, A, B, C, D, E, F, G].
205
+ // fully read --^
176
206
timeline. handle_live_event ( f. text_msg ( "G" ) . sender ( & own_user) ) . await ;
177
207
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
178
208
item. as_event ( ) . unwrap ( ) ;
179
209
180
210
assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
181
211
182
- // But when it's another user who sent the event, then we get a read marker for
183
- // their message.
212
+ // But when it's another user who sent the event, then we get a read marker just
213
+ // before their message. It is the first message that's both after the
214
+ // fully-read event and not sent by us.
215
+ //
216
+ // Timeline: [day-divider, A, B, C, D, E, F, G, H].
217
+ // fully read --^
184
218
timeline. handle_live_event ( f. text_msg ( "H" ) . sender ( & BOB ) ) . await ;
185
219
let item = assert_next_matches ! ( stream, VectorDiff :: PushBack { value } => value) ;
186
220
item. as_event ( ) . unwrap ( ) ;
187
221
222
+ // [our own] v-- sent by Bob
223
+ // Timeline: [day-divider, A, B, C, D, E, F, G, read-marker, H].
224
+ // fully read --^
188
225
let marker = assert_next_matches ! ( stream, VectorDiff :: Insert { index: 8 , value } => value) ;
189
226
assert ! ( marker. is_read_marker( ) ) ;
227
+
228
+ assert ! ( stream. next( ) . now_or_never( ) . is_none( ) ) ;
190
229
}
0 commit comments