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

MSC2654: Unread counts #2654

Open
wants to merge 12 commits into
base: old_master
Choose a base branch
from
103 changes: 103 additions & 0 deletions proposals/2654-unread-counts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# MSC2654: Unread counts

Homeservers currently send clients counts for missed notifications (and
highlights) in responses to `/sync` requests, which allows them to display that
information to clients. However, no count is provided for unread messages. This
means clients have no way of telling users how many messages they've missed
since they last read a given room.

This MSC is an alternative to
[MSC2625](https://github.com/matrix-org/matrix-doc/pull/2625), which doesn't use
push rules to calculate unread counts, allowing for simpler implementations.


## Proposal


### Extended response to `/sync`

This MSC proposes the addition of an `unread_count` parameter in the `Joined
Room` section of
[`/sync`](https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-sync)
Copy link

Choose a reason for hiding this comment

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

Did you mean unread_notifications.unread_count?

responses.

The value of this parameter is a count of every unread event (see below for a
list of criteria an event needs to match to be marked unread) since the latest
read receipt (i.e. the latest `m.read` read marker) for the given user in the
given room. If no read receipt exists for this user in this room, then the value
of the parameter is a count of every unread event since that user joined it.
babolivier marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Considering the case when the user joined, left, and joined again, all without ever reading the timeline. Should the number of unread messages be counted from the first or from the latest join?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there are no implicit read receipts, shouldn't that be the number of unread messages since the last event sent by the user, or something like that?


In case of a mismatch between this count and the value of `notification_count`
in the `Unread Notification Counts` section, clients should use the
`unread_count`.


### Unread events

An event should be counted in the unread count only if it matches at least one
of the following criteria:

* include a non-empty `body` field of type string, in its content
* be a state event which type is one of:
* `m.room.name`
babolivier marked this conversation as resolved.
Show resolved Hide resolved
* `m.room.topic`
* `m.room.avatar`
* `m.room.tombstone`
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/matrix-org/matrix-react-sdk/blob/84af29a7f1a5e4d4a8f3408f0f741293f10be010/src/components/views/rooms/EventTile.tsx#L1186 (as called from https://github.com/matrix-org/matrix-react-sdk/blob/develop/src/Unread.ts#L32) has another interesting addition - it counts an event as unread if it's m.room.create with non-empty predecessor. To be honest, I don't quite understand the rationale behind that and am just documenting the case.

* be an encrypted message (i.e. have the `m.room.encrypted` type)
babolivier marked this conversation as resolved.
Show resolved Hide resolved

Additionally, an event should _not_ be counted in the unread count if it matches
at least one of the following criteria, even if it is otherwise eligible to be
included in the count:

* include a `m.relates_to` parameter in its content that includes a `rel_type`
parameter, which value is `m.replace`. This matches the definition of an edit
in [MSC2676](https://github.com/matrix-org/matrix-doc/pull/2676).
* have the type `m.room.message`, no `state_key`, and include a `msgtype`
parameter in its content which value is `m.notice`.
Comment on lines +55 to +56
Copy link
Member

Choose a reason for hiding this comment

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

What if an m.notice event has state_key? Officially that would make it a (spec-incompliant) state event; and since it's not matching any type from the list above, it's not icluded in the unread count anyway. Seems like "no state_key" condition is superfluous here.

Copy link
Member

Choose a reason for hiding this comment

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

In addition to m.notice, it's worth excluding m.key.verification.* messages (this can only be done on the client side, of course).


Finally, a redaction to an event that was marked as unread should exclude that
event from the unread count.

When calculating the unread count for a given user in a given room, events sent
by the requesting user in the room should be ignored.

If the event is an encrypted message, clients should decrypt it and apply the
rules above to make adjustments to the unread count sent by the homeserver.


## Potential issues
babolivier marked this conversation as resolved.
Show resolved Hide resolved

This MSC mentions edits, which are specified in
[MSC2676](https://github.com/matrix-org/matrix-doc/pull/2676). Therefore, it is
unclear whether this MSC can be merged before MSC2676.
Comment on lines +70 to +72
Copy link
Member

Choose a reason for hiding this comment

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

MSC2676 is now merged.


Unlike notifications, it is not possible to not have the homeserver provide an
unread count for a given room. A way to do this will be described in a separate
MSC.

A known limitation of this proposal is that it does not cover highlights: a message
containing text that is supposed to highlight (i.e. that should impact a
`highlight_count` counter in sync responses) will be counted in the same way as
a message that does not highlight. This means that clients cannot rely on the
`unread_count` field described in this proposal to decide whether there is a
highlighting message in a room.


## Alternatives

As mentioned in the introduction of this proposal,
[MSC2625](https://github.com/matrix-org/matrix-doc/pull/2625) proposes an
alternative implementation of this feature using push rules. However, given the
complexity of push rules and that MSC2625 requires to implement a new behaviour
for the `mark_unread` action, using push rules for this feature doesn't seem to
be adding much values, and seems to add unnecessary complexity to its
implementation.


## Unstable prefix

While this feature is in development, the following names will be in use:

| Proposed final name | Name while in development |
| --- | --- |
| `unread_count` | `org.matrix.msc2654.unread_count` |