Added stream_data.get_name().

This function returns the stream's actual name, if we can get it;
otherwise, it's the identity function.

(imported from commit 7a981adba9632d6c6eba54cb6514a9226d1e83e8)
This commit is contained in:
Steve Howell 2013-08-19 13:25:44 -04:00
parent eccd7e90ab
commit 18857f6601
2 changed files with 16 additions and 0 deletions

View File

@ -75,6 +75,19 @@ exports.get_invite_only = function (stream_name) {
return sub.invite_only;
};
exports.get_name = function (stream_name) {
// This returns the actual name of a stream if we are subscribed to
// it (i.e "Denmark" vs. "denmark"), while falling thru to
// stream_name if we don't have a subscription. (Stream names
// are case-insensitive, but we try to display the actual name
// when we know it.)
var sub = exports.get_sub(stream_name);
if (sub === undefined) {
return stream_name;
}
return sub.name;
};
return exports;
}());

View File

@ -36,4 +36,7 @@ var stream_data = require('js/stream_data.js');
assert(stream_data.get_invite_only('social'));
assert.equal(stream_data.get_color('social'), 'red');
assert.equal(stream_data.get_name('denMARK'), 'Denmark');
assert.equal(stream_data.get_name('unknown Stream'), 'unknown Stream');
}());