Clear messages history in chat notification when it is marked as read

This commit is contained in:
Sylvain Berfini 2020-10-01 11:47:13 +02:00
parent 08cb252116
commit c86b548fa9
2 changed files with 66 additions and 56 deletions

View file

@ -31,9 +31,17 @@ import org.linphone.core.tools.Log
class NotificationBroadcastReceiver : BroadcastReceiver() { class NotificationBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
val notificationId = intent.getIntExtra(NotificationsManager.INTENT_NOTIF_ID, 0) val notificationId = intent.getIntExtra(NotificationsManager.INTENT_NOTIF_ID, 0)
val localIdentity = intent.getStringExtra(NotificationsManager.INTENT_LOCAL_IDENTITY)
if (intent.action == NotificationsManager.INTENT_REPLY_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_MARK_AS_READ_ACTION) { if (intent.action == NotificationsManager.INTENT_REPLY_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_MARK_AS_READ_ACTION) {
handleChatIntent(intent, notificationId)
} else if (intent.action == NotificationsManager.INTENT_ANSWER_CALL_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_HANGUP_CALL_NOTIF_ACTION) {
handleCallIntent(intent, notificationId)
}
}
private fun handleChatIntent(intent: Intent, notificationId: Int) {
val localIdentity = intent.getStringExtra(NotificationsManager.INTENT_LOCAL_IDENTITY)
val remoteSipAddress: String? = coreContext.notificationsManager.getSipUriForChatNotificationId(notificationId) val remoteSipAddress: String? = coreContext.notificationsManager.getSipUriForChatNotificationId(notificationId)
if (remoteSipAddress == null) { if (remoteSipAddress == null) {
Log.e("[Notification Broadcast Receiver] Couldn't find remote address $remoteSipAddress for notification id $notificationId") Log.e("[Notification Broadcast Receiver] Couldn't find remote address $remoteSipAddress for notification id $notificationId")
@ -77,9 +85,11 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
msg.send() msg.send()
Log.i("[Notification Broadcast Receiver] Reply sent for notif id $notificationId") Log.i("[Notification Broadcast Receiver] Reply sent for notif id $notificationId")
} else { } else {
coreContext.notificationsManager.cancel(notificationId) coreContext.notificationsManager.dismissChatNotification(room)
} }
} else if (intent.action == NotificationsManager.INTENT_ANSWER_CALL_NOTIF_ACTION || intent.action == NotificationsManager.INTENT_HANGUP_CALL_NOTIF_ACTION) { }
private fun handleCallIntent(intent: Intent, notificationId: Int) {
val remoteAddress: String? = coreContext.notificationsManager.getSipUriForCallNotificationId(notificationId) val remoteAddress: String? = coreContext.notificationsManager.getSipUriForCallNotificationId(notificationId)
val core: Core = coreContext.core val core: Core = coreContext.core
@ -95,7 +105,6 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
if (call.state == Call.State.IncomingReceived || call.state == Call.State.IncomingEarlyMedia) coreContext.declineCall(call) else coreContext.terminateCall(call) if (call.state == Call.State.IncomingReceived || call.state == Call.State.IncomingEarlyMedia) coreContext.declineCall(call) else coreContext.terminateCall(call)
} }
} }
}
private fun getMessageText(intent: Intent): CharSequence? { private fun getMessageText(intent: Intent): CharSequence? {
val remoteInput = RemoteInput.getResultsFromIntent(intent) val remoteInput = RemoteInput.getResultsFromIntent(intent)

View file

@ -614,6 +614,7 @@ class NotificationsManager(private val context: Context) {
val notifiable: Notifiable? = chatNotificationsMap[address] val notifiable: Notifiable? = chatNotificationsMap[address]
if (notifiable != null) { if (notifiable != null) {
Log.i("[Notifications Manager] Dismissing notification for chat room $room with id ${notifiable.notificationId}") Log.i("[Notifications Manager] Dismissing notification for chat room $room with id ${notifiable.notificationId}")
notifiable.messages.clear()
cancel(notifiable.notificationId) cancel(notifiable.notificationId)
} }
} }