From ee3e9ae17fcbea73d42c6c8e35001f01cd9be9a2 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Mon, 16 Aug 2021 09:58:28 +1000 Subject: [PATCH] delete outgoing message for linked device --- .../attachments/DatabaseAttachmentProvider.kt | 23 ++++++++----------- .../securesms/database/MessagingDatabase.java | 2 ++ .../securesms/database/MmsDatabase.java | 7 +++--- .../securesms/database/SmsDatabase.java | 1 + .../service/ExpiringMessageManager.java | 2 +- .../securesms/util/AttachmentUtil.java | 2 +- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt index aa1fe66f37..2ed700cb3d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/attachments/DatabaseAttachmentProvider.kt @@ -19,6 +19,7 @@ import org.session.libsignal.utilities.guava.Optional import org.thoughtcrime.securesms.database.AttachmentDatabase import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.database.MessagingDatabase import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.events.PartProgressEvent import org.thoughtcrime.securesms.mms.MediaConstraints @@ -167,13 +168,9 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) } override fun deleteMessage(messageID: Long, isSms: Boolean) { - if (isSms) { - val db = DatabaseFactory.getSmsDatabase(context) - db.deleteMessage(messageID) - } else { - val db = DatabaseFactory.getMmsDatabase(context) - db.delete(messageID) - } + val messagingDatabase: MessagingDatabase = if (isSms) DatabaseFactory.getSmsDatabase(context) + else DatabaseFactory.getMmsDatabase(context) + messagingDatabase.deleteMessage(messageID) DatabaseFactory.getLokiMessageDatabase(context).deleteMessage(messageID, isSms) DatabaseFactory.getLokiMessageDatabase(context).deleteMessageServerHash(messageID) } @@ -182,14 +179,12 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) val database = DatabaseFactory.getMmsSmsDatabase(context) val address = Address.fromSerialized(author) val message = database.getMessageFor(timestamp, address)!! - if (message.isMms) { - val mmsDatabase = DatabaseFactory.getMmsDatabase(context) - mmsDatabase.markAsDeleted(message.id, message.isRead) - } else { - val smsDatabase = DatabaseFactory.getSmsDatabase(context) - smsDatabase.markAsDeleted(message.id, message.isRead) + val messagingDatabase: MessagingDatabase = if (message.isMms) DatabaseFactory.getMmsDatabase(context) + else DatabaseFactory.getSmsDatabase(context) + messagingDatabase.markAsDeleted(message.id, message.isRead) + if (message.isOutgoing) { + messagingDatabase.deleteMessage(message.id) } - } override fun getServerHashForMessage(messageID: Long): String? { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java index f542058c76..a3906d2871 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MessagingDatabase.java @@ -40,6 +40,8 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn public abstract void markAsDeleted(long messageId, boolean read); + public abstract boolean deleteMessage(long messageId); + public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) { try { addToDocument(messageId, MISMATCHED_IDENTITIES, diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java index 1fa26000a6..f56792aa71 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -923,7 +923,8 @@ public class MmsDatabase extends MessagingDatabase { reader.close(); } - public boolean delete(long messageId) { + @Override + public boolean deleteMessage(long messageId) { long threadId = getThreadIdForMessage(messageId); AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context); ThreadUtils.queue(() -> attachmentDatabase.deleteAttachmentsForMessage(messageId)); @@ -1050,7 +1051,7 @@ public class MmsDatabase extends MessagingDatabase { cursor = db.query(TABLE_NAME, new String[] {ID}, where, null, null, null, null); while (cursor != null && cursor.moveToNext()) { - delete(cursor.getLong(0)); + deleteMessage(cursor.getLong(0)); } } finally { @@ -1076,7 +1077,7 @@ public class MmsDatabase extends MessagingDatabase { while (cursor != null && cursor.moveToNext()) { Log.i("MmsDatabase", "Trimming: " + cursor.getLong(0)); - delete(cursor.getLong(0)); + deleteMessage(cursor.getLong(0)); } } finally { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java index 5b75037636..17a8364776 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -529,6 +529,7 @@ public class SmsDatabase extends MessagingDatabase { return cursor; } + @Override public boolean deleteMessage(long messageId) { Log.i("MessageDatabase", "Deleting: " + messageId); SQLiteDatabase db = databaseHelper.getWritableDatabase(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java index c2c4834cd5..59cd5cc0c0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/ExpiringMessageManager.java @@ -229,7 +229,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM } if (expiredMessage != null) { - if (expiredMessage.mms) mmsDatabase.delete(expiredMessage.id); + if (expiredMessage.mms) mmsDatabase.deleteMessage(expiredMessage.id); else smsDatabase.deleteMessage(expiredMessage.id); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java index 13cdcc6d6a..2697a634cf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/AttachmentUtil.java @@ -66,7 +66,7 @@ public class AttachmentUtil { .size(); if (attachmentCount <= 1) { - DatabaseFactory.getMmsDatabase(context).delete(mmsId); + DatabaseFactory.getMmsDatabase(context).deleteMessage(mmsId); } else { DatabaseFactory.getAttachmentDatabase(context).deleteAttachment(attachmentId); }