zulip/static/js/notifications_bar.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

var notifications_bar = (function () {
var exports = {};
var disabled = false; // true when the bar should be hidden (eg, it's blocking the composebox)
var displayed = false; // true when the bar is supposedly displayed (ignoring disabled-ness)
var bar_selector = "#notifications-bar"; // the selector jQuery can use to pick the notifications bar
var area_selector = "#notifications-area"; // the selector jQuery can use to pick the container
function show() {
if (disabled) {
return; // we should never show the bar when disabled
}
if (!displayed) {
// If the bar wasn't already displayed, simply show it
$(bar_selector).text("More messages below").slideDown(50);
displayed = true; // we need to set this flag
}
}
// Hide the notifications bar
function hide() {
if (!displayed) {
return; // don't unnecessarily add to the element's fx queue
}
displayed = false;
$(bar_selector).slideUp(50);
}
// If there's a custom message, or if the last message is off the bottom of the
// screen, then show the notifications bar.
Clean up code for unread counts and notifications. The core simplification here is that zephyr.js no longer has: * the global home_unread_messages * the function unread_in_current_view() [which used the global] The logic that used to be in zephyr is now in its proper home of unread.js, which has these changes: * the structure returned from unread.get_counts() includes a new member called unread_in_current_view * there's a helper function unread.num_unread_current_messages() Deprecating zephyr.unread_in_current_view() affected two callers: * notifications.update_title_count() * notifications_bar.update() The above functions used to call back to zephyr to get counts, but there was no nice way to enforce that they were getting counts at the right time in the code flow, because they depended on functions like process_visible_unread_messages() to orchestrate updating internal unread counts before pushing out counts to the DOM. Now both of those function take a parameter with the unread count, and we then had to change all of their callers appropriately. This went hand in hand with another goal, which is that we want all the unread-counts logic to funnel though basically one place, which is zephyr.update_unread_counts(). So now that function always calls notifications_bar.update() [NEW] as well as calling into the modules unread.js, stream_list.js, and notifications.js [OLD]. Adding the call to notifications_bar.update() in update_unread_counts() made it so that some other places in the code no longer needed to call notifications_bar.update(), so you'll see some lines of code removed. There are also cases where notifications.update_title_count() was called redundantly, since the callers were already reaching update_unread_counts() via other calls. Finally, in ui.resizehandler, you'll see a simple case where the call to notifications_bar.update() is preceded by an explicit call to unread.get_counts(). (imported from commit ce84b9c8076c1f9bb20a61209913f0cb0dae098c)
2013-06-05 21:04:06 +02:00
exports.update = function (num_unread) {
if (!viewport.bottom_message_visible() && num_unread > 0) {
show();
} else {
hide();
}
};
// We disable the notifications bar if it overlaps with the composebox
exports.maybe_disable = function () {
if ($("#compose").offset().left + $("#compose").width() > $(area_selector).offset().left) {
disabled = true;
hide();
}
};
// Un-disable the notifications bar, then call the update function to see if it should be displayed
exports.enable = function () {
disabled = false;
exports.update();
};
return exports;
}());