mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
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:
@@ -5,6 +5,7 @@ const {strict: assert} = require("assert");
|
|||||||
const {zrequire} = require("../zjsunit/namespace");
|
const {zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
|
|
||||||
|
const peer_data = zrequire("peer_data");
|
||||||
zrequire("stream_data");
|
zrequire("stream_data");
|
||||||
zrequire("stream_pill");
|
zrequire("stream_pill");
|
||||||
|
|
||||||
@@ -12,24 +13,25 @@ const denmark = {
|
|||||||
stream_id: 1,
|
stream_id: 1,
|
||||||
name: "Denmark",
|
name: "Denmark",
|
||||||
subscribed: true,
|
subscribed: true,
|
||||||
subscriber_count: 10,
|
|
||||||
};
|
};
|
||||||
const sweden = {
|
const sweden = {
|
||||||
stream_id: 2,
|
stream_id: 2,
|
||||||
name: "Sweden",
|
name: "Sweden",
|
||||||
subscribed: false,
|
subscribed: false,
|
||||||
subscriber_count: 30,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
peer_data.set_subscribers(denmark.stream_id, [1, 2, 3]);
|
||||||
|
peer_data.set_subscribers(sweden.stream_id, [1, 2, 3, 4, 5]);
|
||||||
|
|
||||||
const denmark_pill = {
|
const denmark_pill = {
|
||||||
stream_name: denmark.name,
|
stream_name: denmark.name,
|
||||||
stream_id: denmark.stream_id,
|
stream_id: denmark.stream_id,
|
||||||
display_value: "#" + denmark.name + ": " + denmark.subscriber_count + " users",
|
display_value: "#Denmark: 3 users",
|
||||||
};
|
};
|
||||||
const sweden_pill = {
|
const sweden_pill = {
|
||||||
stream_name: sweden.name,
|
stream_name: sweden.name,
|
||||||
stream_id: sweden.stream_id,
|
stream_id: sweden.stream_id,
|
||||||
display_value: "#" + sweden.name + ": " + sweden.subscriber_count + " users",
|
display_value: "#Sweden: 5 users",
|
||||||
};
|
};
|
||||||
|
|
||||||
const subs = [denmark, sweden];
|
const subs = [denmark, sweden];
|
||||||
|
|||||||
@@ -2,15 +2,10 @@
|
|||||||
|
|
||||||
const render_message_view_header = require("../templates/message_view_header.hbs");
|
const render_message_view_header = require("../templates/message_view_header.hbs");
|
||||||
|
|
||||||
|
const peer_data = require("./peer_data");
|
||||||
const rendered_markdown = require("./rendered_markdown");
|
const rendered_markdown = require("./rendered_markdown");
|
||||||
|
|
||||||
function get_sub_count(current_stream) {
|
function get_formatted_sub_count(sub_count) {
|
||||||
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);
|
|
||||||
if (sub_count >= 1000) {
|
if (sub_count >= 1000) {
|
||||||
// parseInt() is used to floor the value of division to an integer
|
// parseInt() is used to floor the value of division to an integer
|
||||||
sub_count = Number.parseInt(sub_count / 1000, 10) + "k";
|
sub_count = Number.parseInt(sub_count / 1000, 10) + "k";
|
||||||
@@ -42,8 +37,9 @@ function make_message_view_header(filter) {
|
|||||||
// the current user can access.
|
// the current user can access.
|
||||||
const current_stream = filter._sub;
|
const current_stream = filter._sub;
|
||||||
message_view_header.rendered_narrow_description = current_stream.rendered_description;
|
message_view_header.rendered_narrow_description = current_stream.rendered_description;
|
||||||
message_view_header.sub_count = get_sub_count(current_stream);
|
const sub_count = peer_data.get_subscriber_count(current_stream.stream_id);
|
||||||
message_view_header.formatted_sub_count = get_formatted_sub_count(current_stream);
|
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)
|
// the "title" is passed as a variable and doesn't get translated (nor should it)
|
||||||
message_view_header.sub_count_tooltip_text = i18n.t(
|
message_view_header.sub_count_tooltip_text = i18n.t(
|
||||||
"__count__ users are subscribed to #__title__",
|
"__count__ users are subscribed to #__title__",
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
const peer_data = require("./peer_data");
|
const peer_data = require("./peer_data");
|
||||||
|
|
||||||
function display_pill(sub) {
|
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) {
|
exports.create_item_from_stream_name = function (stream_name, current_items) {
|
||||||
|
|||||||
@@ -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.
|
// If the streams overlay isn't open, we don't need to rerender anything.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream_row = subs.row_for_stream_id(sub.stream_id);
|
const stream_row = subs.row_for_stream_id(sub.stream_id);
|
||||||
|
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!sub.can_access_subscribers ||
|
!sub.can_access_subscribers ||
|
||||||
(just_subscribed && sub.invite_only) ||
|
(just_subscribed && sub.invite_only) ||
|
||||||
page_params.is_guest
|
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);
|
stream_row.find(".subscriber-count").expectOne().html(rendered_sub_count);
|
||||||
} else {
|
} else {
|
||||||
stream_row.find(".subscriber-count-text").expectOne().text(sub.subscriber_count);
|
stream_row.find(".subscriber-count-text").expectOne().text(sub_count);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user