forked from upstream-mirrors/quik
#1401 - Fix message stuck as sending when delayed messaging enabled
This commit is contained in:
+14
-10
@@ -16,27 +16,31 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.service
|
||||
package com.moez.QKSMS.receiver
|
||||
|
||||
import android.app.IntentService
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.moez.QKSMS.interactor.RetrySending
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import dagger.android.AndroidInjection
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendSmsService : IntentService(null) {
|
||||
class SendSmsReceiver : BroadcastReceiver() {
|
||||
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var retrySending: RetrySending
|
||||
|
||||
override fun onHandleIntent(intent: Intent) {
|
||||
AndroidInjection.inject(this)
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
AndroidInjection.inject(this, context)
|
||||
|
||||
val id = intent.getLongExtra("id", 0L)
|
||||
messageRepo.getMessage(id)?.let { message ->
|
||||
retrySending.buildObservable(message).blockingSubscribe()
|
||||
}
|
||||
intent.getLongExtra("id", -1L)
|
||||
.takeIf { it >= 0 }
|
||||
?.let(messageRepo::getMessage)
|
||||
?.let { message ->
|
||||
val result = goAsync()
|
||||
retrySending.execute(message) { result.finish() }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -42,9 +42,9 @@ import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.receiver.SendSmsReceiver
|
||||
import com.moez.QKSMS.receiver.SmsDeliveredReceiver
|
||||
import com.moez.QKSMS.receiver.SmsSentReceiver
|
||||
import com.moez.QKSMS.service.SendSmsService
|
||||
import com.moez.QKSMS.util.ImageUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
@@ -313,8 +313,8 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
}
|
||||
|
||||
private fun getIntentForDelayedSms(id: Long): PendingIntent {
|
||||
val intent = Intent(context, SendSmsService::class.java).putExtra("id", id)
|
||||
return PendingIntent.getService(context, id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val intent = Intent(context, SendSmsReceiver::class.java).putExtra("id", id)
|
||||
return PendingIntent.getBroadcast(context, id.toInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
override fun insertSentSms(subId: Int, threadId: Long, address: String, body: String, date: Long): Message {
|
||||
|
||||
Reference in New Issue
Block a user