Bundle e164 and relay into PushDestination

This commit is contained in:
Moxie Marlinspike
2013-10-19 16:42:25 -07:00
parent ca3c82f581
commit 246cd10454
4 changed files with 92 additions and 51 deletions

View File

@@ -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);
}
}

View File

@@ -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);