Cleanup NotificationCreator.
This commit is contained in:
parent
f0ec0164ef
commit
29889ad9ec
1 changed files with 31 additions and 58 deletions
|
|
@ -142,14 +142,21 @@ class DefaultNotificationCreator(
|
||||||
} else {
|
} else {
|
||||||
notificationChannels.getChannelIdForMessage(noisy = roomInfo.shouldBing)
|
notificationChannels.getChannelIdForMessage(noisy = roomInfo.shouldBing)
|
||||||
}
|
}
|
||||||
|
// A category allows groups of notifications to be ranked and filtered – per user or system settings.
|
||||||
|
// For example, alarm notifications should display before promo notifications, or message from known contact
|
||||||
|
// that can be displayed in not disturb mode if white listed (the later will need compat28.x)
|
||||||
|
// If any of the events are of rtc notification type it means a missed call, set the category to the right value
|
||||||
|
val category = if (containsMissedCall) {
|
||||||
|
NotificationCompat.CATEGORY_MISSED_CALL
|
||||||
|
} else {
|
||||||
|
NotificationCompat.CATEGORY_MESSAGE
|
||||||
|
}
|
||||||
val builder = if (existingNotification != null) {
|
val builder = if (existingNotification != null) {
|
||||||
NotificationCompat.Builder(context, existingNotification)
|
NotificationCompat.Builder(context, existingNotification)
|
||||||
|
// Clear existing actions
|
||||||
|
.clearActions()
|
||||||
} else {
|
} else {
|
||||||
NotificationCompat.Builder(context, channelId)
|
NotificationCompat.Builder(context, channelId)
|
||||||
// A category allows groups of notifications to be ranked and filtered – per user or system settings.
|
|
||||||
// For example, alarm notifications should display before promo notifications, or message from known contact
|
|
||||||
// that can be displayed in not disturb mode if white listed (the later will need compat28.x)
|
|
||||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
|
||||||
// ID of the corresponding shortcut, for conversation features under API 30+
|
// ID of the corresponding shortcut, for conversation features under API 30+
|
||||||
// Must match those created in the ShortcutInfoCompat.Builder()
|
// Must match those created in the ShortcutInfoCompat.Builder()
|
||||||
// for the notification to appear as a "Conversation":
|
// for the notification to appear as a "Conversation":
|
||||||
|
|
@ -165,7 +172,6 @@ class DefaultNotificationCreator(
|
||||||
// Remove notification after opening it or using an action
|
// Remove notification after opening it or using an action
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val messagingStyle = existingNotification?.let {
|
val messagingStyle = existingNotification?.let {
|
||||||
MessagingStyle.extractMessagingStyleFromNotification(it)
|
MessagingStyle.extractMessagingStyleFromNotification(it)
|
||||||
} ?: createMessagingStyleFromCurrentUser(
|
} ?: createMessagingStyleFromCurrentUser(
|
||||||
|
|
@ -175,52 +181,35 @@ class DefaultNotificationCreator(
|
||||||
isThread = threadId != null,
|
isThread = threadId != null,
|
||||||
roomIsGroup = !roomInfo.isDm,
|
roomIsGroup = !roomInfo.isDm,
|
||||||
)
|
)
|
||||||
|
|
||||||
messagingStyle.addMessagesFromEvents(events, imageLoader)
|
messagingStyle.addMessagesFromEvents(events, imageLoader)
|
||||||
|
|
||||||
return builder
|
return builder
|
||||||
|
.setCategory(category)
|
||||||
.setNumber(events.size)
|
.setNumber(events.size)
|
||||||
.setOnlyAlertOnce(roomInfo.isUpdated)
|
.setOnlyAlertOnce(roomInfo.isUpdated)
|
||||||
.setWhen(lastMessageTimestamp)
|
.setWhen(lastMessageTimestamp)
|
||||||
// MESSAGING_STYLE sets title and content for API 16 and above devices.
|
// MESSAGING_STYLE sets title and content for API 16 and above devices.
|
||||||
.setStyle(messagingStyle)
|
.setStyle(messagingStyle)
|
||||||
.configureWith(notificationAccountParams)
|
.configureWith(notificationAccountParams)
|
||||||
// Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
|
// Mark room/thread as read
|
||||||
// 'importance' which is set in the NotificationChannel. The integers representing
|
.addAction(markAsReadActionFactory.create(roomInfo, threadId))
|
||||||
// 'priority' are different from 'importance', so make sure you don't mix them.
|
.setContentIntent(openIntent)
|
||||||
|
.setLargeIcon(largeIcon)
|
||||||
|
.setDeleteIntent(pendingIntentFactory.createDismissRoomPendingIntent(roomInfo.sessionId, roomInfo.roomId))
|
||||||
.apply {
|
.apply {
|
||||||
|
// Sets priority for 25 and below. For 26 and above, 'priority' is deprecated for
|
||||||
|
// 'importance' which is set in the NotificationChannel. The integers representing
|
||||||
|
// 'priority' are different from 'importance', so make sure you don't mix them.
|
||||||
if (roomInfo.shouldBing) {
|
if (roomInfo.shouldBing) {
|
||||||
// Compat
|
|
||||||
priority = NotificationCompat.PRIORITY_DEFAULT
|
priority = NotificationCompat.PRIORITY_DEFAULT
|
||||||
/*
|
|
||||||
vectorPreferences.getNotificationRingTone()?.let {
|
|
||||||
setSound(it)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setLights(notificationAccountParams.color, 500, 500)
|
setLights(notificationAccountParams.color, 500, 500)
|
||||||
} else {
|
} else {
|
||||||
priority = NotificationCompat.PRIORITY_LOW
|
priority = NotificationCompat.PRIORITY_LOW
|
||||||
}
|
}
|
||||||
// Clear existing actions since we might be updating an existing notification
|
|
||||||
clearActions()
|
|
||||||
// Add actions and notification intents
|
|
||||||
// Mark room/thread as read
|
|
||||||
addAction(markAsReadActionFactory.create(roomInfo, threadId))
|
|
||||||
// Quick reply
|
// Quick reply
|
||||||
if (!roomInfo.hasSmartReplyError) {
|
if (!roomInfo.hasSmartReplyError) {
|
||||||
val latestEventId = events.lastOrNull()?.eventId
|
val latestEventId = events.lastOrNull()?.eventId
|
||||||
addAction(quickReplyActionFactory.create(roomInfo, latestEventId, threadId))
|
addAction(quickReplyActionFactory.create(roomInfo, latestEventId, threadId))
|
||||||
}
|
}
|
||||||
if (openIntent != null) {
|
|
||||||
setContentIntent(openIntent)
|
|
||||||
}
|
|
||||||
setLargeIcon(largeIcon)
|
|
||||||
setDeleteIntent(pendingIntentFactory.createDismissRoomPendingIntent(roomInfo.sessionId, roomInfo.roomId))
|
|
||||||
|
|
||||||
// If any of the events are of rtc notification type it means a missed call, set the category to the right value
|
|
||||||
if (events.any { it.type == EventType.RTC_NOTIFICATION }) {
|
|
||||||
setCategory(NotificationCompat.CATEGORY_MISSED_CALL)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.setTicker(tickerText)
|
.setTicker(tickerText)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -237,32 +226,26 @@ class DefaultNotificationCreator(
|
||||||
.setContentText(inviteNotifiableEvent.description.annotateForDebug(6))
|
.setContentText(inviteNotifiableEvent.description.annotateForDebug(6))
|
||||||
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL)
|
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_ALL)
|
||||||
.configureWith(notificationAccountParams)
|
.configureWith(notificationAccountParams)
|
||||||
|
.addAction(rejectInvitationActionFactory.create(inviteNotifiableEvent))
|
||||||
|
.addAction(acceptInvitationActionFactory.create(inviteNotifiableEvent))
|
||||||
|
// Build the pending intent for when the notification is clicked
|
||||||
|
.setContentIntent(pendingIntentFactory.createOpenRoomPendingIntent(inviteNotifiableEvent.sessionId, inviteNotifiableEvent.roomId, null))
|
||||||
.apply {
|
.apply {
|
||||||
addAction(rejectInvitationActionFactory.create(inviteNotifiableEvent))
|
|
||||||
addAction(acceptInvitationActionFactory.create(inviteNotifiableEvent))
|
|
||||||
// Build the pending intent for when the notification is clicked
|
|
||||||
setContentIntent(pendingIntentFactory.createOpenRoomPendingIntent(inviteNotifiableEvent.sessionId, inviteNotifiableEvent.roomId, null))
|
|
||||||
|
|
||||||
if (inviteNotifiableEvent.noisy) {
|
if (inviteNotifiableEvent.noisy) {
|
||||||
// Compat
|
// Compat
|
||||||
priority = NotificationCompat.PRIORITY_DEFAULT
|
priority = NotificationCompat.PRIORITY_DEFAULT
|
||||||
/*
|
|
||||||
vectorPreferences.getNotificationRingTone()?.let {
|
|
||||||
setSound(it)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setLights(notificationAccountParams.color, 500, 500)
|
setLights(notificationAccountParams.color, 500, 500)
|
||||||
} else {
|
} else {
|
||||||
priority = NotificationCompat.PRIORITY_LOW
|
priority = NotificationCompat.PRIORITY_LOW
|
||||||
}
|
}
|
||||||
setDeleteIntent(
|
|
||||||
pendingIntentFactory.createDismissInvitePendingIntent(
|
|
||||||
inviteNotifiableEvent.sessionId,
|
|
||||||
inviteNotifiableEvent.roomId,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
setAutoCancel(true)
|
|
||||||
}
|
}
|
||||||
|
.setDeleteIntent(
|
||||||
|
pendingIntentFactory.createDismissInvitePendingIntent(
|
||||||
|
inviteNotifiableEvent.sessionId,
|
||||||
|
inviteNotifiableEvent.roomId,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setAutoCancel(true)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,11 +266,6 @@ class DefaultNotificationCreator(
|
||||||
if (simpleNotifiableEvent.noisy) {
|
if (simpleNotifiableEvent.noisy) {
|
||||||
// Compat
|
// Compat
|
||||||
priority = NotificationCompat.PRIORITY_DEFAULT
|
priority = NotificationCompat.PRIORITY_DEFAULT
|
||||||
/*
|
|
||||||
vectorPreferences.getNotificationRingTone()?.let {
|
|
||||||
setSound(it)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setLights(notificationAccountParams.color, 500, 500)
|
setLights(notificationAccountParams.color, 500, 500)
|
||||||
} else {
|
} else {
|
||||||
priority = NotificationCompat.PRIORITY_LOW
|
priority = NotificationCompat.PRIORITY_LOW
|
||||||
|
|
@ -346,11 +324,6 @@ class DefaultNotificationCreator(
|
||||||
if (noisy) {
|
if (noisy) {
|
||||||
// Compat
|
// Compat
|
||||||
priority = NotificationCompat.PRIORITY_DEFAULT
|
priority = NotificationCompat.PRIORITY_DEFAULT
|
||||||
/*
|
|
||||||
vectorPreferences.getNotificationRingTone()?.let {
|
|
||||||
setSound(it)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
setLights(notificationAccountParams.color, 500, 500)
|
setLights(notificationAccountParams.color, 500, 500)
|
||||||
} else {
|
} else {
|
||||||
// compat
|
// compat
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue