Persist pinned status across message sync

This commit is contained in:
Moez Bhatti
2018-07-24 14:51:23 -04:00
parent e88d6d5a5a
commit dbbb7ffcdf
@@ -48,7 +48,6 @@ import javax.inject.Singleton
class SyncRepositoryImpl @Inject constructor( class SyncRepositoryImpl @Inject constructor(
private val contentResolver: ContentResolver, private val contentResolver: ContentResolver,
private val conversationRepo: ConversationRepository, private val conversationRepo: ConversationRepository,
private val messageRepo: MessageRepository,
private val cursorToConversation: CursorToConversation, private val cursorToConversation: CursorToConversation,
private val cursorToMessage: CursorToMessage, private val cursorToMessage: CursorToMessage,
private val cursorToRecipient: CursorToRecipient, private val cursorToRecipient: CursorToRecipient,
@@ -64,6 +63,7 @@ class SyncRepositoryImpl @Inject constructor(
val id: Long, val id: Long,
val archived: Boolean, val archived: Boolean,
val blocked: Boolean, val blocked: Boolean,
val pinned: Boolean,
val name: String) val name: String)
override val syncProgress: Subject<SyncRepository.SyncProgress> = BehaviorSubject.createDefault(SyncRepository.SyncProgress.Idle()) override val syncProgress: Subject<SyncRepository.SyncProgress> = BehaviorSubject.createDefault(SyncRepository.SyncProgress.Idle())
@@ -83,10 +83,12 @@ class SyncRepositoryImpl @Inject constructor(
.or() .or()
.equalTo("blocked", true) .equalTo("blocked", true)
.or() .or()
.equalTo("pinned", true)
.or()
.isNotEmpty("name") .isNotEmpty("name")
.endGroup() .endGroup()
.findAll() .findAll()
.map { PersistedData(it.id, it.archived, it.blocked, it.name) } .map { PersistedData(it.id, it.archived, it.blocked, it.pinned, it.name) }
realm.delete(Contact::class.java) realm.delete(Contact::class.java)
realm.delete(Conversation::class.java) realm.delete(Conversation::class.java)
@@ -109,7 +111,7 @@ class SyncRepositoryImpl @Inject constructor(
persistedData += oldBlockedSenders.get() persistedData += oldBlockedSenders.get()
.map { threadIdString -> threadIdString.toLong() } .map { threadIdString -> threadIdString.toLong() }
.filter { threadId -> persistedData.none { it.id == threadId } } .filter { threadId -> persistedData.none { it.id == threadId } }
.map { threadId -> PersistedData(threadId, false, true, "") } .map { threadId -> PersistedData(threadId, false, true, false, "") }
// Sync conversations // Sync conversations
cursorToConversation.getConversationsCursor()?.use { conversationCursor -> cursorToConversation.getConversationsCursor()?.use { conversationCursor ->
@@ -120,6 +122,7 @@ class SyncRepositoryImpl @Inject constructor(
val conversation = conversations.firstOrNull { conversation -> conversation.id == data.id } val conversation = conversations.firstOrNull { conversation -> conversation.id == data.id }
conversation?.archived = data.archived conversation?.archived = data.archived
conversation?.blocked = data.blocked conversation?.blocked = data.blocked
conversation?.pinned = data.pinned
conversation?.name = data.name conversation?.name = data.name
} }