#965 - Add ability to pin conversations

This commit is contained in:
Moez Bhatti
2018-07-23 14:37:42 -04:00
parent fbd7c7b3a1
commit cb62bcee1d
15 changed files with 215 additions and 31 deletions
@@ -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)