-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate blocked conversations to qk blocking manager
- Loading branch information
1 parent
3aba928
commit 4c9130e
Showing
8 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
data/src/main/java/com/moez/QKSMS/migration/QkMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com> | ||
* | ||
* This file is part of QKSMS. | ||
* | ||
* QKSMS is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* QKSMS is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.moez.QKSMS.migration | ||
|
||
import android.content.Context | ||
import com.moez.QKSMS.blocking.QksmsBlockingClient | ||
import com.moez.QKSMS.repository.ConversationRepository | ||
import com.moez.QKSMS.util.Preferences | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
class QkMigration @Inject constructor( | ||
context: Context, | ||
private val conversationRepo: ConversationRepository, | ||
private val prefs: Preferences, | ||
private val qksmsBlockingClient: QksmsBlockingClient | ||
) { | ||
|
||
init { | ||
val oldVersion = prefs.version.get() | ||
val newVersion = context.packageManager.getPackageInfo(context.packageName, 0).versionCode | ||
|
||
if (oldVersion < 2199) { | ||
upgradeTo370() | ||
} | ||
|
||
prefs.changelogVersion.set(newVersion) | ||
} | ||
|
||
private fun upgradeTo370() = GlobalScope.launch { | ||
// Migrate changelog version | ||
prefs.changelogVersion.set(prefs.version.get()) | ||
|
||
// Migrate from old SIA preference to blocking manager preference | ||
if (prefs.sia.get()) { | ||
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_SIA) | ||
prefs.sia.delete() | ||
} | ||
|
||
// Migrate blocked conversations into QK blocking client | ||
val addresses = conversationRepo.getBlockedConversations() | ||
.flatMap { conversation -> conversation.recipients } | ||
.map { recipient -> recipient.address } | ||
.distinct() | ||
|
||
qksmsBlockingClient.block(addresses).blockingAwait() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters