Create getDismissRoomPendingIntent()

This commit is contained in:
Benoit Marty 2023-04-14 17:14:29 +02:00
parent cb8d206ed4
commit a9881341f1

View file

@ -300,26 +300,13 @@ class NotificationUtils @Inject constructor(
if (!roomInfo.hasSmartReplyError) { if (!roomInfo.hasSmartReplyError) {
addAction(quickReplyActionFactory.create(roomInfo, threadId)) addAction(quickReplyActionFactory.create(roomInfo, threadId))
} }
if (openIntent != null) { if (openIntent != null) {
setContentIntent(openIntent) setContentIntent(openIntent)
} }
if (largeIcon != null) { if (largeIcon != null) {
setLargeIcon(largeIcon) setLargeIcon(largeIcon)
} }
setDeleteIntent(getDismissRoomPendingIntent(roomInfo))
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = actionIds.dismissRoom
intent.putExtra(NotificationBroadcastReceiver.KEY_SESSION_ID, roomInfo.sessionId)
intent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomInfo.roomId)
val pendingIntent = PendingIntent.getBroadcast(
context.applicationContext,
clock.epochMillis().toInt(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
setDeleteIntent(pendingIntent)
} }
.setTicker(tickerText) .setTicker(tickerText)
.build() .build()
@ -487,13 +474,26 @@ class NotificationUtils @Inject constructor(
intent.data = createIgnoredUri("deleteSummary?$sessionId") intent.data = createIgnoredUri("deleteSummary?$sessionId")
intent.putExtra(NotificationBroadcastReceiver.KEY_SESSION_ID, sessionId) intent.putExtra(NotificationBroadcastReceiver.KEY_SESSION_ID, sessionId)
return PendingIntent.getBroadcast( return PendingIntent.getBroadcast(
context.applicationContext, context,
0, 0,
intent, intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
) )
} }
private fun getDismissRoomPendingIntent(roomInfo: RoomEventGroupInfo): PendingIntent {
val intent = Intent(context, NotificationBroadcastReceiver::class.java)
intent.action = actionIds.dismissRoom
intent.putExtra(NotificationBroadcastReceiver.KEY_SESSION_ID, roomInfo.sessionId)
intent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomInfo.roomId)
return PendingIntent.getBroadcast(
context,
clock.epochMillis().toInt(),
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
}
/** /**
* Cancel the foreground notification service. * Cancel the foreground notification service.
*/ */