diff options
Diffstat (limited to '')
3 files changed, 73 insertions, 13 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 523e02b77..22c363f3a 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -29,6 +29,7 @@ import de.pixart.messenger.Config; import de.pixart.messenger.crypto.OmemoSetting; import de.pixart.messenger.crypto.PgpDecryptionService; import de.pixart.messenger.crypto.axolotl.AxolotlService; +import de.pixart.messenger.persistance.DatabaseBackend; import de.pixart.messenger.services.QuickConversationsService; import de.pixart.messenger.utils.JidHelper; import de.pixart.messenger.xmpp.chatstate.ChatState; @@ -253,6 +254,25 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return deleted; } + + public boolean markAsChanged(final List<DatabaseBackend.FilePathInfo> files) { + boolean changed = false; + final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService(); + synchronized (this.messages) { + for (Message message : this.messages) { + for (final DatabaseBackend.FilePathInfo file : files) + if (file.uuid.toString().equals(message.getUuid())) { + message.setFileDeleted(file.FileDeleted); + changed = true; + if (file.FileDeleted && message.getEncryption() == Message.ENCRYPTION_PGP && pgpDecryptionService != null) { + pgpDecryptionService.discard(message); + } + } + } + } + return changed; + } + public void clearMessages() { synchronized (this.messages) { this.messages.clear(); diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 02539c036..8336a4ed9 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -877,12 +877,25 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.endTransaction(); } - public List<FilePath> getAllNonDeletedFilePath() { + public void markFilesAsChanged(List<FilePathInfo> files) { + SQLiteDatabase db = this.getReadableDatabase(); + final String where = Message.UUID + "=?"; + db.beginTransaction(); + for (FilePathInfo info : files) { + final ContentValues contentValues = new ContentValues(); + contentValues.put(Message.FILE_DELETED, info.FileDeleted ? 1 : 0); + db.update(Message.TABLENAME, contentValues, where, new String[]{info.uuid.toString()}); + } + db.setTransactionSuccessful(); + db.endTransaction(); + } + + public List<FilePathInfo> getFilePathInfo() { final SQLiteDatabase db = this.getReadableDatabase(); - final Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID, Message.RELATIVE_FILE_PATH}, "type in (1,2) and file_deleted=0 and " + Message.RELATIVE_FILE_PATH + " is not null", null, null, null, null); - final List<FilePath> list = new ArrayList<>(); + final Cursor cursor = db.query(Message.TABLENAME, new String[]{Message.UUID, Message.RELATIVE_FILE_PATH, Message.FILE_DELETED}, "type in (1,2) and " + Message.RELATIVE_FILE_PATH + " is not null", null, null, null, null); + final List<FilePathInfo> list = new ArrayList<>(); while (cursor != null && cursor.moveToNext()) { - list.add(new FilePath(cursor.getString(0), cursor.getString(1))); + list.add(new FilePathInfo(cursor.getString(0), cursor.getString(1), cursor.getInt(2) > 0)); } if (cursor != null) { cursor.close(); @@ -913,6 +926,21 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } + public static class FilePathInfo extends FilePath { + public boolean FileDeleted; + + private FilePathInfo(String uuid, String path, boolean deleted) { + super(uuid, path); + this.FileDeleted = deleted; + } + + public boolean setFileDeleted(boolean deleted) { + final boolean changed = deleted != this.FileDeleted; + this.FileDeleted = deleted; + return changed; + } + } + public Conversation findConversation(final Account account, final Jid contactJid) { SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = {account.getUuid(), diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index bf4ffcd0a..ec3256b46 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1214,22 +1214,24 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, "Do not check for deleted files because service has been destroyed"); return; } - final List<String> deletedUuids = new ArrayList<>(); - final List<DatabaseBackend.FilePath> relativeFilePaths = databaseBackend.getAllNonDeletedFilePath(); - for (final DatabaseBackend.FilePath filePath : relativeFilePaths) { + final long start = SystemClock.elapsedRealtime(); + final List<DatabaseBackend.FilePathInfo> relativeFilePaths = databaseBackend.getFilePathInfo(); + final List<DatabaseBackend.FilePathInfo> changed = new ArrayList<>(); + for (final DatabaseBackend.FilePathInfo filePath : relativeFilePaths) { if (destroyed) { Log.d(Config.LOGTAG, "Stop checking for deleted files because service has been destroyed"); return; } final File file = fileBackend.getFileForPath(filePath.path); - if (!file.exists()) { - deletedUuids.add(filePath.uuid.toString()); + if (filePath.setFileDeleted(!file.exists())) { + changed.add(filePath); } } - Log.d(Config.LOGTAG, "found " + deletedUuids.size() + " deleted files on start up. total=" + relativeFilePaths.size()); - if (deletedUuids.size() > 0) { - databaseBackend.markFileAsDeleted(deletedUuids); - markUuidsAsDeletedFiles(deletedUuids); + final long duration = SystemClock.elapsedRealtime() - start; + Log.d(Config.LOGTAG, "found " + changed.size() + " changed files on start up. total=" + relativeFilePaths.size() + ". (" + duration + "ms)"); + if (changed.size() > 0) { + databaseBackend.markFilesAsChanged(changed); + markChangedFiles(changed); } } @@ -1869,6 +1871,16 @@ public class XmppConnectionService extends Service { } } + private void markChangedFiles(List<DatabaseBackend.FilePathInfo> infos) { + boolean changed = false; + for (Conversation conversation : getConversations()) { + changed |= conversation.markAsChanged(infos); + } + if (changed) { + updateConversationUi(); + } + } + public void populateWithOrderedConversations(final List<Conversation> list) { populateWithOrderedConversations(list, true, true); } |