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

Calculate encrypted notification counts #851

Merged
merged 8 commits into from
Mar 6, 2019
Merged

Calculate encrypted notification counts #851

merged 8 commits into from
Mar 6, 2019

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Mar 5, 2019

Fixes element-hq/element-web#7489
Required by matrix-org/matrix-react-sdk#2744 Not needed.

I'm not entirely convinced that the changes here are the right place to shove this code, but it does work well enough to at least open a PR. I've since shuffled things around.

My GIF recorder is broken, so here's a deconstructed 2 frame GIF:
image
image

Needed for encrypted events to be able to pass some push rules.
Otherwise we'll be looking at the encrypted source, and that doesn't help anyone.
@turt2live turt2live self-assigned this Mar 5, 2019
@turt2live turt2live requested a review from a team March 5, 2019 21:30
@turt2live turt2live removed their assignment Mar 5, 2019
Copy link
Member

@ara4n ara4n left a comment

Choose a reason for hiding this comment

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

this generally lgtm (thanks!) but i think we should be super clear that it ignores counts of events which arrived whilst the client was offline - ie the server can’t yet calculate correct counts for us.

It’s probably worth observing that either we could download all the traffic to calculate the right badges (which we will need to do for e2e indexing anyway), or matrix-org/matrix-spec-proposals#1796 needs to land.

return true;
}

for (let i = this.timeline.length - 1; i >= 0; --i) {
Copy link
Member

Choose a reason for hiding this comment

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

doing a linear search of the timeline feels quite heavy here, especially if we calc this for every new received event?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a reverse search, and very much ripped off from Unread.doesRoomHaveUnreadMessages() in the react-sdk. Worst case is the room is very popular and the loop falls behind by a couple iterations, but it should never get as bad as traversing the whole timeline.

@turt2live
Copy link
Member Author

we should be super clear that it ignores counts of events which arrived whilst the client was offline - ie the server can’t yet calculate correct counts for us.

Fair point, I didn't mention it in the PR but I did take some time to try and figure it out. The timeline stuff is impenetrable and non-trivial, and I'm not very inclined to keep bashing my head against this. A proper implementation of some MSC would almost certainly help with this.

@turt2live
Copy link
Member Author

Actually, wait a minute: this implementation does fix the counts. We already get a count for the number of unread messages (grey badge) and this specifically manipulates the highlight count using the client-side calculation of the push rules. If the client disappears for a while and comes back, this should be able to do the math correctly and come out with a number. An earlier implementation didn't do this, which is where my last comment is based on.

@ara4n
Copy link
Member

ara4n commented Mar 6, 2019

the problem is that if you’ve been binged in a room and your client wasn’t online at the time and hasn’t backfilled far enough to see it, the count will not include it. which is okay for now, but needs to be flagged in big warning letters and bugfiled

@turt2live turt2live requested a review from ara4n March 6, 2019 16:56
@ara4n
Copy link
Member

ara4n commented Mar 6, 2019

lgtm - thanks!

@ara4n ara4n merged commit 77270fa into develop Mar 6, 2019
@turt2live turt2live deleted the travis/e2e-notifs branch March 6, 2019 17:13
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