From 97d1228b02bac79bec6f0e32d2e297a11cb0842a Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sat, 17 Jul 2021 11:12:14 +0200 Subject: [PATCH 1/2] Fix usage of /messages API The test depended on a bug in Synapse where prev_batch is set to an incorrect value in case /sync is called with since parameter. Signed-off-by: Kurt Roeckx --- tests/10apidoc/34room-messages.pl | 38 ++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/10apidoc/34room-messages.pl b/tests/10apidoc/34room-messages.pl index 13122c43e..0cfb58199 100644 --- a/tests/10apidoc/34room-messages.pl +++ b/tests/10apidoc/34room-messages.pl @@ -128,6 +128,12 @@ sub matrix_send_room_text_message ) } +# This first sends a message, then does a /sync without since parameter. +# That /sync will most likely return the whole timeline for the room +# so we can't use it's prev_batch in the /messages API. So we send +# a 2nd message, and then do a /sync with since set to the previous +# /sync's next_batch. We can then fetch messages with the 2nd /sync's +# prev_batch that are before first /sync. test "GET /rooms/:room_id/messages returns a message", requires => [ local_user_and_room_fixtures(), qw( can_send_message )], @@ -138,12 +144,18 @@ sub matrix_send_room_text_message my ( $user, $room_id ) = @_; matrix_send_room_text_message( $user, $room_id, - body => "Here is the message content", + body => "Here is the first message", )->then( sub { - matrix_sync( $user ) + matrix_sync( $user ); + })->then( sub { + matrix_send_room_text_message( $user, $room_id, + body => "Here is a second message", + ) + })->then( sub { + matrix_sync_again( $user ); })->then( sub { my ( $sync_body ) = @_; - my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; + my $prev_batch = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; do_request_json_for( $user, method => "GET", @@ -152,7 +164,7 @@ sub matrix_send_room_text_message # With no params this does "forwards from END"; i.e. nothing useful params => { dir => "b", - from => $token, + from => $prev_batch, }, ) })->then( sub { @@ -164,6 +176,10 @@ sub matrix_send_room_text_message scalar @{ $body->{chunk} } > 0 or die "Expected some messages but got none at all\n"; + assert_eq( $body->{chunk}[0]{type}, 'm.room.message'); + assert_eq( $body->{chunk}[0]{content}{msgtype}, 'm.text'); + assert_eq( $body->{chunk}[0]{content}{body}, 'Here is the first message'); + Future->done(1); }); }; @@ -176,12 +192,18 @@ sub matrix_send_room_text_message my ( $user, $room_id ) = @_; matrix_send_room_text_message( $user, $room_id, - body => "Here is the message content", + body => "Here is the first message", )->then( sub { - matrix_sync( $user ) + matrix_sync( $user ); + })->then( sub { + matrix_send_room_text_message( $user, $room_id, + body => "Here is a second message", + ) + })->then( sub { + matrix_sync_again( $user ); })->then( sub { my ( $sync_body ) = @_; - my $token = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; + my $prev_batch = $sync_body->{rooms}->{join}->{$room_id}->{timeline}->{prev_batch}; do_request_json_for( $user, method => "GET", @@ -190,7 +212,7 @@ sub matrix_send_room_text_message params => { dir => "b", filter => '{ "lazy_load_members" : true }', - from => $token, + from => $prev_batch, }, ) })->then( sub { From f0acdabd64c0975848e9460c64dc7f00df22ac10 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:53:34 +0100 Subject: [PATCH 2/2] fix indentation --- tests/10apidoc/34room-messages.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/10apidoc/34room-messages.pl b/tests/10apidoc/34room-messages.pl index 0cfb58199..078c15efe 100644 --- a/tests/10apidoc/34room-messages.pl +++ b/tests/10apidoc/34room-messages.pl @@ -148,7 +148,7 @@ sub matrix_send_room_text_message )->then( sub { matrix_sync( $user ); })->then( sub { - matrix_send_room_text_message( $user, $room_id, + matrix_send_room_text_message( $user, $room_id, body => "Here is a second message", ) })->then( sub { @@ -196,7 +196,7 @@ sub matrix_send_room_text_message )->then( sub { matrix_sync( $user ); })->then( sub { - matrix_send_room_text_message( $user, $room_id, + matrix_send_room_text_message( $user, $room_id, body => "Here is a second message", ) })->then( sub {