Sync MMS once sent

This commit is contained in:
Moez Bhatti
2018-01-12 15:52:19 -05:00
parent a3ccdbb667
commit 432f71ee95
4 changed files with 68 additions and 2 deletions
@@ -52,6 +52,7 @@ interface AppComponent {
fun inject(receiver: MarkSeenReceiver)
fun inject(receiver: MarkReadReceiver)
fun inject(receiver: MmsReceivedReceiver)
fun inject(receiver: MmsSentReceiver)
fun inject(receiver: RemoteMessagingReceiver)
fun inject(view: AvatarView)
+12 -1
View File
@@ -20,6 +20,7 @@ package common.util
import android.content.Context
import android.net.Uri
import android.provider.Telephony
import common.util.extensions.asFlowable
import common.util.extensions.insertOrUpdate
import common.util.extensions.map
@@ -106,7 +107,17 @@ class SyncManager @Inject constructor(
}
fun syncMessage(uri: Uri): Flowable<Message> {
val cursor = context.contentResolver.query(uri, null, null, null, null)
val id = uri.lastPathSegment
val isMms = uri.toString().contains("mms")
// The uri might be something like content://mms/inbox/id
// The box might change though, so we should just use the mms/id uri
val stableUri = when(isMms) {
true -> Uri.withAppendedPath(Telephony.Mms.CONTENT_URI, id)
false -> Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, id)
}
val cursor = context.contentResolver.query(stableUri, null, null, null, null)
val columnsMap = CursorToMessage.MessageColumns(cursor)
// Map the cursor to a message
@@ -0,0 +1,34 @@
/*
* 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 interactor
import android.net.Uri
import common.util.SyncManager
import data.model.Message
import io.reactivex.Flowable
import javax.inject.Inject
class MarkMmsSent @Inject constructor(private val syncManager: SyncManager) : Interactor<Uri, Message>() {
override fun buildObservable(params: Uri): Flowable<Message> {
return Flowable.just(params)
.flatMap { uri -> syncManager.syncMessage(uri) }
}
}
@@ -18,6 +18,26 @@
*/
package presentation.receiver
import android.content.Context
import android.content.Intent
import android.net.Uri
import com.klinker.android.send_message.MmsSentReceiver
import common.di.appComponent
import interactor.MarkMmsSent
import javax.inject.Inject
class MmsSentReceiver : MmsSentReceiver()
class MmsSentReceiver : MmsSentReceiver() {
@Inject lateinit var markMmsSent: MarkMmsSent
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
appComponent.inject(this)
Uri.parse(intent.getStringExtra("content_uri"))?.let { uri ->
val pendingResult = goAsync()
markMmsSent.execute(uri) { pendingResult.finish() }
}
}
}