don't double-invite in sync_room_to_group.pl

pull/2694/head
Matthew Hodgson 2017-11-19 00:48:38 +00:00
parent 59a7275258
commit 2145ee1976
1 changed files with 6 additions and 3 deletions

View File

@ -21,7 +21,10 @@ if ($room_id =~ /^#/) {
} }
my $room_users = [ keys %{decode_json($ua->get("${hs}/_matrix/client/r0/rooms/${room_id}/joined_members?access_token=${access_token}")->decoded_content)->{joined}} ]; my $room_users = [ keys %{decode_json($ua->get("${hs}/_matrix/client/r0/rooms/${room_id}/joined_members?access_token=${access_token}")->decoded_content)->{joined}} ];
my $group_users = [ map { $_->{user_id} } @{decode_json($ua->get("${hs}/_matrix/client/unstable/groups/${group_id}/users?access_token=${access_token}" )->decoded_content)->{chunk}} ]; my $group_users = [
(map { $_->{user_id} } @{decode_json($ua->get("${hs}/_matrix/client/unstable/groups/${group_id}/users?access_token=${access_token}" )->decoded_content)->{chunk}}),
(map { $_->{user_id} } @{decode_json($ua->get("${hs}/_matrix/client/unstable/groups/${group_id}/invited_users?access_token=${access_token}" )->decoded_content)->{chunk}}),
];
my $diff = {}; my $diff = {};
foreach my $user (@$room_users) { $diff->{$user}++ } foreach my $user (@$room_users) { $diff->{$user}++ }
@ -30,10 +33,10 @@ foreach my $user (@$group_users) { $diff->{$user}-- }
foreach my $user (keys %$diff) { foreach my $user (keys %$diff) {
if ($diff->{$user} == 1) { if ($diff->{$user} == 1) {
warn "inviting $user"; warn "inviting $user";
$ua->put("${hs}/_matrix/client/unstable/groups/${group_id}/admin/users/invite/${user}?access_token=${access_token}", Content=>'{}'); print STDERR $ua->put("${hs}/_matrix/client/unstable/groups/${group_id}/admin/users/invite/${user}?access_token=${access_token}", Content=>'{}')->status_line."\n";
} }
elsif ($diff->{$user} == -1) { elsif ($diff->{$user} == -1) {
warn "removing $user"; warn "removing $user";
$ua->put("${hs}/_matrix/client/unstable/groups/${group_id}/admin/users/remove/${user}?access_token=${access_token}", Content=>'{}'); print STDERR $ua->put("${hs}/_matrix/client/unstable/groups/${group_id}/admin/users/remove/${user}?access_token=${access_token}", Content=>'{}')->status_line."\n";
} }
} }