mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 00:28:33 +00:00
Fix improper deletion of stickers when restored from backup.
This commit is contained in:
parent
3b925f8674
commit
b8c7e86223
@ -156,7 +156,7 @@ public class FullBackupImporter extends FullBackupBase {
|
|||||||
private static void processSticker(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret, @NonNull SQLiteDatabase db, @NonNull Sticker sticker, BackupRecordInputStream inputStream)
|
private static void processSticker(@NonNull Context context, @NonNull AttachmentSecret attachmentSecret, @NonNull SQLiteDatabase db, @NonNull Sticker sticker, BackupRecordInputStream inputStream)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
File stickerDirectory = context.getDir(AttachmentDatabase.DIRECTORY, Context.MODE_PRIVATE);
|
File stickerDirectory = context.getDir(StickerDatabase.DIRECTORY, Context.MODE_PRIVATE);
|
||||||
File dataFile = File.createTempFile("sticker", ".mms", stickerDirectory);
|
File dataFile = File.createTempFile("sticker", ".mms", stickerDirectory);
|
||||||
|
|
||||||
Pair<byte[], OutputStream> output = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
|
Pair<byte[], OutputStream> output = ModernEncryptingPartOutputStream.createFor(attachmentSecret, dataFile, false);
|
||||||
|
@ -509,6 +509,8 @@ public class AttachmentDatabase extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filesInDb.addAll(DatabaseFactory.getStickerDatabase(context).getAllStickerFiles());
|
||||||
|
|
||||||
Set<String> onDiskButNotInDatabase = SetUtil.difference(filesOnDisk, filesInDb);
|
Set<String> onDiskButNotInDatabase = SetUtil.difference(filesOnDisk, filesInDb);
|
||||||
|
|
||||||
for (String filePath : onDiskButNotInDatabase) {
|
for (String filePath : onDiskButNotInDatabase) {
|
||||||
|
@ -3,12 +3,12 @@ package org.thoughtcrime.securesms.database;
|
|||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
|||||||
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
|
||||||
import org.thoughtcrime.securesms.stickers.BlessedPacks;
|
import org.thoughtcrime.securesms.stickers.BlessedPacks;
|
||||||
import org.thoughtcrime.securesms.stickers.StickerPackInstallEvent;
|
import org.thoughtcrime.securesms.stickers.StickerPackInstallEvent;
|
||||||
|
import org.thoughtcrime.securesms.util.CursorUtil;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@ -30,9 +31,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.util.HashSet;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class StickerDatabase extends Database {
|
public class StickerDatabase extends Database {
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ public class StickerDatabase extends Database {
|
|||||||
"CREATE INDEX IF NOT EXISTS sticker_sticker_id_index ON " + TABLE_NAME + " (" + STICKER_ID + ");"
|
"CREATE INDEX IF NOT EXISTS sticker_sticker_id_index ON " + TABLE_NAME + " (" + STICKER_ID + ");"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String DIRECTORY = "stickers";
|
public static final String DIRECTORY = "stickers";
|
||||||
|
|
||||||
private final AttachmentSecret attachmentSecret;
|
private final AttachmentSecret attachmentSecret;
|
||||||
|
|
||||||
@ -190,6 +191,19 @@ public class StickerDatabase extends Database {
|
|||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull Set<String> getAllStickerFiles() {
|
||||||
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
|
|
||||||
|
Set<String> files = new HashSet<>();
|
||||||
|
try (Cursor cursor = db.query(TABLE_NAME, new String[] { FILE_PATH }, null, null, null, null, null)) {
|
||||||
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
|
files.add(CursorUtil.requireString(cursor, FILE_PATH));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable InputStream getStickerStream(long rowId) throws IOException {
|
public @Nullable InputStream getStickerStream(long rowId) throws IOException {
|
||||||
String selection = _ID + " = ?";
|
String selection = _ID + " = ?";
|
||||||
String[] args = new String[] { String.valueOf(rowId) };
|
String[] args = new String[] { String.valueOf(rowId) };
|
||||||
|
@ -296,6 +296,10 @@ public class ThreadDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void trimThread(long threadId, int length, long trimBeforeDate) {
|
public void trimThread(long threadId, int length, long trimBeforeDate) {
|
||||||
|
if (length == NO_TRIM_MESSAGE_COUNT_SET && trimBeforeDate == NO_TRIM_BEFORE_DATE_SET) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
|
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
|
||||||
GroupReceiptDatabase groupReceiptDatabase = DatabaseFactory.getGroupReceiptDatabase(context);
|
GroupReceiptDatabase groupReceiptDatabase = DatabaseFactory.getGroupReceiptDatabase(context);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user