Include unrestricted unidentified access state in getUserStatus response

This commit is contained in:
AsamK 2022-05-17 20:39:06 +02:00
parent 376fcba9ec
commit bb9d44811c
6 changed files with 36 additions and 24 deletions

View file

@ -21,6 +21,7 @@ import org.asamk.signal.manager.api.StickerPackUrl;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
import org.asamk.signal.manager.groups.GroupNotFoundException;
@ -41,7 +42,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
public interface Manager extends Closeable {
@ -58,7 +58,7 @@ public interface Manager extends Closeable {
* @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
* @throws IOException if it's unable to get the contacts to check if they're registered
*/
Map<String, Pair<String, UUID>> areUsersRegistered(Set<String> numbers) throws IOException;
Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException;
void updateAccountAttributes(String deviceName) throws IOException;

View file

@ -38,6 +38,7 @@ import org.asamk.signal.manager.api.StickerPackUrl;
import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.config.ServiceEnvironmentConfig;
import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
@ -84,7 +85,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
@ -190,7 +190,7 @@ class ManagerImpl implements Manager {
}
@Override
public Map<String, Pair<String, UUID>> areUsersRegistered(Set<String> numbers) throws IOException {
public Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException {
final var canonicalizedNumbers = numbers.stream().collect(Collectors.toMap(n -> n, n -> {
try {
final var canonicalizedNumber = PhoneNumberFormatter.formatNumber(n, account.getNumber());
@ -213,7 +213,13 @@ class ManagerImpl implements Manager {
return numbers.stream().collect(Collectors.toMap(n -> n, n -> {
final var number = canonicalizedNumbers.get(n);
final var aci = registeredUsers.get(number);
return new Pair<>(number.isEmpty() ? null : number, aci == null ? null : aci.uuid());
final var profile = aci == null
? null
: context.getProfileHelper().getRecipientProfile(account.getRecipientStore().resolveRecipient(aci));
return new UserStatus(number.isEmpty() ? null : number,
aci == null ? null : aci.uuid(),
profile != null
&& profile.getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNRESTRICTED);
}));
}

View file

@ -0,0 +1,5 @@
package org.asamk.signal.manager.api;
import java.util.UUID;
public record UserStatus(String number, UUID uuid, boolean unrestrictedUnidentifiedAccess) {}