mirror of https://github.com/zulip/zulip.git
Don't mutate global recent_subjects when creating subject sidebar.
Create our own objects for handlebars, so that we can add transient flags like is_zero without worrying about side effects to other code. (imported from commit b351a369cb3f36233e108e270c7abdd4ab8c5860)
This commit is contained in:
parent
ec1c82d6d7
commit
6b8013c631
|
@ -187,18 +187,26 @@ function rebuild_recent_subjects(stream, subject) {
|
||||||
var stream_li = get_filter_li('stream', stream);
|
var stream_li = get_filter_li('stream', stream);
|
||||||
var subjects = recent_subjects.get(stream) || [];
|
var subjects = recent_subjects.get(stream) || [];
|
||||||
var active_orig_subject = subject;
|
var active_orig_subject = subject;
|
||||||
var display_subjects = _.filter(subjects, function (subject_obj, idx) {
|
|
||||||
var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject);
|
|
||||||
subject_obj.unread = num_unread;
|
|
||||||
subject_obj.is_zero = num_unread === 0;
|
|
||||||
|
|
||||||
|
var display_subjects = [];
|
||||||
|
|
||||||
|
_.each(subjects, function (subject_obj, idx) {
|
||||||
if (subject === subject_obj.canon_subject) {
|
if (subject === subject_obj.canon_subject) {
|
||||||
active_orig_subject = subject_obj.subject;
|
active_orig_subject = subject_obj.subject;
|
||||||
}
|
}
|
||||||
subject_obj.url = narrow.by_stream_subject_uri(stream, subject_obj.subject);
|
|
||||||
|
var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject);
|
||||||
|
|
||||||
// Show the most recent subjects, as well as any with unread messages
|
// Show the most recent subjects, as well as any with unread messages
|
||||||
return idx < max_subjects || subject_obj.unread > 0;
|
if (idx < max_subjects || num_unread > 0) {
|
||||||
|
var display_subject = {
|
||||||
|
subject: subject_obj.subject,
|
||||||
|
unread: num_unread,
|
||||||
|
is_zero: num_unread === 0,
|
||||||
|
url: narrow.by_stream_subject_uri(stream, subject_obj.subject)
|
||||||
|
};
|
||||||
|
display_subjects.push(display_subject);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream_li.append(templates.render('sidebar_subject_list',
|
stream_li.append(templates.render('sidebar_subject_list',
|
||||||
|
|
Loading…
Reference in New Issue