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

message_list_data: Store message_list_data objects created locally. #22410

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amanagr
Copy link
Member

@amanagr amanagr commented Jul 7, 2022

For #15131

@timabbott here is the list of events for which we will have to update the message_list_data objects we have stored locally:

  • muted_topics
  • muted_users
  • stream update/create/delete events
  • delete_message
  • update_message events (stream/topic change)

Does the approach look good to you? I implemented what an update would look like for muted_topics.

@amanagr amanagr marked this pull request as draft July 7, 2022 10:29
@timabbott timabbott requested a review from ryanreh99 July 7, 2022 17:53
/* `excludes_muted_topics` is not included in the key since we can determine `excludes_muted_topics`
from the filter itself. So, `excludes_muted_topics` doesn't vary with the filter.
*/
const data_key = JSON.stringify(filter._operators);
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I don't think this will be a reliable key, since I'm not sure the order will be consistent. I wonder if we can use the "narrow URL" generated by hash_util as a unique string for a view -- we'd need to take some care to just have a fixed sort order in which operators are emitted into those URLs (E.g. "stream" always before "topic", which I think we might already do? Not 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.

We use the same operators to create the hash. The order in the hash is the same as in the operators list.

See hash_util.operators_to_hash():

        for (const elem of operators) {
            // Support legacy tuples.
            const operator = elem.operator;
            const operand = elem.operand;

            const sign = elem.negated ? "-" : "";
            hash +=
                "/" +
                sign +
                internal_url.encodeHashComponent(operator) +
                "/" +
                encode_operand(operator, operand);
        }

@@ -516,4 +517,5 @@ export function remove_messages(message_ids) {
}
recent_senders.update_topics_of_deleted_message_ids(message_ids);
recent_topics_ui.update_topics_of_deleted_message_ids(message_ids);
message_list_data.remove_message_ids(message_ids);
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This call somewhat duplicates the all_messages_data.remove(message_ids); block at the top of this function.

I think a better approach here might be (1) To add an attribute on MessageListData or something for whether the list is currently rendered, and (2) replace the loop at the top of this function with something conceptually like (I've not thought about whether the generic loop function is the right interface):

message_list_data.for_each((list_data) => list_data.remove(message_ids));

And (3) we'd extend that .remove() function to, if it's rendered, call list.remove_and_rerender() instead.

I'm not sure what the cleanest approach would be, but the overall goal would be we'd be refactoring functions like this to just have a "Update all the message lists" block. I suppose that could end up looking like this; might be cleaner than the idea I suggested above:

message_list_data.for_each((list_data) => {
    if (list_data.is_currently_rendered) {
        list_data.list.remove_and_rerender(message_ids);
    } else {
        list_data.remove(message_ids));
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good!

@zulipbot
Copy link
Member

Heads up @amanagr, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants