|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
@ -61,7 +62,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 = 170,
|
|
|
|
version = 171,
|
|
|
|
entities = {
|
|
|
|
entities = {
|
|
|
|
EntityIdentity.class,
|
|
|
|
EntityIdentity.class,
|
|
|
|
EntityAccount.class,
|
|
|
|
EntityAccount.class,
|
|
|
@ -275,27 +276,39 @@ 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());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
|
|
|
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
|
|
|
|
|
|
|
|
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
|
|
|
|
|
|
|
|
}
|
|
|
|
createTriggers(db);
|
|
|
|
createTriggers(db);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void createTriggers(@NonNull SupportSQLiteDatabase 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" +
|
|
|
|
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" +
|
|
|
|
" AFTER INSERT ON attachment" +
|
|
|
|
" AFTER INSERT ON attachment" +
|
|
|
|
" BEGIN" +
|
|
|
|
" BEGIN" +
|
|
|
|
" UPDATE message SET attachments = attachments + 1" +
|
|
|
|
" UPDATE message SET attachments = attachments + 1" +
|
|
|
|
" WHERE message.id = NEW.message" +
|
|
|
|
" WHERE message.id = NEW.message" +
|
|
|
|
" AND (NEW.disposition IS NULL OR NEW.disposition <> 'inline')" +
|
|
|
|
" AND (NEW.encryption IS NULL" +
|
|
|
|
" AND (NEW.encryption IS NULL OR NEW.encryption = 0);" +
|
|
|
|
" AND NOT ((NEW.disposition = 'inline' OR NEW.cid IS NOT NULL) AND NEW.type IN (" + images + ")));" +
|
|
|
|
" END");
|
|
|
|
" END");
|
|
|
|
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
|
|
|
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
|
|
|
" AFTER DELETE ON attachment" +
|
|
|
|
" AFTER DELETE ON attachment" +
|
|
|
|
" BEGIN" +
|
|
|
|
" BEGIN" +
|
|
|
|
" UPDATE message SET attachments = attachments - 1" +
|
|
|
|
" UPDATE message SET attachments = attachments - 1" +
|
|
|
|
" WHERE message.id = OLD.message" +
|
|
|
|
" WHERE message.id = OLD.message" +
|
|
|
|
" AND (OLD.disposition IS NULL OR OLD.disposition <> 'inline')" +
|
|
|
|
" AND (OLD.encryption IS NULL" +
|
|
|
|
" AND (OLD.encryption IS NULL OR OLD.encryption = 0);" +
|
|
|
|
" AND NOT ((OLD.disposition = 'inline' OR OLD.cid IS NOT NULL) AND OLD.type IN (" + images + ")));" +
|
|
|
|
" END");
|
|
|
|
" END");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1670,6 +1683,15 @@ public abstract class DB extends RoomDatabase {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `max_size` INTEGER");
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|