diff --git a/qksms/src/main/java/interactor/ReceiveMms.kt b/qksms/src/main/java/interactor/ReceiveMms.kt new file mode 100644 index 00000000..eed4f91c --- /dev/null +++ b/qksms/src/main/java/interactor/ReceiveMms.kt @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package interactor + +import android.net.Uri +import common.util.NotificationManager +import common.util.SyncManager +import common.util.extensions.mapNotNull +import data.model.Conversation +import data.repository.MessageRepository +import io.reactivex.Flowable +import javax.inject.Inject + +class ReceiveMms @Inject constructor( + private val syncManager: SyncManager, + private val messageRepo: MessageRepository, + private val notificationManager: NotificationManager +) : Interactor() { + + override fun buildObservable(params: Uri): Flowable { + return Flowable.just(params) + .flatMap { uri -> syncManager.syncMessage(uri) } // Sync the message + .doOnNext { message -> messageRepo.loadParts(message.id) } // Sync the message parts + .mapNotNull { message -> messageRepo.getOrCreateConversation(message.threadId) } // Map message to conversation + .doOnNext { conversation -> if (conversation.archived) messageRepo.markUnarchived(conversation.id) } // Unarchive conversation if necessary + .doOnNext { conversation -> notificationManager.update(conversation.id) } // Update the notification + } + +} \ No newline at end of file diff --git a/qksms/src/main/java/interactor/SyncMessage.kt b/qksms/src/main/java/interactor/SyncMessage.kt deleted file mode 100644 index 8cd0bfd2..00000000 --- a/qksms/src/main/java/interactor/SyncMessage.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2017 Moez Bhatti - * - * 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 . - */ -package interactor - -import android.net.Uri -import common.util.SyncManager -import data.model.Message -import io.reactivex.Flowable -import javax.inject.Inject - -class SyncMessage @Inject constructor(private val syncManager: SyncManager) : Interactor() { - - override fun buildObservable(params: Uri): Flowable { - return Flowable.just(params) - .flatMap { uri -> syncManager.syncMessage(uri) } - } - -} \ No newline at end of file diff --git a/qksms/src/main/java/presentation/receiver/MmsReceivedReceiver.kt b/qksms/src/main/java/presentation/receiver/MmsReceivedReceiver.kt index 31f1e3a9..f43fba26 100644 --- a/qksms/src/main/java/presentation/receiver/MmsReceivedReceiver.kt +++ b/qksms/src/main/java/presentation/receiver/MmsReceivedReceiver.kt @@ -21,23 +21,19 @@ package presentation.receiver import android.net.Uri import com.klinker.android.send_message.MmsReceivedReceiver import common.di.appComponent -import interactor.SyncMessage +import interactor.ReceiveMms import javax.inject.Inject class MmsReceivedReceiver : MmsReceivedReceiver() { - @Inject lateinit var syncMessage: SyncMessage - - init { - appComponent.inject(this) - } + @Inject lateinit var receiveMms: ReceiveMms override fun onMessageReceived(messageUri: Uri?) { - super.onMessageReceived(messageUri) + appComponent.inject(this) messageUri?.let { uri -> val pendingResult = goAsync() - syncMessage.execute(uri) { pendingResult.finish() } + receiveMms.execute(uri) { pendingResult.finish() } } }