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

Add function to determine who has read at least a given event #1625

Closed
wants to merge 2 commits into from

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Feb 28, 2021

@turt2live turt2live changed the title Add function to determine who has read at least a given event [WIP] Add function to determine who has read at least a given event Feb 28, 2021
@turt2live turt2live changed the title [WIP] Add function to determine who has read at least a given event Add function to determine who has read at least a given event Mar 1, 2021
@turt2live turt2live marked this pull request as ready for review March 1, 2021 23:26
@turt2live turt2live requested a review from a team March 1, 2021 23:30
Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

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

I'm being cautious on this, as I'd like to work out if there's any possible way to do less work to support the use case.

src/models/room.js Outdated Show resolved Hide resolved
const events = this.getLiveTimeline().getEvents(); // timelines are most recent last
let foundEvent = false;
const receiptIds = new Set();
for (let i = events.length - 1; i >= Math.max(0, events.length - maxEvents); i--) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This loop feels kind of wasteful given that TimelinePanel / MessagePanel already did a very similar scan to construct the EventTile... Anyway, mostly just an idle thought, as I guess you'd need to restructure lots of things for it to be more efficient.

* @param {number} maxEvents The maximum number of events to search within.
* @returns {string[]} A list of user IDs who have read the event.
*/
Room.prototype.getUsersWhoHaveRead = function(event, maxEvents) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you want this API to collect all users who have read the event? In the one caller so far, you actually only care if someone has read it (other than yourself), but the actual list of senders goes unused... Is there a plan to use it in the future?

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 largely the balance of usefulness and API scope. We could add a hasAnyoneRead function, but the react SDK would be the only consumer. In this approach, we're adding something theoretically useful for other applications, and maybe even ourselves if we decide to add a "who has read this" API.

Ideally this whole problem is solved by matrix rather than a loop in our code, but this is the first time we've needed a different kind of receipt calculation.

@turt2live turt2live requested a review from jryans March 2, 2021 18:06
Copy link
Collaborator

@jryans jryans left a comment

Choose a reason for hiding this comment

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

Okay, let's go with this for now.

@turt2live
Copy link
Member Author

This ultimately isn't used.

@turt2live turt2live closed this Mar 5, 2021
@turt2live turt2live deleted the travis/message-states branch March 5, 2021 17:56
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