mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Better handling for unregistered users on outgoing message.
This commit is contained in:
parent
3c3028c8e3
commit
71664926e9
@ -116,12 +116,14 @@ public class PushServiceSocket {
|
|||||||
sendMessage(new OutgoingPushMessageList(messages));
|
sendMessage(new OutgoingPushMessageList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(OutgoingPushMessageList messages) throws IOException {
|
private void sendMessage(OutgoingPushMessageList messages)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
String responseText = makeRequest(MESSAGE_PATH, "POST", new Gson().toJson(messages));
|
String responseText = makeRequest(MESSAGE_PATH, "POST", new Gson().toJson(messages));
|
||||||
PushMessageResponse response = new Gson().fromJson(responseText, PushMessageResponse.class);
|
PushMessageResponse response = new Gson().fromJson(responseText, PushMessageResponse.class);
|
||||||
|
|
||||||
if (response.getFailure().size() != 0)
|
if (response.getFailure().size() != 0)
|
||||||
throw new IOException("Got send failure: " + response.getFailure().get(0));
|
throw new UnregisteredUserException(response.getFailure());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPreKeys(IdentityKey identityKey,
|
public void registerPreKeys(IdentityKey identityKey,
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package org.whispersystems.textsecure.push;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class UnregisteredUserException extends IOException {
|
||||||
|
|
||||||
|
private final List<String> addresses;
|
||||||
|
|
||||||
|
public UnregisteredUserException(List<String> addresses) {
|
||||||
|
super();
|
||||||
|
this.addresses = addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAddresses() {
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -46,6 +46,7 @@ import org.whispersystems.textsecure.push.PushDestination;
|
|||||||
import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
|
import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
import org.whispersystems.textsecure.push.RateLimitException;
|
import org.whispersystems.textsecure.push.RateLimitException;
|
||||||
|
import org.whispersystems.textsecure.push.UnregisteredUserException;
|
||||||
import org.whispersystems.textsecure.storage.SessionRecordV2;
|
import org.whispersystems.textsecure.storage.SessionRecordV2;
|
||||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||||
|
|
||||||
@ -83,6 +84,10 @@ public class PushTransport extends BaseTransport {
|
|||||||
socket.sendMessage(destination, pushBody);
|
socket.sendMessage(destination, pushBody);
|
||||||
|
|
||||||
context.sendBroadcast(constructSentIntent(context, message.getId(), message.getType(), true));
|
context.sendBroadcast(constructSentIntent(context, message.getId(), message.getType(), true));
|
||||||
|
} catch (UnregisteredUserException e) {
|
||||||
|
Log.w("PushTransport", e);
|
||||||
|
destroySessions(e.getAddresses());
|
||||||
|
throw new IOException("Not push registered after all.");
|
||||||
} catch (RateLimitException e) {
|
} catch (RateLimitException e) {
|
||||||
Log.w("PushTransport", e);
|
Log.w("PushTransport", e);
|
||||||
throw new IOException("Rate limit exceeded.");
|
throw new IOException("Rate limit exceeded.");
|
||||||
@ -128,6 +133,10 @@ public class PushTransport extends BaseTransport {
|
|||||||
|
|
||||||
socket.sendMessage(destinations, pushBodies);
|
socket.sendMessage(destinations, pushBodies);
|
||||||
|
|
||||||
|
} catch (UnregisteredUserException e) {
|
||||||
|
Log.w("PushTransport", e);
|
||||||
|
destroySessions(e.getAddresses());
|
||||||
|
throw new IOException("No push registered after all.");
|
||||||
} catch (RateLimitException e) {
|
} catch (RateLimitException e) {
|
||||||
Log.w("PushTransport", e);
|
Log.w("PushTransport", e);
|
||||||
throw new IOException("Rate limit exceeded.");
|
throw new IOException("Rate limit exceeded.");
|
||||||
@ -188,4 +197,16 @@ public class PushTransport extends BaseTransport {
|
|||||||
throw new AssertionError("Unknown ciphertext type: " + message.getType());
|
throw new AssertionError("Unknown ciphertext type: " + message.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void destroySessions(List<String> unregisteredUsers) {
|
||||||
|
for (String unregisteredUser : unregisteredUsers) {
|
||||||
|
Log.w("PushTransport", "Destroying session for: " + unregisteredUser);
|
||||||
|
try {
|
||||||
|
Recipients recipients = RecipientFactory.getRecipientsFromString(context, unregisteredUser, false);
|
||||||
|
SessionRecordV2.delete(context, recipients.getPrimaryRecipient());
|
||||||
|
} catch (RecipientFormattingException e) {
|
||||||
|
Log.w("PushTransport", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user