Skip to content
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

Immutable NotifiableEvent models #4182

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Oct 7, 2021

A little bit of clean up to attempt to reduce the notification redesign PR size...

Updates the NotifiableEvent models to favour immutable state, this allows us to the simplify the mutation flows

  • Gives the NotifiableEventResolver full control over the creation of the events (when I get time I'll revisit and add tests)
  • isPushGatewayEvent -> canBeReplaced
  • isNoisy is calculated at the point of creation rather than appended later on
  • Ensures events can't mutate whilst we're iterating over them*
  • Removes unused handleNotificationWithoutSyncingMode and lockScreenVisibility

Notice how the summary sneaks through in the reading gif, this will also be fixed by the redesign.

RECEIVING READING
after-notification-messages after-reading-messages

*this doesn't include updating hasBeenDisplayed as this will be removed entirely
*against a feature branch

@@ -238,87 +232,4 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
}
return false
}

private fun handleNotificationWithoutSyncingMode(data: Map<String, String>, session: Session?) {
Copy link
Contributor Author

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

Copy link
Member

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

roomId = roomId,
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is a lie! the soundName is in fact never updated

hasBeenDisplayed = false
eventList.replace(eventId) {
when (it) {
is InviteNotifiableEvent -> it.copy(isRedacted = true).apply { hasBeenDisplayed = false }
Copy link
Contributor Author

@ouchadam ouchadam Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating hasBeenDisplayed is temporary

in the redesign simply mutating the contents of the eventList will allow the notifications to be rerendered, no need to use the hasBeenDisplayed state

the eventList will be a 1 to 1 mapping of the currently displaying notifications

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the eventList will be a 1 to 1 mapping of the currently displaying notifications

Could be nice to have this comment above eventList declaration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add 👍

@github-actions
Copy link

github-actions bot commented Oct 7, 2021

Unit Test Results

  42 files    42 suites   47s ⏱️
  83 tests   83 ✔️ 0 💤 0
220 runs  220 ✔️ 0 💤 0

Results for commit 2a328c6.

♻️ This comment has been updated with latest results.

- also makes the notifiable events sealed interfaces so that we can copy the data classes with new redacted values when it changes
…ed or made immutable by the notification redesign
…can be replaced

- makes the property immutable as only the creation of the event knows if it can be replace eg it came from a push or the /sync event stream
@ouchadam ouchadam force-pushed the feature/adm/immutable-notifiable-models branch from 55681b1 to d5e73cc Compare October 11, 2021 16:57
@ouchadam ouchadam mentioned this pull request Oct 12, 2021
ouchadam and others added 2 commits October 12, 2021 17:33
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

@ouchadam ouchadam requested a review from bmarty October 13, 2021 07:40
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, can be merged to the other branch.
I have to admit I made a fast review, will read (and test) more carefully the PR which will land to develop.


val notifiableEvent = resolveMessageEvent(timelineEvent, session)

if (notifiableEvent == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveMessageEvent no longer returns null 🎉

@ouchadam
Copy link
Contributor Author

@bmarty thanks! this PR is probably the lowest risk compared to the big creation/display split and the diffing changes

I could create a separate PR will all the changes merged purely for testing if you think that would help?

@ouchadam ouchadam merged commit ba6e019 into feature/adm/notification-redesign Oct 13, 2021
@ouchadam ouchadam deleted the feature/adm/immutable-notifiable-models branch October 13, 2021 09:50
@bmarty
Copy link
Member

bmarty commented Oct 13, 2021

I could create a separate PR will all the changes merged purely for testing if you think that would help?

Yes, it will be a PR from branch feature/adm/notification-redesign, no? I was thinking you will create one, but it was not the plan? Maybe because feature/adm/notification-redesign only contains approved PRs content?

@ouchadam
Copy link
Contributor Author

yep exactly ^^^ feature/adm/notification-redesign only contains approved PRs

although now I think about it, it might be better to PR the main logic change and the diffing into the same PR, that way there's only 1 PR remaining. then we don't need to the separate test branch (in this case)

it's a bit easier to review new code by itself than new code + changes

I'll still raise the full feature PR against develop for PR/commit tracking purposes but it will only contain already reviewed PRs

@ouchadam ouchadam mentioned this pull request Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants