mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
stream_data: Add get_subscriber_count() function.
This commit is contained in:
@@ -452,3 +452,32 @@ var people = global.people;
|
||||
assert(!stream_data.get_sub('Canada'));
|
||||
assert(!stream_data.get_sub_by_id(canada.stream_id));
|
||||
}());
|
||||
|
||||
(function test_get_subscriber_count() {
|
||||
var india = {
|
||||
stream_id: 102,
|
||||
name: 'India',
|
||||
subscribed: true,
|
||||
};
|
||||
stream_data.clear_subscriptions();
|
||||
assert.equal(stream_data.get_subscriber_count('India'), undefined);
|
||||
stream_data.add_sub('India', india);
|
||||
assert.equal(stream_data.get_subscriber_count('India'), 0);
|
||||
|
||||
var fred = {
|
||||
email: 'fred@zulip.com',
|
||||
full_name: 'Fred',
|
||||
user_id: 101,
|
||||
};
|
||||
people.add(fred);
|
||||
stream_data.add_subscriber('India', 102);
|
||||
assert.equal(stream_data.get_subscriber_count('India'), 1);
|
||||
var george = {
|
||||
email: 'george@zulip.com',
|
||||
full_name: 'George',
|
||||
user_id: 103,
|
||||
};
|
||||
people.add(george);
|
||||
stream_data.add_subscriber('India', 103);
|
||||
assert.equal(stream_data.get_subscriber_count('India'), 2);
|
||||
}());
|
||||
|
||||
@@ -137,6 +137,18 @@ exports.update_subscribers_count = function (sub) {
|
||||
sub.subscriber_count = count;
|
||||
};
|
||||
|
||||
exports.get_subscriber_count = function (stream_name) {
|
||||
var sub = exports.get_sub_by_name(stream_name);
|
||||
if (sub === undefined) {
|
||||
blueslip.warn('We got a get_subscriber_count count call for a non-existent stream.');
|
||||
return;
|
||||
}
|
||||
if (!sub.subscribers) {
|
||||
return 0;
|
||||
}
|
||||
return sub.subscribers.num_items();
|
||||
};
|
||||
|
||||
exports.render_stream_description = function (sub) {
|
||||
if (sub.description) {
|
||||
sub.rendered_description = marked(sub.description).replace('<p>', '').replace('</p>', '');
|
||||
|
||||
Reference in New Issue
Block a user