refactor: Call peer_data.get_subscriber_count().

We are trying to move away from having the
subscriber count on the sub.

This commit handles the easy one-liners
in the JS code.
This commit is contained in:
Steve Howell
2021-01-21 14:55:49 +00:00
committed by Tim Abbott
parent 5babe54310
commit dc9b4de05f
4 changed files with 21 additions and 16 deletions

View File

@@ -2,15 +2,10 @@
const render_message_view_header = require("../templates/message_view_header.hbs");
const peer_data = require("./peer_data");
const rendered_markdown = require("./rendered_markdown");
function get_sub_count(current_stream) {
const sub_count = current_stream.subscriber_count;
return sub_count;
}
function get_formatted_sub_count(current_stream) {
let sub_count = get_sub_count(current_stream);
function get_formatted_sub_count(sub_count) {
if (sub_count >= 1000) {
// parseInt() is used to floor the value of division to an integer
sub_count = Number.parseInt(sub_count / 1000, 10) + "k";
@@ -42,8 +37,9 @@ function make_message_view_header(filter) {
// the current user can access.
const current_stream = filter._sub;
message_view_header.rendered_narrow_description = current_stream.rendered_description;
message_view_header.sub_count = get_sub_count(current_stream);
message_view_header.formatted_sub_count = get_formatted_sub_count(current_stream);
const sub_count = peer_data.get_subscriber_count(current_stream.stream_id);
message_view_header.sub_count = sub_count;
message_view_header.formatted_sub_count = get_formatted_sub_count(sub_count);
// the "title" is passed as a variable and doesn't get translated (nor should it)
message_view_header.sub_count_tooltip_text = i18n.t(
"__count__ users are subscribed to #__title__",

View File

@@ -3,7 +3,8 @@
const peer_data = require("./peer_data");
function display_pill(sub) {
return "#" + sub.name + ": " + sub.subscriber_count + " users";
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
return "#" + sub.name + ": " + sub_count + " users";
}
exports.create_item_from_stream_name = function (stream_name, current_items) {

View File

@@ -174,16 +174,22 @@ exports.update_subscribers_count = function (sub, just_subscribed) {
// If the streams overlay isn't open, we don't need to rerender anything.
return;
}
const stream_row = subs.row_for_stream_id(sub.stream_id);
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
if (
!sub.can_access_subscribers ||
(just_subscribed && sub.invite_only) ||
page_params.is_guest
) {
const rendered_sub_count = render_subscription_count(sub);
const rendered_sub_count = render_subscription_count({
can_access_subscribers: sub.can_access_subscribers,
subscriber_count: sub_count,
});
stream_row.find(".subscriber-count").expectOne().html(rendered_sub_count);
} else {
stream_row.find(".subscriber-count-text").expectOne().text(sub.subscriber_count);
stream_row.find(".subscriber-count-text").expectOne().text(sub_count);
}
};