Don't show error messages before restoration

This commit is contained in:
Ryan ZHAO 2020-08-21 15:39:13 +10:00
parent 82fb950956
commit ad5b2eceb7
2 changed files with 26 additions and 18 deletions

View File

@ -1072,36 +1072,38 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
@NonNull Optional<Long> smsMessageId) @NonNull Optional<Long> smsMessageId)
{ {
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
if (SessionMetaProtocol.shouldErrorMessageShow(context, timestamp)) {
if (!smsMessageId.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
if (!smsMessageId.isPresent()) { if (insertResult.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp); smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
messageNotifier.updateNotification(context, insertResult.get().getThreadId());
if (insertResult.isPresent()) { }
smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId()); } else {
messageNotifier.updateNotification(context, insertResult.get().getThreadId()); smsDatabase.markAsDecryptFailed(smsMessageId.get());
} }
} else {
smsDatabase.markAsDecryptFailed(smsMessageId.get());
} }
SessionManagementProtocol.triggerSessionRestorationUI(context, sender); SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
} }
private void handleNoSessionMessage(@NonNull String sender, int senderDevice, long timestamp, private void handleNoSessionMessage(@NonNull String sender, int senderDevice, long timestamp,
@NonNull Optional<Long> smsMessageId) @NonNull Optional<Long> smsMessageId)
{ {
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context); SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
if (SessionMetaProtocol.shouldErrorMessageShow(context, timestamp)) {
if (!smsMessageId.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp);
if (!smsMessageId.isPresent()) { if (insertResult.isPresent()) {
Optional<InsertResult> insertResult = insertPlaceholder(sender, senderDevice, timestamp); smsDatabase.markAsNoSession(insertResult.get().getMessageId());
messageNotifier.updateNotification(context, insertResult.get().getThreadId());
if (insertResult.isPresent()) { }
smsDatabase.markAsNoSession(insertResult.get().getMessageId()); } else {
messageNotifier.updateNotification(context, insertResult.get().getThreadId()); smsDatabase.markAsNoSession(smsMessageId.get());
} }
} else {
smsDatabase.markAsNoSession(smsMessageId.get());
} }
SessionManagementProtocol.triggerSessionRestorationUI(context, sender); SessionManagementProtocol.triggerSessionRestorationUI(context, sender, timestamp);
} }
private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp, private void handleLegacyMessage(@NonNull String sender, int senderDevice, long timestamp,

View File

@ -30,6 +30,12 @@ object SessionMetaProtocol {
return shouldIgnoreMessage return shouldIgnoreMessage
} }
@JvmStatic
fun shouldErrorMessageShow(context: Context, timestamp: Long): Boolean {
val restorationTimestamp = TextSecurePreferences.getRestorationTime(context)
return timestamp > restorationTimestamp
}
@JvmStatic @JvmStatic
fun handleProfileUpdateIfNeeded(context: Context, content: SignalServiceContent) { fun handleProfileUpdateIfNeeded(context: Context, content: SignalServiceContent) {
val rawDisplayName = content.senderDisplayName.orNull() ?: return val rawDisplayName = content.senderDisplayName.orNull() ?: return