Better handling for unregistered users on outgoing message.

This commit is contained in:
Moxie Marlinspike
2013-12-07 16:04:34 -08:00
parent 3c3028c8e3
commit 71664926e9
3 changed files with 44 additions and 2 deletions

View File

@@ -46,6 +46,7 @@ import org.whispersystems.textsecure.push.PushDestination;
import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
import org.whispersystems.textsecure.push.PushServiceSocket;
import org.whispersystems.textsecure.push.RateLimitException;
import org.whispersystems.textsecure.push.UnregisteredUserException;
import org.whispersystems.textsecure.storage.SessionRecordV2;
import org.whispersystems.textsecure.util.InvalidNumberException;
@@ -83,6 +84,10 @@ public class PushTransport extends BaseTransport {
socket.sendMessage(destination, pushBody);
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) {
Log.w("PushTransport", e);
throw new IOException("Rate limit exceeded.");
@@ -128,6 +133,10 @@ public class PushTransport extends BaseTransport {
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) {
Log.w("PushTransport", e);
throw new IOException("Rate limit exceeded.");
@@ -188,4 +197,16 @@ public class PushTransport extends BaseTransport {
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);
}
}
}
}