forked from upstream-mirrors/quik
Sync MMS once sent
This commit is contained in:
@@ -52,6 +52,7 @@ interface AppComponent {
|
|||||||
fun inject(receiver: MarkSeenReceiver)
|
fun inject(receiver: MarkSeenReceiver)
|
||||||
fun inject(receiver: MarkReadReceiver)
|
fun inject(receiver: MarkReadReceiver)
|
||||||
fun inject(receiver: MmsReceivedReceiver)
|
fun inject(receiver: MmsReceivedReceiver)
|
||||||
|
fun inject(receiver: MmsSentReceiver)
|
||||||
fun inject(receiver: RemoteMessagingReceiver)
|
fun inject(receiver: RemoteMessagingReceiver)
|
||||||
|
|
||||||
fun inject(view: AvatarView)
|
fun inject(view: AvatarView)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package common.util
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.provider.Telephony
|
||||||
import common.util.extensions.asFlowable
|
import common.util.extensions.asFlowable
|
||||||
import common.util.extensions.insertOrUpdate
|
import common.util.extensions.insertOrUpdate
|
||||||
import common.util.extensions.map
|
import common.util.extensions.map
|
||||||
@@ -106,7 +107,17 @@ class SyncManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun syncMessage(uri: Uri): Flowable<Message> {
|
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)
|
val columnsMap = CursorToMessage.MessageColumns(cursor)
|
||||||
|
|
||||||
// Map the cursor to a message
|
// 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
|
package presentation.receiver
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import com.klinker.android.send_message.MmsSentReceiver
|
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() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user