mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 10:35:19 +00:00
Merge branch 'dev' into profile-pic-placeholder
This commit is contained in:
commit
299bdec87f
@ -66,6 +66,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||
import org.thoughtcrime.securesms.loki.database.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionManagementProtocol;
|
||||
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
||||
@ -1085,7 +1086,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
@NonNull Optional<Long> smsMessageId, @NonNull Throwable e)
|
||||
{
|
||||
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||
if (SessionMetaProtocol.shouldErrorMessageShow(context, timestamp)) {
|
||||
if (!SessionMetaProtocol.shouldIgnoreDecryptionException(context, timestamp)) {
|
||||
if (!smsMessageId.isPresent()) {
|
||||
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
|
||||
|
||||
@ -1098,29 +1099,37 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This is a temporary patch for bad mac issues. At least with this people will be able to message again. We have to figure out the root cause of the issue though.
|
||||
if (canRecoverAutomatically(e)) {
|
||||
Recipient recipient = Recipient.from(context, Address.fromSerialized(sender), false);
|
||||
LokiThreadDatabase threadDB = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
||||
threadDB.addSessionRestoreDevice(threadID, sender);
|
||||
SessionManagementProtocol.startSessionReset(context, sender);
|
||||
} else {
|
||||
SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canRecoverAutomatically(Throwable e) {
|
||||
// Corrupt message exception
|
||||
if (e.getCause() != null) {
|
||||
Throwable e2 = e.getCause();
|
||||
if (e2.getCause() != null) {
|
||||
Throwable e3 = e2.getCause();
|
||||
if (e3 instanceof InvalidMessageException) {
|
||||
String message = e3.getMessage();
|
||||
if (message != null && message.startsWith("Bad Mac!")) {
|
||||
SessionManagementProtocol.startSessionReset(context, sender);
|
||||
return; // Don't trigger the session restoration UI
|
||||
}
|
||||
return (message != null && message.startsWith("Bad Mac!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleNoSessionMessage(@NonNull String sender, int senderDevice, long timestamp,
|
||||
@NonNull Optional<Long> smsMessageId)
|
||||
{
|
||||
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||
if (SessionMetaProtocol.shouldErrorMessageShow(context, timestamp)) {
|
||||
if (!SessionMetaProtocol.shouldIgnoreDecryptionException(context, timestamp)) {
|
||||
if (!smsMessageId.isPresent()) {
|
||||
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
|
||||
|
||||
@ -1132,7 +1141,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
smsDatabase.markAsNoSession(smsMessageId.get());
|
||||
}
|
||||
}
|
||||
SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
|
||||
|
||||
// Attempt to recover automatically
|
||||
ApplicationContext.getInstance(context).sendSessionRequestIfNeeded(sender);
|
||||
}
|
||||
|
||||
private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp,
|
||||
|
@ -28,7 +28,6 @@ object SessionManagementProtocol {
|
||||
val recipient = recipient(context, publicKey)
|
||||
if (recipient.isGroupRecipient) { return }
|
||||
val lokiThreadDB = DatabaseFactory.getLokiThreadDatabase(context)
|
||||
if (lokiThreadDB.getSessionResetStatus(publicKey) != SessionResetStatus.NONE) { return }
|
||||
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient)
|
||||
val devices = lokiThreadDB.getSessionRestoreDevices(threadID)
|
||||
for (device in devices) {
|
||||
|
@ -30,9 +30,9 @@ object SessionMetaProtocol {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun shouldErrorMessageShow(context: Context, timestamp: Long): Boolean {
|
||||
fun shouldIgnoreDecryptionException(context: Context, timestamp: Long): Boolean {
|
||||
val restorationTimestamp = TextSecurePreferences.getRestorationTime(context)
|
||||
return timestamp > restorationTimestamp
|
||||
return timestamp <= restorationTimestamp
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
Loading…
Reference in New Issue
Block a user