mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
Revert to old mark as unread on view behavior.
Effectively reverts 185e865 and b67e52d. (imported from commit e9b95f1fd9e2ab7926f15910044e9e9879ea085f)
This commit is contained in:
@@ -41,7 +41,7 @@ var globals =
|
||||
+ ' scroll_to_selected get_private_message_recipient'
|
||||
+ ' load_old_messages'
|
||||
+ ' at_top_of_viewport at_bottom_of_viewport within_viewport'
|
||||
+ ' viewport restart_get_updates force_get_updates'
|
||||
+ ' process_visible_unread_messages viewport restart_get_updates force_get_updates'
|
||||
+ ' load_more_messages reset_load_more_status have_scrolled_away_from_top'
|
||||
+ ' maybe_scroll_to_selected recenter_pointer_on_display suppress_scroll_pointer_update'
|
||||
+ ' mark_current_list_as_read message_range message_in_table process_loaded_for_unread'
|
||||
|
||||
@@ -430,8 +430,8 @@ exports.activate = function (operators, opts) {
|
||||
var then_scroll = !preserve_pre_narrowing_screen_position;
|
||||
|
||||
narrowed_msg_list.select_id(then_select_id, {then_scroll: then_scroll,
|
||||
use_closest: true,
|
||||
mark_read: false});
|
||||
use_closest: true
|
||||
});
|
||||
|
||||
if (preserve_pre_narrowing_screen_position) {
|
||||
// Scroll so that the selected message is in the same
|
||||
@@ -565,8 +565,7 @@ exports.deactivate = function () {
|
||||
// view since leaving it the old selected id might no longer be there
|
||||
home_msg_list.select_id(home_msg_list.selected_id(), {
|
||||
then_scroll: false,
|
||||
use_closest: true,
|
||||
mark_read: false
|
||||
use_closest: true
|
||||
});
|
||||
// We scroll the user back to exactly the offset from the selected
|
||||
// message that he was at the time that he narrowed.
|
||||
|
||||
@@ -30,6 +30,11 @@ exports.initialize = function () {
|
||||
$.each(notice_memory, function (index, notice_mem_entry) {
|
||||
notice_mem_entry.obj.cancel();
|
||||
});
|
||||
|
||||
// Update many places on the DOM to reflect unread
|
||||
// counts.
|
||||
process_visible_unread_messages();
|
||||
|
||||
}).blur(function () {
|
||||
window_has_focus = false;
|
||||
});
|
||||
@@ -270,11 +275,9 @@ function message_is_notifiable(message) {
|
||||
}
|
||||
|
||||
exports.received_messages = function (messages) {
|
||||
var vp = viewport.message_viewport_info();
|
||||
|
||||
$.each(messages, function (index, message) {
|
||||
if (!message_is_notifiable(message)) return;
|
||||
if (viewport.message_is_visible(vp, message)) return;
|
||||
if (!unread.message_unread(message)) return;
|
||||
|
||||
if (page_params.desktop_notifications_enabled &&
|
||||
browser_desktop_notifications_on()) {
|
||||
|
||||
@@ -289,6 +289,7 @@ $(function () {
|
||||
stream_li.addClass('active-filter');
|
||||
}
|
||||
rebuild_recent_subjects(op_stream[0], subject);
|
||||
process_visible_unread_messages();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -675,6 +675,11 @@ $(function () {
|
||||
} else if (!have_scrolled_away_from_top) {
|
||||
have_scrolled_away_from_top = true;
|
||||
}
|
||||
// When the window scrolls, it may cause some messages to
|
||||
// enter the screen and become read. Calling
|
||||
// process_visible_unread_messages will update necessary
|
||||
// data structures and DOM elements.
|
||||
setTimeout(process_visible_unread_messages, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,6 +690,7 @@ $(function () {
|
||||
}
|
||||
|
||||
$(window).scroll($.throttle(50, function (e) {
|
||||
process_visible_unread_messages();
|
||||
scroll_finish();
|
||||
}));
|
||||
|
||||
|
||||
@@ -106,6 +106,34 @@ exports.message_is_visible = function (vp, message) {
|
||||
return (row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height);
|
||||
};
|
||||
|
||||
exports.visible_messages = function () {
|
||||
var selected = current_msg_list.selected_message();
|
||||
var vp = viewport.message_viewport_info();
|
||||
var top = vp.visible_top;
|
||||
var height = vp.visible_height;
|
||||
|
||||
// Being simplistic about this, the smallest message is 30 px high.
|
||||
var selected_row = rows.get(current_msg_list.selected_id(), current_msg_list.table_name);
|
||||
var num_neighbors = Math.floor(height / 30);
|
||||
var candidates = $.merge(selected_row.prevAll("tr.message_row[zid]:lt(" + num_neighbors + ")"),
|
||||
selected_row.nextAll("tr.message_row[zid]:lt(" + num_neighbors + ")"));
|
||||
|
||||
var visible_messages = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i<candidates.length; i++) {
|
||||
var row = $(candidates[i]);
|
||||
var row_offset = row.offset();
|
||||
var row_height = row.height();
|
||||
// Mark very tall messages as read once we've gotten past them
|
||||
if ((row_height > height && row_offset.top > top) || within_viewport(row_offset, row_height)) {
|
||||
var message = current_msg_list.get(rows.id(row));
|
||||
visible_messages.push(message);
|
||||
}
|
||||
}
|
||||
return visible_messages;
|
||||
};
|
||||
|
||||
exports.scrollTop = function viewport_scrollTop () {
|
||||
return jwindow.scrollTop.apply(jwindow, arguments);
|
||||
};
|
||||
|
||||
@@ -308,6 +308,23 @@ function process_read_messages(messages) {
|
||||
update_unread_counts();
|
||||
}
|
||||
|
||||
// If we ever materially change the algorithm for this function, we
|
||||
// may need to update notifications.received_messages as well.
|
||||
function process_visible_unread_messages(update_cursor) {
|
||||
// For any messages visible on the screen, make sure they have been marked
|
||||
// as read.
|
||||
if (! notifications.window_has_focus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var visible_messages = viewport.visible_messages();
|
||||
var mark_as_read = $.grep(visible_messages, unread.message_unread);
|
||||
|
||||
if (mark_as_read.length > 0) {
|
||||
process_read_messages(mark_as_read);
|
||||
}
|
||||
}
|
||||
|
||||
function mark_read_between(msg_list, start_id, end_id) {
|
||||
var msgs_in_range = message_range(msg_list, start_id, end_id);
|
||||
var unread_msgs = $.grep(msgs_in_range, unread.message_unread);
|
||||
@@ -684,6 +701,7 @@ function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
|
||||
|
||||
new_messages = $.map(new_messages, add_message_metadata);
|
||||
add_messages(new_messages, msg_list, messages_are_new);
|
||||
process_visible_unread_messages();
|
||||
compose.update_faded_messages();
|
||||
},
|
||||
error: function (xhr) {
|
||||
@@ -864,6 +882,7 @@ function get_updates_success(data) {
|
||||
respond_to_cursor = saved_respond_to_cursor;
|
||||
}
|
||||
|
||||
process_visible_unread_messages();
|
||||
notifications.received_messages(messages);
|
||||
compose.update_faded_messages();
|
||||
stream_list.update_streams_sidebar();
|
||||
|
||||
@@ -6,6 +6,7 @@ var common = require('../common.js').common;
|
||||
// standalone
|
||||
// Silence jslint errors about the global
|
||||
/*global keep_pointer_in_view: true */
|
||||
/*global process_visible_unread_messages: true */
|
||||
|
||||
function send_with_content(content) {
|
||||
common.send_message('stream', {
|
||||
@@ -78,7 +79,8 @@ casper.then(function () {
|
||||
// Changing the scroll position in phantomjs doesn't seem to trigger on-scroll
|
||||
// handlers, so unread messages are not handled
|
||||
casper.page.scrollPosition = {top: ypos, left: 0};
|
||||
casper.evaluate(function () { keep_pointer_in_view(); });
|
||||
casper.evaluate(function () { keep_pointer_in_view();
|
||||
process_visible_unread_messages(); });
|
||||
}
|
||||
var i = 0;
|
||||
scroll_to(0);
|
||||
|
||||
Reference in New Issue
Block a user