forked from upstream-mirrors/quik
Indicate in UI when scheduled messages are present
Added a new property to scheduled messages to save which conversation the scheduled message belongs to.
This commit is contained in:
@@ -36,7 +36,7 @@ class QkRealmMigration @Inject constructor(
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SchemaVersion: Long = 11
|
||||
const val SchemaVersion: Long = 12
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@@ -233,6 +233,14 @@ class QkRealmMigration @Inject constructor(
|
||||
|
||||
version++
|
||||
}
|
||||
if (version == 11L) {
|
||||
realm.schema.get("ScheduledMessage")
|
||||
?.addField("conversationId", Long::class.java, FieldAttribute.REQUIRED)
|
||||
// Because there was never any property associated with which conversation/recipients a scheduled message was for,
|
||||
// we can't update this field on a realm migration. It will be set to a default of 0
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
check(version >= newVersion) { "Migration missing from v$oldVersion to v$newVersion" }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
recipients: List<String>,
|
||||
sendAsGroup: Boolean,
|
||||
body: String,
|
||||
attachments: List<String>
|
||||
attachments: List<String>,
|
||||
conversationId: Long
|
||||
): ScheduledMessage {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val id = (realm
|
||||
@@ -34,7 +35,7 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
val attachmentsRealmList = RealmList(*attachments.toTypedArray())
|
||||
|
||||
val message = ScheduledMessage(id, date, subId, recipientsRealmList, sendAsGroup, body,
|
||||
attachmentsRealmList)
|
||||
attachmentsRealmList, conversationId)
|
||||
|
||||
realm.executeTransaction { realm.insertOrUpdate(message) }
|
||||
|
||||
@@ -63,6 +64,13 @@ class ScheduledMessageRepositoryImpl @Inject constructor() : ScheduledMessageRep
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
override fun getScheduledMessagesForConversation(conversationId: Long): RealmResults<ScheduledMessage> {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(ScheduledMessage::class.java)
|
||||
.equalTo("conversationId", conversationId)
|
||||
.findAllAsync()
|
||||
}
|
||||
|
||||
override fun deleteScheduledMessage(id: Long) {
|
||||
val subscription = Completable.fromAction {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
|
||||
Reference in New Issue
Block a user