From f963e51de197f15a90c05c2de62178dcf42710cd Mon Sep 17 00:00:00 2001 From: Julius Linus Date: Mon, 11 Dec 2023 11:10:01 -0600 Subject: [PATCH] - Fixed bug with Room Overwriting old data Signed-off-by: Julius Linus --- .../9.json | 11 ++++++----- .../talk/arbitrarystorage/ArbitraryStorageManager.kt | 2 +- .../talk/conversationinfo/ConversationInfoActivity.kt | 2 +- .../nextcloud/talk/data/source/local/TalkDatabase.kt | 4 ++-- .../data/storage/ArbitraryStoragesRepositoryImpl.kt | 4 +++- .../talk/data/storage/model/ArbitraryStorage.kt | 2 +- .../talk/data/storage/model/ArbitraryStorageEntity.kt | 4 ++-- .../preferencestorage/DatabaseStorageModule.java | 6 ++++++ 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/9.json b/app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/9.json index 4b966b37e75..fc519c41c8f 100644 --- a/app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/9.json +++ b/app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/9.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 9, - "identityHash": "666fcc4bbbdf3ff121b8f1ace8fcbcb8", + "identityHash": "250a3a56f3943f0d72f7ca0aac08fd1e", "entities": [ { "tableName": "User", @@ -92,7 +92,7 @@ }, { "tableName": "ArbitraryStorage", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountIdentifier` INTEGER NOT NULL, `key` TEXT NOT NULL, `object` TEXT, `value` TEXT, PRIMARY KEY(`accountIdentifier`, `key`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountIdentifier` INTEGER NOT NULL, `key` TEXT NOT NULL, `object` TEXT NOT NULL, `value` TEXT, PRIMARY KEY(`accountIdentifier`, `key`, `object`))", "fields": [ { "fieldPath": "accountIdentifier", @@ -110,7 +110,7 @@ "fieldPath": "storageObject", "columnName": "object", "affinity": "TEXT", - "notNull": false + "notNull": true }, { "fieldPath": "value", @@ -123,7 +123,8 @@ "autoGenerate": false, "columnNames": [ "accountIdentifier", - "key" + "key", + "object" ] }, "indices": [], @@ -133,7 +134,7 @@ "views": [], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '666fcc4bbbdf3ff121b8f1ace8fcbcb8')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '250a3a56f3943f0d72f7ca0aac08fd1e')" ] } } \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/arbitrarystorage/ArbitraryStorageManager.kt b/app/src/main/java/com/nextcloud/talk/arbitrarystorage/ArbitraryStorageManager.kt index 27c2550e0ea..dee554bf5b8 100644 --- a/app/src/main/java/com/nextcloud/talk/arbitrarystorage/ArbitraryStorageManager.kt +++ b/app/src/main/java/com/nextcloud/talk/arbitrarystorage/ArbitraryStorageManager.kt @@ -25,7 +25,7 @@ import com.nextcloud.talk.data.storage.model.ArbitraryStorage import io.reactivex.Maybe class ArbitraryStorageManager(private val arbitraryStoragesRepository: ArbitraryStoragesRepository) { - fun storeStorageSetting(accountIdentifier: Long, key: String, value: String?, objectString: String?) { + fun storeStorageSetting(accountIdentifier: Long, key: String, value: String?, objectString: String) { arbitraryStoragesRepository.saveArbitraryStorage(ArbitraryStorage(accountIdentifier, key, objectString, value)) } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index e04bd2ac6f6..e4377dacf3d 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -166,10 +166,10 @@ class ConversationInfoActivity : override fun onResume() { super.onResume() - if (databaseStorageModule == null) { databaseStorageModule = DatabaseStorageModule(conversationUser, conversationToken) } + Log.d("Julius", "DatabaseModule is $databaseStorageModule") setUpNotificationSettings(databaseStorageModule!!) binding.deleteConversationAction.setOnClickListener { showDeleteConversationDialog() } binding.leaveConversationAction.setOnClickListener { leaveConversation() } diff --git a/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt b/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt index 65eb7ee5fe9..3e165991530 100644 --- a/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt +++ b/app/src/main/java/com/nextcloud/talk/data/source/local/TalkDatabase.kt @@ -94,8 +94,8 @@ abstract class TalkDatabase : RoomDatabase() { return Room .databaseBuilder(context.applicationContext, TalkDatabase::class.java, dbName) - // comment out openHelperFactory to view the database entries in Android Studio for debugging - .openHelperFactory(factory) + // NOTE: comment out openHelperFactory to view the database entries in Android Studio for debugging + // .openHelperFactory(factory) .addMigrations(Migrations.MIGRATION_6_8, Migrations.MIGRATION_7_8, Migrations.MIGRATION_8_9) .allowMainThreadQueries() .addCallback( diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt index 6eb07cf7614..558fa5ab2bc 100644 --- a/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/data/storage/ArbitraryStoragesRepositoryImpl.kt @@ -33,7 +33,9 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar ): Maybe { return arbitraryStoragesDao .getStorageSetting(accountIdentifier, key, objectString) - .map { ArbitraryStorageMapper.toModel(it) } + .map { + ArbitraryStorageMapper.toModel(it) + } } override fun getAll(): Maybe> { diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt b/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt index 56b93b38b45..7f2f4ae5695 100644 --- a/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt +++ b/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorage.kt @@ -27,6 +27,6 @@ import kotlinx.parcelize.Parcelize data class ArbitraryStorage( var accountIdentifier: Long, var key: String, - var storageObject: String? = null, + var storageObject: String, var value: String? = null ) : Parcelable diff --git a/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorageEntity.kt b/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorageEntity.kt index ab5f7dc6261..b54c3dc39cb 100644 --- a/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorageEntity.kt +++ b/app/src/main/java/com/nextcloud/talk/data/storage/model/ArbitraryStorageEntity.kt @@ -26,7 +26,7 @@ import androidx.room.Entity import kotlinx.parcelize.Parcelize @Parcelize -@Entity(tableName = "ArbitraryStorage", primaryKeys = ["accountIdentifier", "key"]) +@Entity(tableName = "ArbitraryStorage", primaryKeys = ["accountIdentifier", "key", "object"]) data class ArbitraryStorageEntity( @ColumnInfo(name = "accountIdentifier") var accountIdentifier: Long = 0, @@ -35,7 +35,7 @@ data class ArbitraryStorageEntity( var key: String = "", @ColumnInfo(name = "object") - var storageObject: String? = null, + var storageObject: String = "", @ColumnInfo(name = "value") var value: String? = null diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java index cc4365c55bc..a93fa829108 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/preferencestorage/DatabaseStorageModule.java @@ -251,4 +251,10 @@ public String getString(String key, String defaultVal) { public void setMessageExpiration(int messageExpiration) { this.messageExpiration = messageExpiration; } + + @androidx.annotation.NonNull + public String toString() { + return "Conversation token: " + conversationToken + + "\nAccount Number: " + accountIdentifier; + } }