forked from upstream-mirrors/quik
#965 - Add ability to pin conversations
This commit is contained in:
@@ -26,7 +26,7 @@ import io.realm.RealmMigration
|
||||
class QkRealmMigration : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SCHEMA_VERSION: Long = 4
|
||||
const val SCHEMA_VERSION: Long = 5
|
||||
}
|
||||
|
||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||
@@ -66,6 +66,13 @@ class QkRealmMigration : RealmMigration {
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 4L) {
|
||||
realm.schema.get("Conversation")
|
||||
?.addField("pinned", Boolean::class.java, FieldAttribute.REQUIRED, FieldAttribute.INDEXED)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version < newVersion) {
|
||||
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.equalTo("archived", archived)
|
||||
.equalTo("blocked", false)
|
||||
.isNotEmpty("recipients")
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.sort("pinned", Sort.DESCENDING, "date", Sort.DESCENDING)
|
||||
.findAllAsync()
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.equalTo("archived", false)
|
||||
.equalTo("blocked", false)
|
||||
.isNotEmpty("recipients")
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.sort("pinned", Sort.DESCENDING, "date", Sort.DESCENDING)
|
||||
.findAll())
|
||||
}
|
||||
|
||||
@@ -206,6 +206,30 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun markPinned(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.pinned = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markUnpinned(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
.anyOf("id", threadIds)
|
||||
.findAll()
|
||||
|
||||
realm.executeTransaction {
|
||||
conversations.forEach { it.pinned = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun markBlocked(vararg threadIds: Long) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val conversations = realm.where(Conversation::class.java)
|
||||
|
||||
Reference in New Issue
Block a user