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 view: Do not mark selected message as read on narrow. #16313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion frontend_tests/node_tests/message_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,45 @@ run_test("basics", (override) => {

assert.deepEqual(list.all_messages(), messages);

override($, "Event", (ev) => {
let message_select_events = [];
override($, "Event", (ev, opts) => {
assert.equal(ev, "message_selected.zulip");
message_select_events.push(opts);
});

assert.equal(list.selected_id(), -1);
const stub = make_stub();
list.view.rerender_preserving_scrolltop = stub.f;
// When narrow initially renders in narrow.update_selection.
list.select_id(60, {
use_closest: true,
force_rerender: true,
});

const expected_message_select_events = [
{
id: 60,
previously_selected_id: 60,
},
{
id: 60,
previously_selected_id: -1,
},
];
const actual_message_select_events = message_select_events.map((e) => ({
id: e.id,
previously_selected_id: e.previously_selected_id,
}));

// The render function is called which inturn calls selected_id,
// before the original message selection event takes place.
// Thus the event which contains the updated data is actually
// called first, instead of the original selected_id function call.
assert.equal(list.selected_id(), 60);
assert.equal(message_select_events.length, 2);
assert.deepEqual(actual_message_select_events, expected_message_select_events);
message_select_events = [];

list.select_id(50);

assert.equal(list.selected_id(), 50);
Expand Down
6 changes: 5 additions & 1 deletion static/js/message_scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ export function initialize() {
if (event.id === -1) {
return;
}
if (!event.mark_read || event.id === event.previously_selected_id) {
// Do not mark selected message read on initial narrow load.
return;
}

if (event.mark_read && event.previously_selected_id !== -1) {
if (event.previously_selected_id !== -1) {
// Mark messages between old pointer and new pointer as read
let messages;
if (event.id < event.previously_selected_id) {
Expand Down