Don't show encryption attachments as attachments

This commit is contained in:
M66B 2020-01-22 09:02:59 +01:00
parent 168ec03b5e
commit f93fe15775
2 changed files with 2118 additions and 7 deletions

File diff suppressed because it is too large Load Diff

View File

@ -58,7 +58,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 133, version = 134,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -174,16 +174,28 @@ public abstract class DB extends RoomDatabase {
public void onOpen(@NonNull SupportSQLiteDatabase db) { public void onOpen(@NonNull SupportSQLiteDatabase db) {
Log.i("Database version=" + db.getVersion()); Log.i("Database version=" + db.getVersion());
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" + createTriggers(db);
" AFTER INSERT ON attachment" +
" BEGIN UPDATE message SET attachments = attachments + 1 WHERE message.id = NEW.message; 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; END");
} }
}); });
} }
private static void createTriggers(@NonNull SupportSQLiteDatabase db) {
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.encryption IS NULL OR NEW.encryption = 0);" +
" 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.encryption IS NULL OR OLD.encryption = 0);" +
" END");
}
private static RoomDatabase.Builder<DB> migrate(final Context context, RoomDatabase.Builder<DB> builder) { private static RoomDatabase.Builder<DB> migrate(final Context context, RoomDatabase.Builder<DB> builder) {
// https://www.sqlite.org/lang_altertable.html // https://www.sqlite.org/lang_altertable.html
return builder return builder
@ -1280,6 +1292,15 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `account` ADD COLUMN `leave_on_device` INTEGER NOT NULL DEFAULT 0"); db.execSQL("ALTER TABLE `account` ADD COLUMN `leave_on_device` INTEGER NOT NULL DEFAULT 0");
db.execSQL("UPDATE `account` SET `leave_on_server` = `browse` WHERE `pop` = " + EntityAccount.TYPE_POP); db.execSQL("UPDATE `account` SET `leave_on_server` = `browse` WHERE `pop` = " + EntityAccount.TYPE_POP);
} }
})
.addMigrations(new Migration(133, 134) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("DROP TRIGGER attachment_insert");
db.execSQL("DROP TRIGGER attachment_delete");
createTriggers(db);
}
}); });
} }