mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-08 02:56:53 +00:00
Clean & handle media message errors
This commit is contained in:
parent
652201958a
commit
8c6b60aa08
@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.jobmanager.Data;
|
|||||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||||
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||||
import org.thoughtcrime.securesms.mms.MmsException;
|
import org.thoughtcrime.securesms.mms.MmsException;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
@ -35,6 +36,7 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
|||||||
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
||||||
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
|
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview;
|
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Preview;
|
||||||
@ -42,6 +44,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSy
|
|||||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
|
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities;
|
import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities;
|
||||||
import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage;
|
import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage;
|
||||||
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
|
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
|
||||||
@ -229,13 +232,17 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
|||||||
database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey());
|
database.addMismatchedIdentity(messageId, Address.fromSerialized(uie.getE164Number()), uie.getIdentityKey());
|
||||||
database.markAsSentFailed(messageId);
|
database.markAsSentFailed(messageId);
|
||||||
}
|
}
|
||||||
|
} catch (LokiAPI.Error e) {
|
||||||
|
android.util.Log.d("Loki", "Couldn't send message due to error: " + e.getDescription());
|
||||||
|
if (messageId < 0) { return; }
|
||||||
|
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context);
|
||||||
|
lokiMessageDatabase.setErrorMessage(messageId, e.getDescription());
|
||||||
|
database.markAsSentFailed(messageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onShouldRetry(@NonNull Exception exception) {
|
public boolean onShouldRetry(@NonNull Exception exception) {
|
||||||
// Loki - Disable since we have our own retrying
|
|
||||||
// if (exception instanceof RetryLaterException) return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +256,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
|||||||
|
|
||||||
private boolean deliver(OutgoingMediaMessage message)
|
private boolean deliver(OutgoingMediaMessage message)
|
||||||
throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException,
|
throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException,
|
||||||
UndeliverableMessageException
|
UndeliverableMessageException, LokiAPI.Error
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Recipient recipient = Recipient.from(context, destination, false);
|
Recipient recipient = Recipient.from(context, destination, false);
|
||||||
@ -295,7 +302,17 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
|||||||
// We also need to use the original message ID and not -1
|
// We also need to use the original message ID and not -1
|
||||||
syncMessage = new LokiSyncMessage(masterAddress, templateMessageId);
|
syncMessage = new LokiSyncMessage(masterAddress, templateMessageId);
|
||||||
}
|
}
|
||||||
return messageSender.sendMessage(messageId, address, UnidentifiedAccessUtil.getAccessFor(context, recipient), mediaMessage, Optional.fromNullable(syncMessage)).getSuccess().isUnidentified();
|
SendMessageResult result = messageSender.sendMessage(messageId, address, UnidentifiedAccessUtil.getAccessFor(context, recipient), mediaMessage, Optional.fromNullable(syncMessage));
|
||||||
|
if (result.getLokiAPIError() != null) {
|
||||||
|
Throwable lokiAPIError = result.getLokiAPIError();
|
||||||
|
if (lokiAPIError instanceof LokiAPI.Error) { // Should always be true
|
||||||
|
throw (LokiAPI.Error) lokiAPIError;
|
||||||
|
} else {
|
||||||
|
return result.getSuccess().isUnidentified();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return result.getSuccess().isUnidentified();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (UnregisteredUserException e) {
|
} catch (UnregisteredUserException e) {
|
||||||
warn(TAG, e);
|
warn(TAG, e);
|
||||||
|
@ -34,8 +34,6 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
|||||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities;
|
import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities;
|
||||||
import org.whispersystems.signalservice.loki.api.LokiDotNetAPI;
|
|
||||||
import org.whispersystems.signalservice.loki.api.LokiSnodeProxy;
|
|
||||||
import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage;
|
import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage;
|
||||||
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
|
import org.whispersystems.signalservice.loki.utilities.PromiseUtil;
|
||||||
|
|
||||||
@ -122,8 +120,6 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log(TAG, "Sending message: " + templateMessageId + (hasSameDestination ? "" : "to another device."));
|
log(TAG, "Sending message: " + templateMessageId + (hasSameDestination ? "" : "to another device."));
|
||||||
|
|
||||||
@ -181,16 +177,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
} catch (LokiAPI.Error e) {
|
} catch (LokiAPI.Error e) {
|
||||||
Log.d("Loki", "Couldn't send message due to error: " + e.getDescription());
|
Log.d("Loki", "Couldn't send message due to error: " + e.getDescription());
|
||||||
if (messageId < 0) { return; }
|
if (messageId < 0) { return; }
|
||||||
lokiMessageDatabase.setErrorMessage(record.getId(), e.getDescription());
|
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context);
|
||||||
database.markAsSentFailed(record.getId());
|
|
||||||
} catch (LokiDotNetAPI.Error e) {
|
|
||||||
Log.d("Loki", "Couldn't send message due to error: " + e.getDescription());
|
|
||||||
if (messageId < 0) { return; }
|
|
||||||
lokiMessageDatabase.setErrorMessage(record.getId(), e.getDescription());
|
|
||||||
database.markAsSentFailed(record.getId());
|
|
||||||
} catch (LokiSnodeProxy.Error e) {
|
|
||||||
Log.d("Loki", "Couldn't send message due to error: " + e.getDescription());
|
|
||||||
if (messageId < 0) { return; }
|
|
||||||
lokiMessageDatabase.setErrorMessage(record.getId(), e.getDescription());
|
lokiMessageDatabase.setErrorMessage(record.getId(), e.getDescription());
|
||||||
database.markAsSentFailed(record.getId());
|
database.markAsSentFailed(record.getId());
|
||||||
}
|
}
|
||||||
@ -219,7 +206,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean deliver(SmsMessageRecord message)
|
private boolean deliver(SmsMessageRecord message)
|
||||||
throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException, LokiAPI.Error, LokiDotNetAPI.Error, LokiSnodeProxy.Error
|
throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException, LokiAPI.Error
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// rotateSenderCertificateIfNecessary();
|
// rotateSenderCertificateIfNecessary();
|
||||||
@ -265,14 +252,10 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
syncMessage = new LokiSyncMessage(masterAddress, templateMessageId);
|
syncMessage = new LokiSyncMessage(masterAddress, templateMessageId);
|
||||||
}
|
}
|
||||||
SendMessageResult result = messageSender.sendMessage(messageId, address, unidentifiedAccess, textSecureMessage, Optional.fromNullable(syncMessage));
|
SendMessageResult result = messageSender.sendMessage(messageId, address, unidentifiedAccess, textSecureMessage, Optional.fromNullable(syncMessage));
|
||||||
if (result.getException() != null) {
|
if (result.getLokiAPIError() != null) {
|
||||||
Throwable exception = result.getException();
|
Throwable lokiAPIError = result.getLokiAPIError();
|
||||||
if (exception instanceof LokiAPI.Error) {
|
if (lokiAPIError instanceof LokiAPI.Error) { // Should always be true
|
||||||
throw (LokiAPI.Error) exception;
|
throw (LokiAPI.Error) lokiAPIError;
|
||||||
} else if (exception instanceof LokiDotNetAPI.Error) {
|
|
||||||
throw (LokiDotNetAPI.Error) exception;
|
|
||||||
} else if (exception instanceof LokiSnodeProxy.Error) {
|
|
||||||
throw (LokiSnodeProxy.Error) exception;
|
|
||||||
} else {
|
} else {
|
||||||
return result.getSuccess().isUnidentified();
|
return result.getSuccess().isUnidentified();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user