stream: Move subscriber_count to api_stream_schema.

This commit is contained in:
Evy Kassirer
2025-09-29 17:56:28 -07:00
committed by Tim Abbott
parent e9135cdc34
commit 7167150a87
2 changed files with 8 additions and 9 deletions

View File

@@ -14,12 +14,11 @@ import * as settings_config from "./settings_config.ts";
import * as settings_data from "./settings_data.ts"; import * as settings_data from "./settings_data.ts";
import type {CurrentUser, GroupSettingValue, StateData} from "./state_data.ts"; import type {CurrentUser, GroupSettingValue, StateData} from "./state_data.ts";
import {current_user, realm} from "./state_data.ts"; import {current_user, realm} from "./state_data.ts";
import type {StreamPermissionGroupSetting, StreamTopicsPolicy} from "./stream_types.ts"; import type {APIStream, StreamPermissionGroupSetting, StreamTopicsPolicy} from "./stream_types.ts";
import * as sub_store from "./sub_store.ts"; import * as sub_store from "./sub_store.ts";
import type { import type {
ApiStreamSubscription, ApiStreamSubscription,
NeverSubscribedStream, NeverSubscribedStream,
Stream,
StreamSpecificNotificationSettings, StreamSpecificNotificationSettings,
StreamSubscription, StreamSubscription,
} from "./sub_store.ts"; } from "./sub_store.ts";
@@ -1037,12 +1036,11 @@ export async function maybe_fetch_is_user_subscribed(
); );
} }
export function create_streams(streams: Stream[]): void { export function create_streams(streams: APIStream[]): void {
for (const stream of streams) { for (const stream of streams) {
// We handle subscriber stuff in other events. // We handle subscriber stuff in other events.
const attrs = { const attrs = {
stream_weekly_traffic: null,
subscribers: [], subscribers: [],
...stream, ...stream,
}; };

View File

@@ -60,11 +60,6 @@ export const stream_schema = z.object({
rendered_description: z.string(), rendered_description: z.string(),
stream_id: z.number(), stream_id: z.number(),
stream_post_policy: z.enum(StreamPostPolicy), stream_post_policy: z.enum(StreamPostPolicy),
// This field is stripped from subscriber objects when loading data
// from the server. Always use `peer_data.get_subscriber_count` to
// access channel subscriber counts, and see its comments for notes
// about the possibility of inaccuracy in the presence of certain races.
subscriber_count: z.optional(z.number()),
topics_policy: stream_topics_policy_schema, topics_policy: stream_topics_policy_schema,
}); });
@@ -79,7 +74,13 @@ export const stream_specific_notification_settings_schema = z.object({
export const api_stream_schema = z.object({ export const api_stream_schema = z.object({
...stream_schema.shape, ...stream_schema.shape,
stream_weekly_traffic: z.nullable(z.number()), stream_weekly_traffic: z.nullable(z.number()),
// This field is stripped from subscriber objects when loading data
// from the server. Always use `peer_data.get_subscriber_count` to
// access channel subscriber counts, and see its comments for notes
// about the possibility of inaccuracy in the presence of certain races.
subscriber_count: z.number(),
}); });
export type APIStream = z.infer<typeof api_stream_schema>;
export const never_subscribed_stream_schema = z.object({ export const never_subscribed_stream_schema = z.object({
...api_stream_schema.shape, ...api_stream_schema.shape,