forked from upstream-mirrors/quik
#1200 - Fix new conversations failing to sync on Huawei devices
This commit is contained in:
@@ -75,9 +75,4 @@ class CursorToConversationImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversationCursor(threadId: Long): Cursor? {
|
|
||||||
return context.contentResolver.query(URI, PROJECTION,
|
|
||||||
"_id = ?", arrayOf(threadId.toString()), null)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -256,11 +256,10 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
* conversation unless it contains at least 1 message
|
* conversation unless it contains at least 1 message
|
||||||
*/
|
*/
|
||||||
private fun getConversationFromCp(threadId: Long): Conversation? {
|
private fun getConversationFromCp(threadId: Long): Conversation? {
|
||||||
return cursorToConversation.getConversationCursor(threadId)
|
return cursorToConversation.getConversationsCursor()
|
||||||
?.takeIf { cursor -> cursor.moveToFirst() }
|
?.map(cursorToConversation::map)
|
||||||
?.use { cursor ->
|
?.firstOrNull { it.id == threadId }
|
||||||
val conversation = cursorToConversation.map(cursor)
|
?.let { conversation ->
|
||||||
|
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val contacts = realm.copyFromRealm(realm.where(Contact::class.java).findAll())
|
val contacts = realm.copyFromRealm(realm.where(Contact::class.java).findAll())
|
||||||
|
|
||||||
|
|||||||
@@ -28,14 +28,18 @@ import android.graphics.Bitmap
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import android.telephony.SmsManager
|
import android.telephony.SmsManager
|
||||||
|
import androidx.core.content.contentValuesOf
|
||||||
import com.google.android.mms.ContentType
|
import com.google.android.mms.ContentType
|
||||||
import com.klinker.android.send_message.BroadcastUtils
|
import com.klinker.android.send_message.BroadcastUtils
|
||||||
import com.klinker.android.send_message.Settings
|
import com.klinker.android.send_message.Settings
|
||||||
import com.klinker.android.send_message.StripAccents
|
import com.klinker.android.send_message.StripAccents
|
||||||
import com.klinker.android.send_message.Transaction
|
import com.klinker.android.send_message.Transaction
|
||||||
|
import com.moez.QKSMS.compat.TelephonyCompat
|
||||||
import com.moez.QKSMS.extensions.anyOf
|
import com.moez.QKSMS.extensions.anyOf
|
||||||
import com.moez.QKSMS.extensions.insertOrUpdate
|
import com.moez.QKSMS.extensions.insertOrUpdate
|
||||||
|
import com.moez.QKSMS.extensions.map
|
||||||
import com.moez.QKSMS.manager.KeyManager
|
import com.moez.QKSMS.manager.KeyManager
|
||||||
|
import com.moez.QKSMS.mapper.CursorToConversation
|
||||||
import com.moez.QKSMS.model.Attachment
|
import com.moez.QKSMS.model.Attachment
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
import com.moez.QKSMS.model.Message
|
import com.moez.QKSMS.model.Message
|
||||||
@@ -54,7 +58,6 @@ import javax.inject.Singleton
|
|||||||
class MessageRepositoryImpl @Inject constructor(
|
class MessageRepositoryImpl @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val messageIds: KeyManager,
|
private val messageIds: KeyManager,
|
||||||
private val conversationRepo: ConversationRepository,
|
|
||||||
private val imageRepository: ImageRepository,
|
private val imageRepository: ImageRepository,
|
||||||
private val prefs: Preferences) : MessageRepository {
|
private val prefs: Preferences) : MessageRepository {
|
||||||
|
|
||||||
@@ -367,13 +370,12 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
override fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message {
|
override fun insertReceivedSms(subId: Int, address: String, body: String, sentTime: Long): Message {
|
||||||
|
|
||||||
// Insert the message to the native content provider
|
// Insert the message to the native content provider
|
||||||
val values = ContentValues().apply {
|
val uri = contentValuesOf(
|
||||||
put(Telephony.Sms.ADDRESS, address)
|
Pair(Telephony.Sms.ADDRESS, address),
|
||||||
put(Telephony.Sms.BODY, body)
|
Pair(Telephony.Sms.BODY, body),
|
||||||
put(Telephony.Sms.DATE_SENT, sentTime)
|
Pair(Telephony.Sms.DATE_SENT, sentTime),
|
||||||
put(Telephony.Sms.SUBSCRIPTION_ID, subId)
|
Pair(Telephony.Sms.SUBSCRIPTION_ID, subId))
|
||||||
}
|
.let { values -> context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values) }
|
||||||
val uri = context.contentResolver.insert(Telephony.Sms.Inbox.CONTENT_URI, values)
|
|
||||||
|
|
||||||
// Insert the message to Realm
|
// Insert the message to Realm
|
||||||
return Message().apply {
|
return Message().apply {
|
||||||
@@ -384,8 +386,8 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
this.subId = subId
|
this.subId = subId
|
||||||
|
|
||||||
id = messageIds.newId()
|
id = messageIds.newId()
|
||||||
threadId = conversationRepo.getOrCreateConversation(address)?.id ?: 0L
|
threadId = TelephonyCompat.getOrCreateThreadId(context, address)
|
||||||
contentId = uri.lastPathSegment.toLong()
|
contentId = uri?.lastPathSegment?.toLong() ?: 0L
|
||||||
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
|
boxId = Telephony.Sms.MESSAGE_TYPE_INBOX
|
||||||
type = "sms"
|
type = "sms"
|
||||||
insertOrUpdate()
|
insertOrUpdate()
|
||||||
|
|||||||
@@ -25,6 +25,4 @@ interface CursorToConversation : Mapper<Cursor, Conversation> {
|
|||||||
|
|
||||||
fun getConversationsCursor(lastSync: Long = 0): Cursor?
|
fun getConversationsCursor(lastSync: Long = 0): Cursor?
|
||||||
|
|
||||||
fun getConversationCursor(threadId: Long): Cursor?
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user