mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 14:46:31 +02:00
Improved attachment recognition
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -61,7 +62,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 170,
|
||||
version = 171,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -275,27 +276,39 @@ public abstract class DB extends RoomDatabase {
|
||||
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("Database version=" + db.getVersion());
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
|
||||
}
|
||||
createTriggers(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void createTriggers(@NonNull SupportSQLiteDatabase db) {
|
||||
List<String> image = new ArrayList<>();
|
||||
for (String img : EntityAttachment.IMAGE_TYPES)
|
||||
image.add("'" + img + "'");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
for (String img : EntityAttachment.IMAGE_TYPES8)
|
||||
image.add("'" + img + "'");
|
||||
String images = TextUtils.join(",", image);
|
||||
|
||||
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" +
|
||||
" AFTER INSERT ON attachment" +
|
||||
" BEGIN" +
|
||||
" UPDATE message SET attachments = attachments + 1" +
|
||||
" WHERE message.id = NEW.message" +
|
||||
" AND (NEW.disposition IS NULL OR NEW.disposition <> 'inline')" +
|
||||
" AND (NEW.encryption IS NULL OR NEW.encryption = 0);" +
|
||||
" AND (NEW.encryption IS NULL" +
|
||||
" AND NOT ((NEW.disposition = 'inline' OR NEW.cid IS NOT NULL) AND NEW.type IN (" + images + ")));" +
|
||||
" END");
|
||||
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
||||
" AFTER DELETE ON attachment" +
|
||||
" BEGIN" +
|
||||
" UPDATE message SET attachments = attachments - 1" +
|
||||
" WHERE message.id = OLD.message" +
|
||||
" AND (OLD.disposition IS NULL OR OLD.disposition <> 'inline')" +
|
||||
" AND (OLD.encryption IS NULL OR OLD.encryption = 0);" +
|
||||
" AND (OLD.encryption IS NULL" +
|
||||
" AND NOT ((OLD.disposition = 'inline' OR OLD.cid IS NOT NULL) AND OLD.type IN (" + images + ")));" +
|
||||
" END");
|
||||
}
|
||||
|
||||
@@ -1670,6 +1683,15 @@ public abstract class DB extends RoomDatabase {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `account` ADD COLUMN `max_size` INTEGER");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(170, 171) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
|
||||
createTriggers(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user