aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java2
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java20
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java29
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java2
4 files changed, 26 insertions, 27 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java b/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
index 93cddacc1..74025eef3 100644
--- a/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
+++ b/src/main/java/de/pixart/messenger/crypto/PgpDecryptionService.java
@@ -209,10 +209,10 @@ public class PgpDecryptionService {
URL url = message.getFileParams().url;
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
+ mXmppConnectionService.updateMessage(message);
if (!inputFile.delete()) {
Log.w(Config.LOGTAG, "unable to delete pgp encrypted source file " + inputFile.getAbsolutePath());
}
- mXmppConnectionService.updateMessage(message);
skipNotificationPush = true;
mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile, () -> notifyIfPending(message));
break;
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index 73e2786dc..c375aafa1 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -193,20 +193,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
- public void findMessagesWithFiles(final OnMessageFound onMessageFound) {
- final ArrayList<Message> results = new ArrayList<>();
- synchronized (this.messages) {
- for (final Message m : this.messages) {
- if (m.isFileOrImage() && m.getEncryption() != Message.ENCRYPTION_PGP) {
- results.add(m);
- }
- }
- }
- for (Message result : results) {
- onMessageFound.onMessageFound(result);
- }
- }
-
public void findFailedMessagesWithFiles(final OnMessageFound onMessageFound) {
final ArrayList<Message> results = new ArrayList<>();
synchronized (this.messages) {
@@ -252,11 +238,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public boolean markAsDeleted(final List<String> uuids) {
boolean deleted = false;
+ final PgpDecryptionService pgpDecryptionService = account.getPgpDecryptionService();
synchronized (this.messages) {
- for(Message message : this.messages) {
+ for (Message message : this.messages) {
if (uuids.contains(message.getUuid())) {
message.setFileDeleted(true);
deleted = true;
+ if (message.getEncryption() == Message.ENCRYPTION_PGP && pgpDecryptionService != null) {
+ pgpDecryptionService.discard(message);
+ }
}
}
}
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index 22c1ae6e3..f17845b75 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -161,8 +161,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ ");";
private static String CREATE_MESSAGE_TIME_INDEX = "create INDEX message_time_index ON " + Message.TABLENAME + "(" + Message.TIME_SENT + ")";
private static String CREATE_MESSAGE_CONVERSATION_INDEX = "create INDEX message_conversation_index ON " + Message.TABLENAME + "(" + Message.CONVERSATION + ")";
- private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON "+ Message.TABLENAME + "(" + Message.DELETED + ")";
- private static String CREATE_MESSAGE_FILE_DELETED_INDEX = "create index message_file_deleted_index ON "+ Message.TABLENAME + "(" + Message.FILE_DELETED + ")";
+ private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON " + Message.TABLENAME + "(" + Message.DELETED + ")";
+ private static String CREATE_MESSAGE_FILE_DELETED_INDEX = "create index message_file_deleted_index ON " + Message.TABLENAME + "(" + Message.FILE_DELETED + ")";
private static String CREATE_MESSAGE_RELATIVE_FILE_PATH_INDEX = "create INDEX message_file_path_index ON " + Message.TABLENAME + "(" + Message.RELATIVE_FILE_PATH + ")";
private static String CREATE_MESSAGE_TYPE_INDEX = "create INDEX message_type_index ON " + Message.TABLENAME + "(" + Message.TYPE + ")";
@@ -346,7 +346,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
/* Any migrations that alter the Account table need to happen BEFORE this migration, as it
* depends on account de-serialization.
- */
+ */
if (oldVersion < 17 && newVersion >= 17 && newVersion < 31) {
List<Account> accounts = getAccounts(db);
for (Account account : accounts) {
@@ -819,8 +819,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
String selection;
String[] selectionArgs;
if (internal) {
- selection = Message.RELATIVE_FILE_PATH + " IN(?,?) and type in (1,2)";
- selectionArgs = new String[]{file.getAbsolutePath(), file.getName()};
+ final String name = file.getName();
+ if (name.endsWith(".pgp")) {
+ selection = "(" + Message.RELATIVE_FILE_PATH + " IN(?,?) OR (" + Message.RELATIVE_FILE_PATH + "=? and encryption in(1,4))) and type in (1,2)";
+ selectionArgs = new String[]{file.getAbsolutePath(), name, name.substring(0, name.length() - 4)};
+ } else {
+ selection = Message.RELATIVE_FILE_PATH + " IN(?,?) and type in (1,2)";
+ selectionArgs = new String[]{file.getAbsolutePath(), name};
+ }
} else {
selection = Message.RELATIVE_FILE_PATH + "=? and type in (1,2)";
selectionArgs = new String[]{file.getAbsolutePath()};
@@ -866,7 +872,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public List<FilePath> getRelativeFilePaths(String account, Jid jid, int limit) {
SQLiteDatabase db = this.getReadableDatabase();
final String SQL = "select uuid,relativeFilePath from messages where type in (1,2) and file_deleted=0 and conversationUuid=(select uuid from conversations where accountUuid=? and (contactJid=? or contactJid like ?)) order by timeSent desc";
-
final String[] args = {account, jid.toEscapedString(), jid.toEscapedString() + "/%"};
Cursor cursor = db.rawQuery(SQL + (limit > 0 ? " limit " + String.valueOf(limit) : ""), args);
List<FilePath> filesPaths = new ArrayList<>();
@@ -941,6 +946,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
}
+
private List<Account> getAccounts(SQLiteDatabase db) {
List<Account> list = new ArrayList<>();
Cursor cursor = db.query(Account.TABLENAME, null, null, null, null,
@@ -977,11 +983,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return db.update(Message.TABLENAME, message.getContentValues(), Message.UUID + "=?", args) == 1;
}
- public void updateMessage(Message message, String uuid) {
+ public boolean updateMessage(Message message, String uuid) {
SQLiteDatabase db = this.getWritableDatabase();
String[] args = {uuid};
- db.update(Message.TABLENAME, message.getContentValues(), Message.UUID
- + "=?", args);
+ return db.update(Message.TABLENAME, message.getContentValues(), Message.UUID + "=?", args) == 1;
}
public void readRoster(Roster roster) {
@@ -1020,10 +1025,13 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public void deleteMessageInConversation(Message message) {
long start = SystemClock.elapsedRealtime();
final SQLiteDatabase db = this.getWritableDatabase();
+ db.beginTransaction();
ContentValues values = new ContentValues();
values.put(Message.DELETED, "1");
String[] args = {message.getUuid()};
int rows = db.update("messages", values, "uuid =?", args);
+ db.setTransactionSuccessful();
+ db.endTransaction();
Log.d(Config.LOGTAG, "deleted " + rows + " message in " + (SystemClock.elapsedRealtime() - start) + "ms");
}
@@ -1594,7 +1602,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
storeIdentityKey(account, account.getJid().asBareJid().toString(), true, CryptoHelper.bytesToHex(identityKeyPair.getPublicKey().serialize()), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), FingerprintStatus.createActiveVerified(false));
}
- public void recreateAxolotlDb(SQLiteDatabase db) {
+
+ private void recreateAxolotlDb(SQLiteDatabase db) {
Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + ">>> (RE)CREATING AXOLOTL DATABASE <<<");
db.execSQL("DROP TABLE IF EXISTS " + SQLiteAxolotlStore.SESSION_TABLENAME);
db.execSQL(CREATE_SESSIONS_STATEMENT);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 075692101..2e9325ea2 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -1309,7 +1309,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
copyLink.setVisible(true);
}
}
- if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
+ if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
retryDecryption.setVisible(true);
}
if (!showError