forked from upstream-mirrors/quik
Migrate blocked preferences from 2.7.3
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.ContentUris
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import android.telephony.PhoneNumberUtils
|
import android.telephony.PhoneNumberUtils
|
||||||
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import mapper.CursorToContact
|
import mapper.CursorToContact
|
||||||
import mapper.CursorToConversation
|
import mapper.CursorToConversation
|
||||||
@@ -48,7 +49,8 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
private val cursorToConversation: CursorToConversation,
|
private val cursorToConversation: CursorToConversation,
|
||||||
private val cursorToMessage: CursorToMessage,
|
private val cursorToMessage: CursorToMessage,
|
||||||
private val cursorToRecipient: CursorToRecipient,
|
private val cursorToRecipient: CursorToRecipient,
|
||||||
private val cursorToContact: CursorToContact
|
private val cursorToContact: CursorToContact,
|
||||||
|
private val rxPrefs: RxSharedPreferences
|
||||||
) : SyncRepository {
|
) : SyncRepository {
|
||||||
|
|
||||||
sealed class Status {
|
sealed class Status {
|
||||||
@@ -72,10 +74,10 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
realm.beginTransaction()
|
realm.beginTransaction()
|
||||||
|
|
||||||
var persistedData: List<PersistedData>? = null
|
var persistedData: List<PersistedData> = listOf()
|
||||||
|
|
||||||
if (fullSync) {
|
if (fullSync) {
|
||||||
persistedData = realm.where(Conversation::class.java)
|
persistedData += realm.where(Conversation::class.java)
|
||||||
.beginGroup()
|
.beginGroup()
|
||||||
.equalTo("archived", true)
|
.equalTo("archived", true)
|
||||||
.or()
|
.or()
|
||||||
@@ -106,13 +108,19 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
realm.insertOrUpdate(messages)
|
realm.insertOrUpdate(messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate blocked conversations from 2.7.3
|
||||||
|
val oldBlockedSenders = rxPrefs.getStringSet("pref_key_blocked_senders")
|
||||||
|
persistedData += oldBlockedSenders.get()
|
||||||
|
.map { threadIdString -> threadIdString.toLong() }
|
||||||
|
.filter { threadId -> persistedData.none { it.id == threadId } }
|
||||||
|
.map { threadId -> PersistedData(threadId, false, true) }
|
||||||
|
|
||||||
// Sync conversations
|
// Sync conversations
|
||||||
cursorToConversation.getConversationsCursor()?.use { conversationCursor ->
|
cursorToConversation.getConversationsCursor()?.use { conversationCursor ->
|
||||||
val conversations = conversationCursor
|
val conversations = conversationCursor
|
||||||
.map { cursor -> cursorToConversation.map(cursor) }
|
.map { cursor -> cursorToConversation.map(cursor) }
|
||||||
|
|
||||||
persistedData?.forEach { data ->
|
persistedData.forEach { data ->
|
||||||
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
|
||||||
@@ -131,6 +139,9 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
realm.commitTransaction()
|
realm.commitTransaction()
|
||||||
realm.close()
|
realm.close()
|
||||||
|
|
||||||
|
// Only delete this after the sync has successfully completed
|
||||||
|
oldBlockedSenders.delete()
|
||||||
|
|
||||||
syncContacts()
|
syncContacts()
|
||||||
|
|
||||||
status = Status.Idle()
|
status = Status.Idle()
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* When upgrading from 2.7.3 to 3.0, migrate the preferences
|
* When upgrading from 2.7.3 to 3.0, migrate the preferences
|
||||||
|
*
|
||||||
|
* Blocked conversations will be migrated in SyncManager
|
||||||
*/
|
*/
|
||||||
class MigratePreferences @Inject constructor(
|
class MigratePreferences @Inject constructor(
|
||||||
private val nightModeManager: NightModeManager,
|
private val nightModeManager: NightModeManager,
|
||||||
|
|||||||
Reference in New Issue
Block a user