diff --git a/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java b/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java index 970cbd570..988e0328a 100644 --- a/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java +++ b/src/conversations/java/eu/siacs/conversations/services/ImportBackupService.java @@ -103,6 +103,7 @@ public class ImportBackupService extends Service { public void loadBackupFiles(OnBackupFilesLoaded onBackupFilesLoaded) { executor.execute(() -> { + List accounts = mDatabaseBackend.getAccountJids(false); final ArrayList backupFiles = new ArrayList<>(); final Set apps = new HashSet<>(Arrays.asList("Conversations", "Quicksy", getString(R.string.app_name))); for (String app : apps) { @@ -114,7 +115,12 @@ public class ImportBackupService extends Service { for (File file : directory.listFiles()) { if (file.isFile() && file.getName().endsWith(".ceb")) { try { - backupFiles.add(BackupFile.read(file)); + final BackupFile backupFile = BackupFile.read(file); + if (accounts.contains(backupFile.getHeader().getJid())) { + Log.d(Config.LOGTAG,"skipping backup for "+backupFile.getHeader().getJid()); + } else { + backupFiles.add(backupFile); + } } catch (IOException e) { Log.d(Config.LOGTAG, "unable to read backup file ", e); } @@ -153,7 +159,6 @@ public class ImportBackupService extends Service { BufferedReader reader = new BufferedReader(new InputStreamReader(gzipInputStream, "UTF-8")); String line; StringBuilder multiLineQuery = null; - int error = 0; while ((line = reader.readLine()) != null) { int count = count(line, '\''); if (multiLineQuery != null) { @@ -171,7 +176,6 @@ public class ImportBackupService extends Service { } } } - Log.d(Config.LOGTAG, "done reading file"); final Jid jid = backupFileHeader.getJid(); Cursor countCursor = db.rawQuery("select count(messages.uuid) from messages join conversations on conversations.uuid=messages.conversationUuid join accounts on conversations.accountUuid=accounts.uuid where accounts.username=? and accounts.server=?", new String[]{jid.getEscapedLocal(), jid.getDomain()}); countCursor.moveToFirst(); diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 233b14d53..152662708 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -917,11 +917,11 @@ public class DatabaseBackend extends SQLiteOpenHelper { return getAccounts(db); } - public List getAccountJids() { + public List getAccountJids(final boolean enabledOnly) { SQLiteDatabase db = this.getReadableDatabase(); final List jids = new ArrayList<>(); final String[] columns = new String[]{Account.USERNAME, Account.SERVER}; - String where = "not options & (1 <<1)"; + String where = enabledOnly ? "not options & (1 <<1)" : null; Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null); try { while (cursor.moveToNext()) { diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index d2f44ffb2..95f179ceb 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -85,7 +85,7 @@ public class UriHandlerActivity extends AppCompatActivity { private void handleUri(Uri uri, final boolean scanned) { final Intent intent; final XmppUri xmppUri = new XmppUri(uri); - final List accounts = DatabaseBackend.getInstance(this).getAccountJids(); //TODO only look at enabled accounts + final List accounts = DatabaseBackend.getInstance(this).getAccountJids(true); if (accounts.size() == 0) { if (xmppUri.isJidValid()) {