-
Notifications
You must be signed in to change notification settings - Fork 868
Immutable NotifiableEvent models #4182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
44f2320
6ddb153
6080024
1acf4da
012df13
45d30e3
e3f2161
dcae177
d5e73cc
ae2dadf
ecaac69
2a328c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Adding the room name to the invitation notification (if the room summary is available) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
| */ | ||
| package im.vector.app.features.notifications | ||
|
|
||
| import androidx.core.app.NotificationCompat | ||
| import im.vector.app.BuildConfig | ||
| import im.vector.app.R | ||
| import im.vector.app.core.resources.StringProvider | ||
|
|
@@ -54,21 +53,19 @@ class NotifiableEventResolver @Inject constructor( | |
|
|
||
| // private val eventDisplay = RiotEventDisplay(context) | ||
|
|
||
| fun resolveEvent(event: Event/*, roomState: RoomState?, bingRule: PushRule?*/, session: Session): NotifiableEvent? { | ||
| fun resolveEvent(event: Event/*, roomState: RoomState?, bingRule: PushRule?*/, session: Session, isNoisy: Boolean): NotifiableEvent? { | ||
| val roomID = event.roomId ?: return null | ||
| val eventId = event.eventId ?: return null | ||
| if (event.getClearType() == EventType.STATE_ROOM_MEMBER) { | ||
| return resolveStateRoomEvent(event, session) | ||
| return resolveStateRoomEvent(event, session, canBeReplaced = false, isNoisy = isNoisy) | ||
| } | ||
| val timelineEvent = session.getRoom(roomID)?.getTimeLineEvent(eventId) ?: return null | ||
| when (event.getClearType()) { | ||
| EventType.MESSAGE -> { | ||
| return resolveMessageEvent(timelineEvent, session) | ||
| return resolveMessageEvent(timelineEvent, session, canBeReplaced = false, isNoisy = isNoisy) | ||
| } | ||
| EventType.ENCRYPTED -> { | ||
| val messageEvent = resolveMessageEvent(timelineEvent, session) | ||
| messageEvent?.lockScreenVisibility = NotificationCompat.VISIBILITY_PRIVATE | ||
| return messageEvent | ||
| return resolveMessageEvent(timelineEvent, session, canBeReplaced = false, isNoisy = isNoisy) | ||
| } | ||
| else -> { | ||
| // If the event can be displayed, display it as is | ||
|
|
@@ -85,12 +82,14 @@ class NotifiableEventResolver @Inject constructor( | |
| description = bodyPreview, | ||
| title = stringProvider.getString(R.string.notification_unknown_new_event), | ||
| soundName = null, | ||
| type = event.type) | ||
| type = event.type, | ||
| canBeReplaced = false | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun resolveInMemoryEvent(session: Session, event: Event): NotifiableEvent? { | ||
| fun resolveInMemoryEvent(session: Session, event: Event, canBeReplaced: Boolean): NotifiableEvent? { | ||
| if (event.getClearType() != EventType.MESSAGE) return null | ||
|
|
||
| // Ignore message edition | ||
|
|
@@ -114,24 +113,14 @@ class NotifiableEventResolver @Inject constructor( | |
| avatarUrl = user.avatarUrl | ||
| ) | ||
| ) | ||
|
|
||
| val notifiableEvent = resolveMessageEvent(timelineEvent, session) | ||
|
|
||
| if (notifiableEvent == null) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Timber.d("## Failed to resolve event") | ||
| // TODO | ||
| null | ||
| } else { | ||
| notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank() | ||
| notifiableEvent | ||
| } | ||
| resolveMessageEvent(timelineEvent, session, canBeReplaced = canBeReplaced, isNoisy = !notificationAction.soundName.isNullOrBlank()) | ||
| } else { | ||
| Timber.d("Matched push rule is set to not notify") | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun resolveMessageEvent(event: TimelineEvent, session: Session): NotifiableEvent? { | ||
| private fun resolveMessageEvent(event: TimelineEvent, session: Session, canBeReplaced: Boolean, isNoisy: Boolean): NotifiableEvent { | ||
| // The event only contains an eventId, and roomId (type is m.room.*) , we need to get the displayable content (names, avatar, text, etc...) | ||
| val room = session.getRoom(event.root.roomId!! /*roomID cannot be null*/) | ||
|
|
||
|
|
@@ -142,19 +131,19 @@ class NotifiableEventResolver @Inject constructor( | |
| val roomName = stringProvider.getString(R.string.notification_unknown_room_name) | ||
| val senderDisplayName = event.senderInfo.disambiguatedDisplayName | ||
|
|
||
| val notifiableEvent = NotifiableMessageEvent( | ||
| return NotifiableMessageEvent( | ||
| eventId = event.root.eventId!!, | ||
| editedEventId = event.getEditedEventId(), | ||
| canBeReplaced = canBeReplaced, | ||
| timestamp = event.root.originServerTs ?: 0, | ||
| noisy = false, // will be updated | ||
| noisy = isNoisy, | ||
| senderName = senderDisplayName, | ||
| senderId = event.root.senderId, | ||
| body = body.toString(), | ||
| roomId = event.root.roomId!!, | ||
| roomName = roomName) | ||
|
|
||
| notifiableEvent.matrixID = session.myUserId | ||
| return notifiableEvent | ||
| roomName = roomName, | ||
| matrixID = session.myUserId | ||
| ) | ||
| } else { | ||
| if (event.root.isEncrypted() && event.root.mxDecryptionResult == null) { | ||
| // TODO use a global event decryptor? attache to session and that listen to new sessionId? | ||
|
|
@@ -175,57 +164,56 @@ class NotifiableEventResolver @Inject constructor( | |
| val roomName = room.roomSummary()?.displayName ?: "" | ||
| val senderDisplayName = event.senderInfo.disambiguatedDisplayName | ||
|
|
||
| val notifiableEvent = NotifiableMessageEvent( | ||
| return NotifiableMessageEvent( | ||
| eventId = event.root.eventId!!, | ||
| editedEventId = event.getEditedEventId(), | ||
| canBeReplaced = canBeReplaced, | ||
| timestamp = event.root.originServerTs ?: 0, | ||
| noisy = false, // will be updated | ||
| noisy = isNoisy, | ||
| senderName = senderDisplayName, | ||
| senderId = event.root.senderId, | ||
| body = body, | ||
| roomId = event.root.roomId!!, | ||
| roomName = roomName, | ||
| roomIsDirect = room.roomSummary()?.isDirect ?: false) | ||
|
|
||
| notifiableEvent.matrixID = session.myUserId | ||
| notifiableEvent.soundName = null | ||
|
|
||
| // Get the avatars URL | ||
| notifiableEvent.roomAvatarPath = session.contentUrlResolver() | ||
| .resolveThumbnail(room.roomSummary()?.avatarUrl, | ||
| 250, | ||
| 250, | ||
| ContentUrlResolver.ThumbnailMethod.SCALE) | ||
|
|
||
| notifiableEvent.senderAvatarPath = session.contentUrlResolver() | ||
| .resolveThumbnail(event.senderInfo.avatarUrl, | ||
| 250, | ||
| 250, | ||
| ContentUrlResolver.ThumbnailMethod.SCALE) | ||
|
|
||
| return notifiableEvent | ||
| roomIsDirect = room.roomSummary()?.isDirect ?: false, | ||
| roomAvatarPath = session.contentUrlResolver() | ||
| .resolveThumbnail(room.roomSummary()?.avatarUrl, | ||
| 250, | ||
| 250, | ||
| ContentUrlResolver.ThumbnailMethod.SCALE), | ||
| senderAvatarPath = session.contentUrlResolver() | ||
| .resolveThumbnail(event.senderInfo.avatarUrl, | ||
| 250, | ||
| 250, | ||
| ContentUrlResolver.ThumbnailMethod.SCALE), | ||
| matrixID = session.myUserId, | ||
| soundName = null | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun resolveStateRoomEvent(event: Event, session: Session): NotifiableEvent? { | ||
| private fun resolveStateRoomEvent(event: Event, session: Session, canBeReplaced: Boolean, isNoisy: Boolean): NotifiableEvent? { | ||
| val content = event.content?.toModel<RoomMemberContent>() ?: return null | ||
| val roomId = event.roomId ?: return null | ||
| val dName = event.senderId?.let { session.getRoomMember(it, roomId)?.displayName } | ||
| if (Membership.INVITE == content.membership) { | ||
| val body = noticeEventFormatter.format(event, dName, isDm = session.getRoomSummary(roomId)?.isDirect.orFalse()) | ||
| val roomSummary = session.getRoomSummary(roomId) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the room name change is from #4230 (for next time I'll be sure to better highlight the merge ordering to avoid growing diffs) |
||
| val body = noticeEventFormatter.format(event, dName, isDm = roomSummary?.isDirect.orFalse()) | ||
| ?: stringProvider.getString(R.string.notification_new_invitation) | ||
| return InviteNotifiableEvent( | ||
| session.myUserId, | ||
| eventId = event.eventId!!, | ||
| editedEventId = null, | ||
| canBeReplaced = canBeReplaced, | ||
| roomId = roomId, | ||
| roomName = roomSummary?.displayName, | ||
| timestamp = event.originServerTs ?: 0, | ||
| noisy = false, // will be set later | ||
| noisy = isNoisy, | ||
| title = stringProvider.getString(R.string.notification_new_invitation), | ||
| description = body.toString(), | ||
| soundName = null, // will be set later | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment is a lie! the |
||
| type = event.getClearType(), | ||
| isPushGatewayEvent = false) | ||
| type = event.getClearType() | ||
| ) | ||
| } else { | ||
| Timber.e("## unsupported notifiable event for eventId [${event.eventId}]") | ||
| if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was unused, if we want it back we can retrieve it from the source control history
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup. In practice I think this code will be lost forever :), but anyway, this is not a big loss