@@ -128,6 +128,12 @@ sub matrix_send_room_text_message
128128 )
129129}
130130
131+ # This first sends a message, then does a /sync without since parameter.
132+ # That /sync will most likely return the whole timeline for the room
133+ # so we can't use it's prev_batch in the /messages API. So we send
134+ # a 2nd message, and then do a /sync with since set to the previous
135+ # /sync's next_batch. We can then fetch messages with the 2nd /sync's
136+ # prev_batch that are before first /sync.
131137test " GET /rooms/:room_id/messages returns a message" ,
132138 requires => [ local_user_and_room_fixtures(),
133139 qw( can_send_message ) ],
@@ -138,12 +144,18 @@ sub matrix_send_room_text_message
138144 my ( $user , $room_id ) = @_ ;
139145
140146 matrix_send_room_text_message( $user , $room_id ,
141- body => " Here is the message content " ,
147+ body => " Here is the first message " ,
142148 )-> then( sub {
143- matrix_sync( $user )
149+ matrix_sync( $user );
150+ })-> then( sub {
151+ matrix_send_room_text_message( $user , $room_id ,
152+ body => " Here is a second message" ,
153+ )
154+ })-> then( sub {
155+ matrix_sync_again( $user );
144156 })-> then( sub {
145157 my ( $sync_body ) = @_ ;
146- my $token = $sync_body -> {rooms }-> {join }-> {$room_id }-> {timeline }-> {prev_batch };
158+ my $prev_batch = $sync_body -> {rooms }-> {join }-> {$room_id }-> {timeline }-> {prev_batch };
147159
148160 do_request_json_for( $user ,
149161 method => " GET" ,
@@ -152,7 +164,7 @@ sub matrix_send_room_text_message
152164 # With no params this does "forwards from END"; i.e. nothing useful
153165 params => {
154166 dir => " b" ,
155- from => $token ,
167+ from => $prev_batch ,
156168 },
157169 )
158170 })-> then( sub {
@@ -164,6 +176,10 @@ sub matrix_send_room_text_message
164176 scalar @{ $body -> {chunk } } > 0 or
165177 die " Expected some messages but got none at all\n " ;
166178
179+ assert_eq( $body -> {chunk }[0]{type }, ' m.room.message' );
180+ assert_eq( $body -> {chunk }[0]{content }{msgtype }, ' m.text' );
181+ assert_eq( $body -> {chunk }[0]{content }{body }, ' Here is the first message' );
182+
167183 Future-> done(1);
168184 });
169185 };
@@ -176,12 +192,18 @@ sub matrix_send_room_text_message
176192 my ( $user , $room_id ) = @_ ;
177193
178194 matrix_send_room_text_message( $user , $room_id ,
179- body => " Here is the message content " ,
195+ body => " Here is the first message " ,
180196 )-> then( sub {
181- matrix_sync( $user )
197+ matrix_sync( $user );
198+ })-> then( sub {
199+ matrix_send_room_text_message( $user , $room_id ,
200+ body => " Here is a second message" ,
201+ )
202+ })-> then( sub {
203+ matrix_sync_again( $user );
182204 })-> then( sub {
183205 my ( $sync_body ) = @_ ;
184- my $token = $sync_body -> {rooms }-> {join }-> {$room_id }-> {timeline }-> {prev_batch };
206+ my $prev_batch = $sync_body -> {rooms }-> {join }-> {$room_id }-> {timeline }-> {prev_batch };
185207
186208 do_request_json_for( $user ,
187209 method => " GET" ,
@@ -190,7 +212,7 @@ sub matrix_send_room_text_message
190212 params => {
191213 dir => " b" ,
192214 filter => ' { "lazy_load_members" : true }' ,
193- from => $token ,
215+ from => $prev_batch ,
194216 },
195217 )
196218 })-> then( sub {
0 commit comments