mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Show notification if message failed to send
This commit is contained in:
@@ -133,6 +133,37 @@ class NotificationManager @Inject constructor(
|
||||
notificationManager.notify(threadId.toInt(), notification.build())
|
||||
}
|
||||
|
||||
fun notifyFailed(msgId: Long) {
|
||||
val message = messageRepo.getMessage(msgId)
|
||||
|
||||
if (message == null || !message.isFailedMessage()) {
|
||||
return
|
||||
}
|
||||
|
||||
val threadId = message.threadId
|
||||
val conversation = messageRepo.getConversation(threadId) ?: return
|
||||
|
||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||
taskStackBuilder.addParentStack(ComposeActivity::class.java)
|
||||
taskStackBuilder.addNextIntent(contentIntent)
|
||||
val contentPI = taskStackBuilder.getPendingIntent(threadId.toInt() + 40000, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
|
||||
val notification = NotificationCompat.Builder(context, DEFAULT_CHANNEL_ID)
|
||||
.setContentTitle(context.getString(R.string.notification_message_failed_title))
|
||||
.setContentText(context.getString(R.string.notification_message_failed_text, conversation.getTitle()))
|
||||
.setColor(colors.theme.blockingFirst())
|
||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||
.setSmallIcon(R.drawable.ic_notification_failed)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(contentPI)
|
||||
.setSound(Uri.parse(prefs.ringtone.get()))
|
||||
.setLights(Color.WHITE, 500, 2000)
|
||||
.setVibrate(if (prefs.vibration.get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||
|
||||
notificationManager.notify(threadId.toInt() + 50000, notification.build())
|
||||
}
|
||||
|
||||
private fun getReplyAction(address: String, threadId: Long): NotificationCompat.Action {
|
||||
val replyIntent = Intent(context, RemoteMessagingReceiver::class.java)
|
||||
.putExtra("address", address)
|
||||
|
||||
@@ -142,6 +142,13 @@ class MessageRepository @Inject constructor(
|
||||
.findAll()
|
||||
}
|
||||
|
||||
fun getMessage(id: Long): Message? {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Message::class.java)
|
||||
.equalTo("id", id)
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of messages which should be shown in the notification
|
||||
* for a given conversation
|
||||
|
||||
@@ -18,12 +18,16 @@
|
||||
*/
|
||||
package interactor
|
||||
|
||||
import common.util.NotificationManager
|
||||
import data.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import javax.inject.Inject
|
||||
|
||||
class MarkFailed @Inject constructor(private val messageRepo: MessageRepository) : Interactor<MarkFailed.Params, Any>() {
|
||||
class MarkFailed @Inject constructor(
|
||||
private val messageRepo: MessageRepository,
|
||||
private val notificationManager: NotificationManager
|
||||
) : Interactor<MarkFailed.Params, Any>() {
|
||||
|
||||
data class Params(val id: Long, val resultCode: Int)
|
||||
|
||||
@@ -31,6 +35,7 @@ class MarkFailed @Inject constructor(private val messageRepo: MessageRepository)
|
||||
return Flowable.just(Unit)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap { messageRepo.markFailed(params.id, params.resultCode) }
|
||||
.doOnNext { notificationManager.notifyFailed(params.id) }
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
@@ -127,6 +127,9 @@
|
||||
<string name="toast_unarchived">Moved to inbox</string>
|
||||
<string name="toast_qksms_plus">You must unlock QKSMS+ to use this</string>
|
||||
|
||||
<string name="notification_message_failed_title">Message not sent</string>
|
||||
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
||||
|
||||
<string-array name="message_options">
|
||||
<item>Copy text</item>
|
||||
<item>Forward</item>
|
||||
|
||||
Reference in New Issue
Block a user