mirror of https://github.com/zulip/zulip.git
stream sidebar: Clean up unsubscribe logic.
From subs.js we don't redundantly try to remove an element from ths sidebar; we just trigger the event. In stream_list.js we continue to remove the element from the DOM, and we also remove the widget from our internal Dict of sidebar rows, so that if we re-subscribe, we know we'll automatically re-build the widget from the template and the latest data from stream_data.js.
This commit is contained in:
parent
d867cba90b
commit
f3373d62e1
|
@ -51,6 +51,16 @@ exports.stream_sidebar = (function () {
|
|||
return self.rows.has(stream_id);
|
||||
};
|
||||
|
||||
self.remove_row = function (stream_id) {
|
||||
var widget = self.rows.get(stream_id);
|
||||
if (!widget) {
|
||||
blueslip.warn('Cannot remove stream id ' + stream_id);
|
||||
return;
|
||||
}
|
||||
widget.remove();
|
||||
self.rows.del(stream_id);
|
||||
};
|
||||
|
||||
return self;
|
||||
}());
|
||||
|
||||
|
@ -249,6 +259,10 @@ function build_stream_sidebar_row(sub) {
|
|||
return list_item;
|
||||
};
|
||||
|
||||
self.remove = function () {
|
||||
list_item.remove();
|
||||
};
|
||||
|
||||
exports.stream_sidebar.set_row(sub.stream_id, self);
|
||||
}
|
||||
|
||||
|
@ -348,10 +362,6 @@ exports.set_pm_conversation_count = function (conversation, count) {
|
|||
update_count_in_dom(count_span, value_span, count);
|
||||
};
|
||||
|
||||
exports.remove_narrow_filter = function (name, type) {
|
||||
get_filter_li(type, name).remove();
|
||||
};
|
||||
|
||||
function rebuild_recent_topics(stream) {
|
||||
// TODO: Call rebuild_recent_topics less, not on every new
|
||||
// message.
|
||||
|
@ -510,8 +520,7 @@ $(function () {
|
|||
});
|
||||
|
||||
$(document).on('subscription_remove_done.zulip', function (event) {
|
||||
var stream_name = event.sub.name;
|
||||
exports.remove_narrow_filter(stream_name, 'stream');
|
||||
exports.stream_sidebar.remove_row(event.sub.stream_id);
|
||||
// We need to make sure we resort if the removed sub gets added again
|
||||
previous_sort_order = undefined;
|
||||
previous_unpinned_order = undefined;
|
||||
|
|
|
@ -442,8 +442,6 @@ exports.mark_sub_unsubscribed = function (sub) {
|
|||
// We don't know about this stream
|
||||
return;
|
||||
} else if (sub.subscribed) {
|
||||
stream_list.remove_narrow_filter(sub.name, 'stream');
|
||||
|
||||
stream_data.unsubscribe_myself(sub);
|
||||
|
||||
var button = button_for_sub(sub);
|
||||
|
|
Loading…
Reference in New Issue