kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add some additional endpoints for PNP.
rodzic
4309127b8c
commit
2df303cde7
|
@ -33,6 +33,7 @@ import org.whispersystems.signalservice.api.payments.CurrencyConversions;
|
||||||
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite;
|
||||||
import org.whispersystems.signalservice.api.push.ACI;
|
import org.whispersystems.signalservice.api.push.ACI;
|
||||||
|
import org.whispersystems.signalservice.api.push.AccountIdentifier;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
|
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NoContentException;
|
import org.whispersystems.signalservice.api.push.exceptions.NoContentException;
|
||||||
|
@ -408,6 +409,13 @@ public class SignalServiceAccountManager {
|
||||||
return this.pushServiceSocket.getCurrentSignedPreKey();
|
return this.pushServiceSocket.getCurrentSignedPreKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the identifier corresponds to a registered user, otherwise false.
|
||||||
|
*/
|
||||||
|
public boolean isIdentifierRegistered(AccountIdentifier identifier) throws IOException {
|
||||||
|
return pushServiceSocket.isIdentifierRegistered(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a contact is currently registered with the server.
|
* Checks whether a contact is currently registered with the server.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,12 +16,10 @@ import io.reactivex.rxjava3.annotations.NonNull;
|
||||||
* An ACI is an "Account Identity". They're just UUIDs, but given multiple different things could be UUIDs, this wrapper exists to give us type safety around
|
* An ACI is an "Account Identity". They're just UUIDs, but given multiple different things could be UUIDs, this wrapper exists to give us type safety around
|
||||||
* this *specific type* of UUID.
|
* this *specific type* of UUID.
|
||||||
*/
|
*/
|
||||||
public final class ACI {
|
public final class ACI extends AccountIdentifier {
|
||||||
|
|
||||||
public static final ACI UNKNOWN = ACI.from(UuidUtil.UNKNOWN_UUID);
|
public static final ACI UNKNOWN = ACI.from(UuidUtil.UNKNOWN_UUID);
|
||||||
|
|
||||||
private final UUID uuid;
|
|
||||||
|
|
||||||
public static ACI from(UUID uuid) {
|
public static ACI from(UUID uuid) {
|
||||||
return new ACI(uuid);
|
return new ACI(uuid);
|
||||||
}
|
}
|
||||||
|
@ -72,11 +70,7 @@ public final class ACI {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ACI(UUID uuid) {
|
private ACI(UUID uuid) {
|
||||||
this.uuid = uuid;
|
super(uuid);
|
||||||
}
|
|
||||||
|
|
||||||
public UUID uuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteString toByteString() {
|
public ByteString toByteString() {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.whispersystems.signalservice.api.push;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper around a UUID that represents an identifier for an account. Today, that is either an {@link ACI} or a {@link PNI}.
|
||||||
|
*/
|
||||||
|
public abstract class AccountIdentifier {
|
||||||
|
|
||||||
|
protected final UUID uuid;
|
||||||
|
|
||||||
|
protected AccountIdentifier(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID uuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return uuid.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.whispersystems.signalservice.api.push;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A PNI is a "Phone Number Identity". They're just UUIDs, but given multiple different things could be UUIDs, this wrapper exists to give us type safety around
|
||||||
|
* this *specific type* of UUID.
|
||||||
|
*/
|
||||||
|
public final class PNI extends AccountIdentifier {
|
||||||
|
|
||||||
|
public static PNI from(UUID uuid) {
|
||||||
|
return new PNI(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PNI(UUID uuid) {
|
||||||
|
super(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return uuid.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (other instanceof PNI) {
|
||||||
|
return uuid.equals(((PNI) other).uuid);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,7 @@ import org.whispersystems.signalservice.api.profiles.ProfileAndCredential;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
|
||||||
import org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite;
|
import org.whispersystems.signalservice.api.profiles.SignalServiceProfileWrite;
|
||||||
import org.whispersystems.signalservice.api.push.ACI;
|
import org.whispersystems.signalservice.api.push.ACI;
|
||||||
|
import org.whispersystems.signalservice.api.push.AccountIdentifier;
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
|
import org.whispersystems.signalservice.api.push.SignedPreKeyEntity;
|
||||||
|
@ -86,7 +87,6 @@ import org.whispersystems.signalservice.api.subscriptions.SubscriptionLevels;
|
||||||
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
import org.whispersystems.signalservice.api.util.CredentialsProvider;
|
||||||
import org.whispersystems.signalservice.api.util.Tls12SocketFactory;
|
import org.whispersystems.signalservice.api.util.Tls12SocketFactory;
|
||||||
import org.whispersystems.signalservice.api.util.TlsProxySocketFactory;
|
import org.whispersystems.signalservice.api.util.TlsProxySocketFactory;
|
||||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
|
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
|
||||||
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
|
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
|
||||||
|
@ -192,6 +192,7 @@ public class PushServiceSocket {
|
||||||
private static final String DELETE_USERNAME_PATH = "/v1/accounts/username";
|
private static final String DELETE_USERNAME_PATH = "/v1/accounts/username";
|
||||||
private static final String DELETE_ACCOUNT_PATH = "/v1/accounts/me";
|
private static final String DELETE_ACCOUNT_PATH = "/v1/accounts/me";
|
||||||
private static final String CHANGE_NUMBER_PATH = "/v1/accounts/number";
|
private static final String CHANGE_NUMBER_PATH = "/v1/accounts/number";
|
||||||
|
private static final String IDENTIFIER_REGISTERED_PATH = "/v1/accounts/account/%s";
|
||||||
|
|
||||||
private static final String PREKEY_METADATA_PATH = "/v2/keys/";
|
private static final String PREKEY_METADATA_PATH = "/v2/keys/";
|
||||||
private static final String PREKEY_PATH = "/v2/keys/%s";
|
private static final String PREKEY_PATH = "/v2/keys/%s";
|
||||||
|
@ -332,7 +333,7 @@ public class PushServiceSocket {
|
||||||
public ACI getOwnAci() throws IOException {
|
public ACI getOwnAci() throws IOException {
|
||||||
String body = makeServiceRequest(WHO_AM_I, "GET", null);
|
String body = makeServiceRequest(WHO_AM_I, "GET", null);
|
||||||
WhoAmIResponse response = JsonUtil.fromJson(body, WhoAmIResponse.class);
|
WhoAmIResponse response = JsonUtil.fromJson(body, WhoAmIResponse.class);
|
||||||
Optional<ACI> aci = ACI.parse(response.getUuid());
|
Optional<ACI> aci = ACI.parse(response.getAci());
|
||||||
|
|
||||||
if (aci.isPresent()) {
|
if (aci.isPresent()) {
|
||||||
return aci.get();
|
return aci.get();
|
||||||
|
@ -345,6 +346,15 @@ public class PushServiceSocket {
|
||||||
return JsonUtil.fromJson(makeServiceRequest(WHO_AM_I, "GET", null), WhoAmIResponse.class);
|
return JsonUtil.fromJson(makeServiceRequest(WHO_AM_I, "GET", null), WhoAmIResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIdentifierRegistered(AccountIdentifier identifier) throws IOException {
|
||||||
|
try {
|
||||||
|
makeServiceRequestWithoutAuthentication(String.format(IDENTIFIER_REGISTERED_PATH, identifier.toString()), "HEAD", null);
|
||||||
|
return true;
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CdshAuthResponse getCdshAuth() throws IOException {
|
public CdshAuthResponse getCdshAuth() throws IOException {
|
||||||
String body = makeServiceRequest(CDSH_AUTH, "GET", null);
|
String body = makeServiceRequest(CDSH_AUTH, "GET", null);
|
||||||
return JsonUtil.fromJsonResponse(body, CdshAuthResponse.class);
|
return JsonUtil.fromJsonResponse(body, CdshAuthResponse.class);
|
||||||
|
|
|
@ -6,13 +6,20 @@ public class WhoAmIResponse {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String uuid;
|
private String uuid;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String pni;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private String number;
|
private String number;
|
||||||
|
|
||||||
public String getUuid() {
|
public String getAci() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPni() {
|
||||||
|
return pni;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNumber() {
|
public String getNumber() {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue