Add a deduplicate message feature

- Adds a new class of features for message management.
- Adds a manual option to find and delete duplicate messages
- Adds a setting to automatically delete duplicates during sync
- Adds a sha256 hashing function

Co-authored-by: octoshrimpy <octoshrimpy@users.noreply.github.com>
This commit is contained in:
Inhishonor
2026-01-10 13:34:37 -08:00
parent b4bce2c1a9
commit c1d824abbc
24 changed files with 539 additions and 3 deletions
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 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 dev.octoshrimpy.quik.interactor
import dev.octoshrimpy.quik.repository.MessageRepository
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class DeduplicateMessages @Inject constructor(
private val messageRepo: MessageRepository
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<MessageRepository.DeduplicationResult> =
messageRepo.deduplicateMessages()
.subscribeOn(Schedulers.io())
}
@@ -22,9 +22,24 @@ import android.net.Uri
import dev.octoshrimpy.quik.model.Attachment
import dev.octoshrimpy.quik.model.Message
import dev.octoshrimpy.quik.model.MmsPart
import io.reactivex.Flowable
import io.reactivex.Observable
import io.realm.RealmResults
interface MessageRepository {
sealed class DeduplicationProgress {
object Idle : DeduplicationProgress()
data class Running(val max: Int, val progress: Int, val indeterminate: Boolean) : DeduplicationProgress()
}
sealed class DeduplicationResult {
object Success : DeduplicationResult()
object NoDuplicates : DeduplicationResult()
data class Failure(val error: Throwable) : DeduplicationResult()
}
val deduplicationProgress: Observable<DeduplicationProgress>
fun getMessages(threadId: Long, query: String = ""): RealmResults<Message>
fun getMessagesSync(threadId: Long, query: String = ""): RealmResults<Message>
@@ -88,5 +103,7 @@ interface MessageRepository {
fun deleteOldMessages(maxAgeDays: Int)
fun deduplicateMessages(): Flowable<DeduplicationResult>
fun markAsSendingNow(messageId: Long)
}
@@ -136,6 +136,8 @@ class Preferences @Inject constructor(
val logging = rxPrefs.getBoolean("logging", false)
val unreadAtTop = rxPrefs.getBoolean("unreadAtTop", false)
val autoDeduplicate = rxPrefs.getBoolean("autoDeduplicateMessages", false)
init {
// Migrate from old night mode preference to new one, now that we support android Q night mode
val nightModeSummary = rxPrefs.getInteger("nightModeSummary")