mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
refactoring: Let activity.js manage its own unread counts.
This change breaks a needless dependency of activity.js on stream_list.js.
This commit is contained in:
@@ -51,6 +51,50 @@ exports.presence_info = {};
|
|||||||
|
|
||||||
var huddle_timestamps = new Dict();
|
var huddle_timestamps = new Dict();
|
||||||
|
|
||||||
|
function update_count_in_dom(count_span, value_span, count) {
|
||||||
|
if (count === 0) {
|
||||||
|
count_span.hide();
|
||||||
|
if (count_span.parent().hasClass("user_sidebar_entry")) {
|
||||||
|
count_span.parent(".user_sidebar_entry").removeClass("user-with-count");
|
||||||
|
} else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
||||||
|
count_span.parent(".group-pms-sidebar-entry").removeClass("group-with-count");
|
||||||
|
}
|
||||||
|
value_span.text('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
count_span.show();
|
||||||
|
|
||||||
|
if (count_span.parent().hasClass("user_sidebar_entry")) {
|
||||||
|
count_span.parent(".user_sidebar_entry").addClass("user-with-count");
|
||||||
|
} else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
||||||
|
count_span.parent(".group-pms-sidebar-entry").addClass("group-with-count");
|
||||||
|
}
|
||||||
|
value_span.text(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_filter_li(name) {
|
||||||
|
if (name.indexOf(",") < 0) {
|
||||||
|
return $("li.user_sidebar_entry[data-email='" + name + "']");
|
||||||
|
} else {
|
||||||
|
return $("li.group-pms-sidebar-entry[data-emails='" + name + "']");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_count(name, count) {
|
||||||
|
var count_span = get_filter_li(name).find('.count');
|
||||||
|
var value_span = count_span.find('.value');
|
||||||
|
update_count_in_dom(count_span, value_span, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.update_dom_with_unread_counts = function (counts) {
|
||||||
|
// counts is just a data object that gets calculated elsewhere
|
||||||
|
// Our job is to update some DOM elements.
|
||||||
|
|
||||||
|
counts.pm_count.each(function (count, person) {
|
||||||
|
set_count(person, count);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.process_loaded_messages = function (messages) {
|
exports.process_loaded_messages = function (messages) {
|
||||||
var need_resize = false;
|
var need_resize = false;
|
||||||
@@ -320,7 +364,7 @@ exports.update_huddles = function () {
|
|||||||
|
|
||||||
_.each(huddles, function (huddle) {
|
_.each(huddles, function (huddle) {
|
||||||
var count = unread.num_unread_for_person(huddle);
|
var count = unread.num_unread_for_person(huddle);
|
||||||
stream_list.set_presence_list_count(huddle, count);
|
set_count(huddle, count);
|
||||||
});
|
});
|
||||||
|
|
||||||
show_huddles();
|
show_huddles();
|
||||||
|
|||||||
@@ -151,8 +151,6 @@ function iterate_to_find(selector, name_to_find, context) {
|
|||||||
return found ? $(found) : $();
|
return found ? $(found) : $();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Now that the unread count functions support the user sidebar
|
|
||||||
// as well, we probably should consider moving them to a different file.
|
|
||||||
function get_filter_li(type, name) {
|
function get_filter_li(type, name) {
|
||||||
if (type === 'stream') {
|
if (type === 'stream') {
|
||||||
var sub = stream_data.get_sub(name);
|
var sub = stream_data.get_sub(name);
|
||||||
@@ -307,10 +305,6 @@ function update_count_in_dom(count_span, value_span, count) {
|
|||||||
count_span.hide();
|
count_span.hide();
|
||||||
if (count_span.parent().hasClass("subscription_block")) {
|
if (count_span.parent().hasClass("subscription_block")) {
|
||||||
count_span.parent(".subscription_block").removeClass("stream-with-count");
|
count_span.parent(".subscription_block").removeClass("stream-with-count");
|
||||||
} else if (count_span.parent().hasClass("user_sidebar_entry")) {
|
|
||||||
count_span.parent(".user_sidebar_entry").removeClass("user-with-count");
|
|
||||||
} else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
|
||||||
count_span.parent(".group-pms-sidebar-entry").removeClass("group-with-count");
|
|
||||||
}
|
}
|
||||||
value_span.text('');
|
value_span.text('');
|
||||||
return;
|
return;
|
||||||
@@ -320,10 +314,6 @@ function update_count_in_dom(count_span, value_span, count) {
|
|||||||
|
|
||||||
if (count_span.parent().hasClass("subscription_block")) {
|
if (count_span.parent().hasClass("subscription_block")) {
|
||||||
count_span.parent(".subscription_block").addClass("stream-with-count");
|
count_span.parent(".subscription_block").addClass("stream-with-count");
|
||||||
} else if (count_span.parent().hasClass("user_sidebar_entry")) {
|
|
||||||
count_span.parent(".user_sidebar_entry").addClass("user-with-count");
|
|
||||||
} else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
|
||||||
count_span.parent(".group-pms-sidebar-entry").addClass("group-with-count");
|
|
||||||
}
|
}
|
||||||
value_span.text(count);
|
value_span.text(count);
|
||||||
}
|
}
|
||||||
@@ -413,10 +403,6 @@ function animate_mention_changes(new_mention_count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.set_presence_list_count = function (person, count) {
|
|
||||||
set_count("private", person, count);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.update_dom_with_unread_counts = function (counts) {
|
exports.update_dom_with_unread_counts = function (counts) {
|
||||||
// counts is just a data object that gets calculated elsewhere
|
// counts is just a data object that gets calculated elsewhere
|
||||||
// Our job is to update some DOM elements.
|
// Our job is to update some DOM elements.
|
||||||
@@ -434,7 +420,6 @@ exports.update_dom_with_unread_counts = function (counts) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
counts.pm_count.each(function (count, person) {
|
counts.pm_count.each(function (count, person) {
|
||||||
exports.set_presence_list_count(person, count);
|
|
||||||
exports.set_pm_conversation_count(person, count);
|
exports.set_pm_conversation_count(person, count);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ exports.update_unread_counts = function () {
|
|||||||
// Side effects from here down:
|
// Side effects from here down:
|
||||||
// This updates some DOM elements directly, so try to
|
// This updates some DOM elements directly, so try to
|
||||||
// avoid excessive calls to this.
|
// avoid excessive calls to this.
|
||||||
|
activity.update_dom_with_unread_counts(res);
|
||||||
stream_list.update_dom_with_unread_counts(res);
|
stream_list.update_dom_with_unread_counts(res);
|
||||||
notifications.update_title_count(res.home_unread_messages);
|
notifications.update_title_count(res.home_unread_messages);
|
||||||
notifications.update_pm_count(res.private_message_count);
|
notifications.update_pm_count(res.private_message_count);
|
||||||
|
|||||||
Reference in New Issue
Block a user