mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 03:28:52 +01:00
Sync MMS upon receiving
This commit is contained in:
@@ -19,19 +19,25 @@
|
||||
package common.util
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import common.util.extensions.asFlowable
|
||||
import common.util.extensions.insertOrUpdate
|
||||
import common.util.extensions.map
|
||||
import common.util.extensions.mapWhile
|
||||
import data.mapper.CursorToConversation
|
||||
import data.mapper.CursorToMessage
|
||||
import data.mapper.CursorToRecipient
|
||||
import data.model.*
|
||||
import data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import io.realm.Realm
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class SyncManager @Inject constructor(
|
||||
context: Context,
|
||||
private val context: Context,
|
||||
private val messageRepo: MessageRepository,
|
||||
private val cursorToConversation: CursorToConversation,
|
||||
private val cursorToMessage: CursorToMessage,
|
||||
private val cursorToRecipient: CursorToRecipient) {
|
||||
@@ -99,4 +105,15 @@ class SyncManager @Inject constructor(
|
||||
status = Status.Idle()
|
||||
}
|
||||
|
||||
fun syncMessage(uri: Uri): Flowable<Message> {
|
||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
||||
val columnsMap = CursorToMessage.MessageColumns(cursor)
|
||||
|
||||
// Map the cursor to a message
|
||||
return cursor.asFlowable()
|
||||
.map { cursorToMessage.map(Pair(it, columnsMap)) }
|
||||
.doOnNext { message -> messageRepo.getOrCreateConversation(message.threadId) }
|
||||
.doOnNext { message -> message.insertOrUpdate() }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user