delete outgoing message for linked device

This commit is contained in:
ryanzhao 2021-08-16 09:58:28 +10:00
parent 064e509992
commit ee3e9ae17f
6 changed files with 18 additions and 19 deletions

View File

@ -19,6 +19,7 @@ import org.session.libsignal.utilities.guava.Optional
import org.thoughtcrime.securesms.database.AttachmentDatabase import org.thoughtcrime.securesms.database.AttachmentDatabase
import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.Database
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.MessagingDatabase
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.thoughtcrime.securesms.events.PartProgressEvent import org.thoughtcrime.securesms.events.PartProgressEvent
import org.thoughtcrime.securesms.mms.MediaConstraints import org.thoughtcrime.securesms.mms.MediaConstraints
@ -167,13 +168,9 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
} }
override fun deleteMessage(messageID: Long, isSms: Boolean) { override fun deleteMessage(messageID: Long, isSms: Boolean) {
if (isSms) { val messagingDatabase: MessagingDatabase = if (isSms) DatabaseFactory.getSmsDatabase(context)
val db = DatabaseFactory.getSmsDatabase(context) else DatabaseFactory.getMmsDatabase(context)
db.deleteMessage(messageID) messagingDatabase.deleteMessage(messageID)
} else {
val db = DatabaseFactory.getMmsDatabase(context)
db.delete(messageID)
}
DatabaseFactory.getLokiMessageDatabase(context).deleteMessage(messageID, isSms) DatabaseFactory.getLokiMessageDatabase(context).deleteMessage(messageID, isSms)
DatabaseFactory.getLokiMessageDatabase(context).deleteMessageServerHash(messageID) DatabaseFactory.getLokiMessageDatabase(context).deleteMessageServerHash(messageID)
} }
@ -182,14 +179,12 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
val database = DatabaseFactory.getMmsSmsDatabase(context) val database = DatabaseFactory.getMmsSmsDatabase(context)
val address = Address.fromSerialized(author) val address = Address.fromSerialized(author)
val message = database.getMessageFor(timestamp, address)!! val message = database.getMessageFor(timestamp, address)!!
if (message.isMms) { val messagingDatabase: MessagingDatabase = if (message.isMms) DatabaseFactory.getMmsDatabase(context)
val mmsDatabase = DatabaseFactory.getMmsDatabase(context) else DatabaseFactory.getSmsDatabase(context)
mmsDatabase.markAsDeleted(message.id, message.isRead) messagingDatabase.markAsDeleted(message.id, message.isRead)
} else { if (message.isOutgoing) {
val smsDatabase = DatabaseFactory.getSmsDatabase(context) messagingDatabase.deleteMessage(message.id)
smsDatabase.markAsDeleted(message.id, message.isRead)
} }
} }
override fun getServerHashForMessage(messageID: Long): String? { override fun getServerHashForMessage(messageID: Long): String? {

View File

@ -40,6 +40,8 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn
public abstract void markAsDeleted(long messageId, boolean read); public abstract void markAsDeleted(long messageId, boolean read);
public abstract boolean deleteMessage(long messageId);
public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) { public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) {
try { try {
addToDocument(messageId, MISMATCHED_IDENTITIES, addToDocument(messageId, MISMATCHED_IDENTITIES,

View File

@ -923,7 +923,8 @@ public class MmsDatabase extends MessagingDatabase {
reader.close(); reader.close();
} }
public boolean delete(long messageId) { @Override
public boolean deleteMessage(long messageId) {
long threadId = getThreadIdForMessage(messageId); long threadId = getThreadIdForMessage(messageId);
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context); AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
ThreadUtils.queue(() -> attachmentDatabase.deleteAttachmentsForMessage(messageId)); 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); cursor = db.query(TABLE_NAME, new String[] {ID}, where, null, null, null, null);
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
delete(cursor.getLong(0)); deleteMessage(cursor.getLong(0));
} }
} finally { } finally {
@ -1076,7 +1077,7 @@ public class MmsDatabase extends MessagingDatabase {
while (cursor != null && cursor.moveToNext()) { while (cursor != null && cursor.moveToNext()) {
Log.i("MmsDatabase", "Trimming: " + cursor.getLong(0)); Log.i("MmsDatabase", "Trimming: " + cursor.getLong(0));
delete(cursor.getLong(0)); deleteMessage(cursor.getLong(0));
} }
} finally { } finally {

View File

@ -529,6 +529,7 @@ public class SmsDatabase extends MessagingDatabase {
return cursor; return cursor;
} }
@Override
public boolean deleteMessage(long messageId) { public boolean deleteMessage(long messageId) {
Log.i("MessageDatabase", "Deleting: " + messageId); Log.i("MessageDatabase", "Deleting: " + messageId);
SQLiteDatabase db = databaseHelper.getWritableDatabase(); SQLiteDatabase db = databaseHelper.getWritableDatabase();

View File

@ -229,7 +229,7 @@ public class ExpiringMessageManager implements SSKEnvironment.MessageExpirationM
} }
if (expiredMessage != null) { if (expiredMessage != null) {
if (expiredMessage.mms) mmsDatabase.delete(expiredMessage.id); if (expiredMessage.mms) mmsDatabase.deleteMessage(expiredMessage.id);
else smsDatabase.deleteMessage(expiredMessage.id); else smsDatabase.deleteMessage(expiredMessage.id);
} }
} }

View File

@ -66,7 +66,7 @@ public class AttachmentUtil {
.size(); .size();
if (attachmentCount <= 1) { if (attachmentCount <= 1) {
DatabaseFactory.getMmsDatabase(context).delete(mmsId); DatabaseFactory.getMmsDatabase(context).deleteMessage(mmsId);
} else { } else {
DatabaseFactory.getAttachmentDatabase(context).deleteAttachment(attachmentId); DatabaseFactory.getAttachmentDatabase(context).deleteAttachment(attachmentId);
} }