mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 08:33:43 +00:00
stream_data: Refactor create_sub_from_server_data function.
We should just accept `subscribed` and `previously_subscribed` fields as arguments to this function to avoid adding them on the `attrs` object itself to simplify the type for `ApiGenericStreamSubscription`.
This commit is contained in:
@@ -28,11 +28,10 @@ type StreamInitParams = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Type for the parameter of `create_sub_from_server_data` function.
|
// Type for the parameter of `create_sub_from_server_data` function.
|
||||||
type ApiGenericStreamSubscription = (
|
type ApiGenericStreamSubscription =
|
||||||
| (NeverSubscribedStream & {previously_subscribed: boolean})
|
| NeverSubscribedStream
|
||||||
| (ApiStreamSubscription & {previously_subscribed: boolean})
|
| ApiStreamSubscription
|
||||||
| (Stream & {stream_weekly_traffic: number | null; subscribers: number[]})
|
| (Stream & {stream_weekly_traffic: number | null; subscribers: number[]});
|
||||||
) & {subscribed: boolean};
|
|
||||||
|
|
||||||
type InviteStreamData = {
|
type InviteStreamData = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -753,10 +752,9 @@ export function create_streams(streams: Stream[]): void {
|
|||||||
const attrs = {
|
const attrs = {
|
||||||
stream_weekly_traffic: null,
|
stream_weekly_traffic: null,
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
subscribed: false,
|
|
||||||
...stream,
|
...stream,
|
||||||
};
|
};
|
||||||
create_sub_from_server_data(attrs);
|
create_sub_from_server_data(attrs, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,6 +766,8 @@ export function clean_up_description(sub: StreamSubscription): void {
|
|||||||
|
|
||||||
export function create_sub_from_server_data(
|
export function create_sub_from_server_data(
|
||||||
attrs: ApiGenericStreamSubscription,
|
attrs: ApiGenericStreamSubscription,
|
||||||
|
subscribed: boolean,
|
||||||
|
previously_subscribed: boolean,
|
||||||
): StreamSubscription {
|
): StreamSubscription {
|
||||||
if (!attrs.stream_id) {
|
if (!attrs.stream_id) {
|
||||||
// fail fast
|
// fail fast
|
||||||
@@ -801,6 +801,8 @@ export function create_sub_from_server_data(
|
|||||||
email_notifications: null,
|
email_notifications: null,
|
||||||
wildcard_mentions_notify: null,
|
wildcard_mentions_notify: null,
|
||||||
color: "color" in attrs ? attrs.color : color_data.pick_color(),
|
color: "color" in attrs ? attrs.color : color_data.pick_color(),
|
||||||
|
subscribed,
|
||||||
|
previously_subscribed,
|
||||||
...attrs,
|
...attrs,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -880,13 +882,7 @@ export function initialize(params: StreamInitParams): void {
|
|||||||
previously_subscribed: boolean,
|
previously_subscribed: boolean,
|
||||||
): void {
|
): void {
|
||||||
for (const sub of subs) {
|
for (const sub of subs) {
|
||||||
const attrs = {
|
create_sub_from_server_data(sub, subscribed, previously_subscribed);
|
||||||
...sub,
|
|
||||||
subscribed,
|
|
||||||
previously_subscribed,
|
|
||||||
};
|
|
||||||
|
|
||||||
create_sub_from_server_data(attrs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export type ExtraStreamAttrs = {
|
|||||||
render_subscribers: boolean;
|
render_subscribers: boolean;
|
||||||
newly_subscribed: boolean;
|
newly_subscribed: boolean;
|
||||||
subscribed: boolean;
|
subscribed: boolean;
|
||||||
previously_subscribed?: boolean;
|
previously_subscribed: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the actual type of subscription objects we use in the app.
|
// This is the actual type of subscription objects we use in the app.
|
||||||
|
|||||||
Reference in New Issue
Block a user