Only remove a filter when unsubscribing if subscribed

Addionally, print out a blueslip error instead of dying
if a stream id is accessed when there is no stream to get

(imported from commit 0d6466ca79312a4fb9a235f313303ac5246afb35)
This commit is contained in:
Leo Franchi 2013-05-06 12:33:03 -04:00
parent 57d5bcf1f8
commit 5e70253bf9
1 changed files with 5 additions and 2 deletions

View File

@ -111,6 +111,10 @@ function update_table_stream_color(table, stream_name, color) {
exports.stream_id = function(stream_name) {
var sub = get_sub(stream_name);
if (sub === undefined) {
blueslip.error("Tried to get subs.stream_id for a stream user is not subscribed to!");
return 0;
}
return parseInt(sub.id, 10);
};
@ -324,12 +328,11 @@ function mark_subscribed(stream_name, attrs) {
function mark_unsubscribed(stream_name) {
var sub = get_sub(stream_name);
ui.remove_narrow_filter(stream_name, 'stream');
if (sub === undefined) {
// We don't know about this stream
return;
} else if (sub.subscribed) {
ui.remove_narrow_filter(stream_name, 'stream');
sub.subscribed = false;
button_for_sub(sub).text("Subscribe").addClass("btn-primary");
var settings = settings_for_sub(sub);