forked from upstream-mirrors/quik
Stricter check for phone number equality
This commit is contained in:
@@ -18,20 +18,22 @@
|
||||
*/
|
||||
package com.moez.QKSMS.repository
|
||||
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.moez.QKSMS.extensions.anyOf
|
||||
import com.moez.QKSMS.model.BlockedNumber
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
import javax.inject.Inject
|
||||
|
||||
class BlockingRepositoryImpl @Inject constructor() : BlockingRepository {
|
||||
class BlockingRepositoryImpl @Inject constructor(
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : BlockingRepository {
|
||||
|
||||
override fun blockNumber(vararg addresses: String) {
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
val blockedNumbers = realm.where(BlockedNumber::class.java).findAll()
|
||||
val newAddresses = addresses.filter { address ->
|
||||
blockedNumbers.none { number -> PhoneNumberUtils.compare(number.address, address) }
|
||||
blockedNumbers.none { number -> phoneNumberUtils.compare(number.address, address) }
|
||||
}
|
||||
|
||||
val maxId = realm.where(BlockedNumber::class.java)
|
||||
@@ -60,7 +62,7 @@ class BlockingRepositoryImpl @Inject constructor() : BlockingRepository {
|
||||
return Realm.getDefaultInstance().use { realm ->
|
||||
realm.where(BlockedNumber::class.java)
|
||||
.findAll()
|
||||
.any { number -> PhoneNumberUtils.compare(number.address, address) }
|
||||
.any { number -> phoneNumberUtils.compare(number.address, address) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +82,7 @@ class BlockingRepositoryImpl @Inject constructor() : BlockingRepository {
|
||||
val ids = realm.where(BlockedNumber::class.java)
|
||||
.findAll()
|
||||
.filter { number ->
|
||||
addresses.any { address -> PhoneNumberUtils.compare(number.address, address) }
|
||||
addresses.any { address -> phoneNumberUtils.compare(number.address, address) }
|
||||
}
|
||||
.map { number -> number.id }
|
||||
.toLongArray()
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.moez.QKSMS.repository
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.provider.Telephony
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.moez.QKSMS.compat.TelephonyCompat
|
||||
import com.moez.QKSMS.extensions.anyOf
|
||||
import com.moez.QKSMS.extensions.map
|
||||
@@ -34,6 +33,7 @@ import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.model.SearchResult
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.realm.Case
|
||||
import io.realm.Realm
|
||||
@@ -46,7 +46,8 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val conversationFilter: ConversationFilter,
|
||||
private val cursorToConversation: CursorToConversation,
|
||||
private val cursorToRecipient: CursorToRecipient
|
||||
private val cursorToRecipient: CursorToRecipient,
|
||||
private val phoneNumberUtils: PhoneNumberUtils
|
||||
) : ConversationRepository {
|
||||
|
||||
override fun getConversations(archived: Boolean): RealmResults<Conversation> {
|
||||
@@ -179,7 +180,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.findAll()
|
||||
.firstOrNull { conversation ->
|
||||
conversation.recipients.size == recipients.size && conversation.recipients.map { it.address }.all { address ->
|
||||
recipients.any { recipient -> PhoneNumberUtils.compare(recipient, address) }
|
||||
recipients.any { recipient -> phoneNumberUtils.compare(recipient, address) }
|
||||
}
|
||||
}
|
||||
?.id
|
||||
@@ -363,7 +364,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.map { recipient ->
|
||||
recipient.apply {
|
||||
contact = contacts.firstOrNull {
|
||||
it.numbers.any { PhoneNumberUtils.compare(recipient.address, it.address) }
|
||||
it.numbers.any { phoneNumberUtils.compare(recipient.address, it.address) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import android.provider.Telephony
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.telephony.SmsManager
|
||||
import androidx.core.content.contentValuesOf
|
||||
import com.google.android.mms.ContentType
|
||||
@@ -47,6 +46,7 @@ import com.moez.QKSMS.receiver.SendSmsReceiver
|
||||
import com.moez.QKSMS.receiver.SmsDeliveredReceiver
|
||||
import com.moez.QKSMS.receiver.SmsSentReceiver
|
||||
import com.moez.QKSMS.util.ImageUtils
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.realm.Case
|
||||
@@ -61,8 +61,9 @@ import javax.inject.Singleton
|
||||
class MessageRepositoryImpl @Inject constructor(
|
||||
private val activeConversationManager: ActiveConversationManager,
|
||||
private val context: Context,
|
||||
private val messageIds: KeyManager,
|
||||
private val imageRepository: ImageRepository,
|
||||
private val messageIds: KeyManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences,
|
||||
private val syncRepository: SyncRepository
|
||||
) : MessageRepository {
|
||||
@@ -290,7 +291,7 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.map { vCard -> MMSPart("contact", ContentType.TEXT_VCARD, vCard) }
|
||||
|
||||
val transaction = Transaction(context)
|
||||
transaction.sendNewMessage(subId, threadId, addresses.map(PhoneNumberUtils::stripSeparators), parts, null)
|
||||
transaction.sendNewMessage(subId, threadId, addresses.map(phoneNumberUtils::normalizeNumber), parts, null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.content.ContentResolver
|
||||
import android.content.ContentUris
|
||||
import android.net.Uri
|
||||
import android.provider.Telephony
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import com.moez.QKSMS.extensions.insertOrUpdate
|
||||
import com.moez.QKSMS.extensions.map
|
||||
@@ -37,6 +36,7 @@ import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.model.SyncLog
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
@@ -54,6 +54,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
private val cursorToRecipient: CursorToRecipient,
|
||||
private val cursorToContact: CursorToContact,
|
||||
private val keys: KeyManager,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val rxPrefs: RxSharedPreferences
|
||||
) : SyncRepository {
|
||||
|
||||
@@ -170,7 +171,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||
cursorToRecipient.map(cursor).apply {
|
||||
contact = contacts.firstOrNull { contact ->
|
||||
contact.numbers.any { PhoneNumberUtils.compare(address, it.address) }
|
||||
contact.numbers.any { phoneNumberUtils.compare(address, it.address) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,7 +251,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
val updatedRecipients = recipients.map { recipient ->
|
||||
recipient.apply {
|
||||
contact = contacts.firstOrNull {
|
||||
it.numbers.any { PhoneNumberUtils.compare(recipient.address, it.address) }
|
||||
it.numbers.any { phoneNumberUtils.compare(recipient.address, it.address) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +265,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
override fun syncContact(address: String): Boolean {
|
||||
// See if there's a contact that matches this phone number
|
||||
var contact = getContacts().firstOrNull {
|
||||
it.numbers.any { number -> PhoneNumberUtils.compare(number.address, address) }
|
||||
it.numbers.any { number -> phoneNumberUtils.compare(number.address, address) }
|
||||
} ?: return false
|
||||
|
||||
Realm.getDefaultInstance().use { realm ->
|
||||
@@ -277,7 +278,7 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
val updatedRecipients = recipients
|
||||
.filter { recipient ->
|
||||
contact.numbers.any { number ->
|
||||
PhoneNumberUtils.compare(recipient.address, number.address)
|
||||
phoneNumberUtils.compare(recipient.address, number.address)
|
||||
}
|
||||
}
|
||||
.map { recipient -> recipient.apply { this.contact = contact } }
|
||||
|
||||
Reference in New Issue
Block a user