Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the userdir synced not rely on being able to search for yourself #567

Merged
merged 12 commits into from
Mar 7, 2019
64 changes: 54 additions & 10 deletions tests/52user-directory/01public.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@
my ( $user ) = @_;

my $room_id;
my $searching_user;

my $displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )
->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing commas are nice

);
})->then( sub {
( $searching_user ) = @_;

matrix_create_room( $user,
preset => "public_chat",
);
})->then( sub {
my ( $room_id ) = @_;
matrix_join_room( $searching_user, $room_id );
})->then( sub {
( $room_id ) = @_;
hawkowl marked this conversation as resolved.
Show resolved Hide resolved

repeat_until_true {
do_request_json_for( $user,
do_request_json_for( $searching_user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $displayname,
}
Expand All @@ -44,17 +55,22 @@
my ( $user ) = @_;

my $room_id;
hawkowl marked this conversation as resolved.
Show resolved Hide resolved
my $searching_user;

my $displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
);
})->then( sub {
( $searching_user ) = @_;

matrix_set_displayname( $user, $displayname )
->then( sub {
matrix_create_room( $user,
preset => "private_chat",
);
})->then( sub {
( $room_id ) = @_;

matrix_get_user_dir_synced( $user, $displayname );
hawkowl marked this conversation as resolved.
Show resolved Hide resolved
})->then( sub {
my ( $body ) = @_;
Expand Down Expand Up @@ -384,12 +400,25 @@
my ( $user ) = @_;

my $room_id;
my $searching_user;

my $displayname = generate_random_displayname();
my $second_displayname = generate_random_displayname();
my $searching_displayname = generate_random_displayname();

matrix_set_displayname( $user, $displayname )
->then( sub {

hawkowl marked this conversation as resolved.
Show resolved Hide resolved
matrix_create_user_on_server( $user->http,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure why we are creating a user that is never used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they have to join the room so that the dir is populated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they don't seem to join a room?

displayname => $second_displayname
);
})->then( sub {
matrix_create_user_on_server( $user->http,
displayname => $searching_displayname
);
}) -> then( sub {
( $searching_user ) = @_;

log_if_fail "First displayname", $displayname;

matrix_create_room( $user,
Expand All @@ -398,6 +427,8 @@
})->then( sub {
( $room_id ) = @_;

matrix_join_room( $searching_user, $room_id );
})->then( sub {
matrix_get_user_dir_synced( $user, $displayname );
})->then( sub {
my ( $body ) = @_;
Expand Down Expand Up @@ -435,30 +466,43 @@ sub generate_random_displayname
}


# Get the user direectory after a change has been made. This creates a new user
# Get the user directory after a change has been made. This creates a new user
hawkowl marked this conversation as resolved.
Show resolved Hide resolved
# and then polls the user directory until we see it. This is to get around the
hawkowl marked this conversation as resolved.
Show resolved Hide resolved
# fact that the user directory gets updated asynchronously.
sub matrix_get_user_dir_synced
{
my ( $user, $search_term ) = @_;

my $new_user;
my $searching_user;
my $room_id;

my $random_id = join "", map { chr 65 + rand 26 } 1 .. 20;
my $searching_random_id = join "", map { chr 65 + rand 26 } 1 .. 20;

matrix_create_user_on_server( $user->http,
displayname => $random_id
)->then( sub {
( $new_user ) = @_;

matrix_create_user_on_server( $user->http,
displayname => $searching_random_id
);
}) -> then( sub {
( $searching_user ) = @_;

matrix_create_room( $new_user,
preset => "public_chat",
);
})->then( sub {
( $room_id ) = @_;

matrix_join_room( $searching_user, $room_id );
})->then( sub {
repeat_until_true {
do_request_json_for( $new_user,
do_request_json_for( $searching_user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $random_id,
}
Expand All @@ -474,7 +518,7 @@ sub matrix_get_user_dir_synced
})->then( sub {
do_request_json_for( $user,
method => "POST",
uri => "/unstable/user_directory/search",
uri => "/r0/user_directory/search",
content => {
search_term => $search_term,
}
Expand Down