Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add a small indicator for when a new event is pinned #1486

Merged
merged 6 commits into from
Nov 7, 2017

Conversation

turt2live
Copy link
Member

Description

This PR adds a small indicator when there are "unread" pins. The implementation relies on room account data to store the last pinned events state event that was seen. When the user opens the panel, the room account data is updated. The indicator will not appear for cases when all pins are removed.

The indicator's behaviour and look is heavily influenced from Discord and Slack which have similar features.

Required PRs

What it looks like

image
image

Signed-off-by: Travis Ralston <travpc@gmail.com>
lastReadEvent = readPinsEvent.getContent().last_read_id;
}

if (lastReadEvent !== pinnedEvents.getId()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't make sure that the lastReadEvent is ahead in the DAG relative to pinnedEvents.getId(). This could lead to two clients (i.e. clients with potentially differing state event data) fighting over which pinned message is really the last one read.

Copy link
Member Author

Choose a reason for hiding this comment

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

What's the best way to check for this? Just using .getTs()?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can't technically rely on the timestamp to compare events because it might not be accurate. If we want to do this with some guarantee of the event ID always "increasing" in the timeline, we'd need server-side support. This would look something like m.fully_read - the read marker.

As there's no generic API for setting a similar m.pinned_messages.fully_read or whatever, this would require server-side changes.

But if we assume that the TS on the events are accurate and comparable (which they probably are), then sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

m.fully_read doesn't seem to appear in the spec at all. Is it something that already exists or is that part of the server-side implementation request?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

(which is matrix-org/matrix-spec-proposals#910)

I'll take a look and give it a shot I suppose.

@ara4n
Copy link
Member

ara4n commented Nov 3, 2017

Just to recap (as I had to think quite hard about this): the problem is that we store the ID of the most recent pinned-message state-event in account_data. However, an older client might end up refreshing the UI whilst using a stale copy of room state, and so fight over what the 'most recent' pinned-message actually is. @lukebarnard1 - well done for spotting this edge case; I would have definitely have missed it :)

I wonder whether there's a simpler solution though than mandating yet another new server API: how about just storing all of the event IDs of the pinned-message state events which the user has explicitly read in account_data. This is unlikely ever to get particularly big, but then whenever the client sees a pinned messages event whose ID isn't in the list, we declare there to be unread pinned messages?

Alternatively, the 'right' server API might be one that @erikjohnston has been rumbling about forever: an entirely generic API where you can just ask the server whether $event_id1 precedes $event_id2 or not (and let the server worry about the DAG calculations). This would then let us break up the fight (and could also be useful on handling all sorts of other edge cases like the direction of RM arrows).

OR, we could ignore this as an extreme edge case; comment it; merge it; and see how much it bites us (if ever) in reality.

@turt2live
Copy link
Member Author

The list shouldn't get particularly nasty, although it would be ever-increasing. 65kb is a large amount of wiggle room, although I'd be concerned about rooms which enjoy pinning constantly (I've seen this happen on other platforms often enough for it to be concerning).

Would checking origin_server_ts be a suitable workaround pending that awesome generic API that I also want?

@ara4n
Copy link
Member

ara4n commented Nov 4, 2017

checking origin_server_ts is just evil evil evil. i'd prefer to just ignore the race potential and flag it as a known race for now and merge this (as without it pins are of questionable use).

Also, for pins to work, it has to have some kind of UI to tell you when a room actually has pinned messages or not (whether not you have actually read them).

@turt2live
Copy link
Member Author

With this, joining a new room will display an indicator as you haven't read them yet. What would the UX be for a persistent notification?

Merging with the race sounds like a bad idea to me, and it's probably best to just make the event an array for now and hope that people don't pin a few hundred thousand times in the room. I'll whip this up in a bit.

Signed-off-by: Travis Ralston <travpc@gmail.com>
@turt2live
Copy link
Member Author

@ara4n I've pushed the change for storing the events as an array.

Would the following make sense for UX?

  • Red indicator - unread pins
  • Gray indicator - pins are available
  • No indicator - no pins

Signed-off-by: Travis Ralston <travpc@gmail.com>
@ara4n
Copy link
Member

ara4n commented Nov 4, 2017

sgtm

@turt2live
Copy link
Member Author

@ara4n and the indicator is now implemented for "pins exist". Requires CSS PR element-hq/element-web#5511

Looks like this:
image
image

Signed-off-by: Travis Ralston <travpc@gmail.com>
@ara4n
Copy link
Member

ara4n commented Nov 7, 2017

lgtm - thanks!

@ara4n ara4n merged commit e14e0bf into matrix-org:develop Nov 7, 2017
@turt2live turt2live deleted the travis/pinned-notice branch August 22, 2018 01:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants