implement Dbus isRegistered() methods (#729)

* implement Dbus isRegistered() methods

isRegistered(number<s>) returns a boolean

isRegistered(numbers<as>) returns an array of Booleans

* Dbus isRegistered() methods

restore isRegistered() and respond to other requests by AsamK
This commit is contained in:
John Freed 2021-09-26 20:09:57 +02:00 committed by GitHub
parent df8dd54791
commit 1c4a32fef4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 4 deletions

View file

@ -322,8 +322,15 @@ Exception: Failure
version() -> version<s>:: version() -> version<s>::
* version : Version string of signal-cli * version : Version string of signal-cli
isRegistred -> result<b>:: isRegistered() -> result<b>::
* result : Currently always returns 1=true isRegistered(number<s>) -> result<b>::
isRegistered(numbers<as>) -> results<ab>::
* number : Phone number
* numbers : String array of phone numbers
* result : true=number is registered, false=number is not registered
* results : Boolean array of results
Exception: InvalidNumber for an incorrectly formatted phone number. For unknown numbers, false is returned, but no exception is raised. If no number is given, returns whether you are registered (presumably true).
addDevice(deviceUri<s>) -> <>:: addDevice(deviceUri<s>) -> <>::
* deviceUri : URI in the form of tsdevice:/?uuid=... Normally received from Signal desktop or smartphone app * deviceUri : URI in the form of tsdevice:/?uuid=... Normally received from Signal desktop or smartphone app

View file

@ -87,7 +87,11 @@ public interface Signal extends DBusInterface {
byte[] groupId, String name, List<String> members, String avatar byte[] groupId, String name, List<String> members, String avatar
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId; ) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId;
boolean isRegistered(); boolean isRegistered() throws Error.Failure, Error.InvalidNumber;
boolean isRegistered(String number) throws Error.Failure, Error.InvalidNumber;
List<Boolean> isRegistered(List<String> numbers) throws Error.Failure, Error.InvalidNumber;
void addDevice(String uri) throws Error.InvalidUri; void addDevice(String uri) throws Error.InvalidUri;

View file

@ -41,6 +41,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -467,7 +468,33 @@ public class DbusSignalImpl implements Signal {
@Override @Override
public boolean isRegistered() { public boolean isRegistered() {
return true; var result = isRegistered(List.of(m.getUsername()));
return result.get(0);
}
@Override
public boolean isRegistered(String number) {
var result = isRegistered(List.of(number));
return result.get(0);
}
@Override
public List<Boolean> isRegistered(List<String> numbers) {
var results = new ArrayList<Boolean> ();
Map<String, Pair<String, UUID>> registered;
if (numbers.isEmpty()) {
return results;
}
try {
registered = m.areUsersRegistered(new HashSet<String>(numbers));
} catch (IOException e) {
throw new Error.Failure(e.getMessage());
}
for (String number : numbers) {
UUID uuid = registered.get(number).second();
results.add(uuid != null);
}
return results;
} }
@Override @Override