mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-21 23:17:28 +00:00
Bundle e164 and relay into PushDestination
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.whispersystems.textsecure.push;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.whispersystems.textsecure.directory.Directory;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
public class PushDestination {
|
||||
|
||||
private final String e164number;
|
||||
private final String relay;
|
||||
|
||||
private PushDestination(String e164number, String relay) {
|
||||
this.e164number = e164number;
|
||||
this.relay = relay;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return e164number;
|
||||
}
|
||||
|
||||
public String getRelay() {
|
||||
return relay;
|
||||
}
|
||||
|
||||
public static PushDestination getInstance(Context context,
|
||||
PushServiceSocket.PushCredentials credentials,
|
||||
String destinationNumber)
|
||||
{
|
||||
String e164destination = PhoneNumberFormatter.formatNumber(destinationNumber, credentials.getLocalNumber(context));
|
||||
String relay = Directory.getInstance(context).getRelay(e164destination);
|
||||
|
||||
return new PushDestination(e164destination, relay);
|
||||
}
|
||||
}
|
@@ -84,31 +84,32 @@ public class PushServiceSocket {
|
||||
makeRequest(REGISTER_GCM_PATH, "DELETE", null);
|
||||
}
|
||||
|
||||
public void sendMessage(String relay, String recipient, byte[] body, int type)
|
||||
public void sendMessage(PushDestination recipient, byte[] body, int type)
|
||||
throws IOException
|
||||
{
|
||||
OutgoingPushMessage message = new OutgoingPushMessage(relay, recipient, body, type);
|
||||
OutgoingPushMessage message = new OutgoingPushMessage(recipient.getRelay(),
|
||||
recipient.getNumber(),
|
||||
body, type);
|
||||
|
||||
sendMessage(new OutgoingPushMessageList(message));
|
||||
}
|
||||
|
||||
public void sendMessage(List<String> relays, List<String> recipients,
|
||||
public void sendMessage(List<PushDestination> recipients,
|
||||
List<byte[]> bodies, List<Integer> types)
|
||||
throws IOException
|
||||
{
|
||||
List<OutgoingPushMessage> messages = new LinkedList<OutgoingPushMessage>();
|
||||
|
||||
Iterator<String> relaysIterator = relays.iterator();
|
||||
Iterator<String> recipientsIterator = recipients.iterator();
|
||||
Iterator<byte[]> bodiesIterator = bodies.iterator();
|
||||
Iterator<Integer> typesIterator = types.iterator();
|
||||
Iterator<PushDestination> recipientsIterator = recipients.iterator();
|
||||
Iterator<byte[]> bodiesIterator = bodies.iterator();
|
||||
Iterator<Integer> typesIterator = types.iterator();
|
||||
|
||||
while (recipientsIterator.hasNext()) {
|
||||
String relay = relaysIterator.next();
|
||||
String recipient = recipientsIterator.next();
|
||||
byte[] body = bodiesIterator.next();
|
||||
int type = typesIterator.next();
|
||||
PushDestination recipient = recipientsIterator.next();
|
||||
byte[] body = bodiesIterator.next();
|
||||
int type = typesIterator.next();
|
||||
|
||||
messages.add(new OutgoingPushMessage(relay, recipient, body, type));
|
||||
messages.add(new OutgoingPushMessage(recipient.getRelay(), recipient.getNumber(), body, type));
|
||||
}
|
||||
|
||||
sendMessage(new OutgoingPushMessageList(messages));
|
||||
@@ -143,11 +144,11 @@ public class PushServiceSocket {
|
||||
makeRequest(String.format(PREKEY_PATH, ""), "PUT", PreKeyList.toJson(new PreKeyList(lastResortEntity, entities)));
|
||||
}
|
||||
|
||||
public PreKeyEntity getPreKey(String relay, String number) throws IOException {
|
||||
String path = String.format(PREKEY_PATH, number);
|
||||
public PreKeyEntity getPreKey(PushDestination destination) throws IOException {
|
||||
String path = String.format(PREKEY_PATH, destination.getNumber());
|
||||
|
||||
if (relay != null) {
|
||||
path = path + "?relay=" + relay;
|
||||
if (destination.getRelay() != null) {
|
||||
path = path + "?relay=" + destination.getRelay();
|
||||
}
|
||||
|
||||
String responseText = makeRequest(path, "GET", null);
|
||||
|
Reference in New Issue
Block a user