Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

sub_store: Add seperate types for api stream objects.

Lalit980c74e8da16
diff --git a/web/src/page_params.ts b/web/src/page_params.ts
index 481bacd470c..3b4e821a611 100644
--- a/web/src/page_params.ts
+++ b/web/src/page_params.ts
@@ -31,6 +31,7 @@ export const page_params: {
realm_enable_spectator_access: boolean;
realm_invite_to_realm_policy: number;
realm_invite_to_stream_policy: number;
+ realm_is_zephyr_mirror_realm: boolean;
realm_move_messages_between_streams_policy: number;
realm_name_changes_disabled: boolean;
realm_name: string;
diff --git a/web/src/sub_store.ts b/web/src/sub_store.ts
index 133dadcb2a5..885bbcb5e8b 100644
--- a/web/src/sub_store.ts
+++ b/web/src/sub_store.ts
@@ -1,5 +1,7 @@
import * as blueslip from "./blueslip";
+type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<T>;
+
export const enum StreamPostPolicy {
EVERYONE = 1,
ADMINS = 2,
@@ -7,6 +9,7 @@ export const enum StreamPostPolicy {
MODERATORS = 4,
}
+// These types are taken from the `zerver/lib/types.py`.
export type Stream = {
date_created: number;
description: string;
@@ -20,6 +23,7 @@ export type Stream = {
rendered_description: string;
stream_id: number;
stream_post_policy: StreamPostPolicy;
+ can_remove_subscribers_group: number;
};
export type StreamSpecificNotificationSettings = {
@@ -30,16 +34,36 @@ export type StreamSpecificNotificationSettings = {
wildcard_mentions_notify: boolean | null;
};
-export type StreamSubscription = (Stream & StreamSpecificNotificationSettings) & {
+export type NeverSubscribedStream = Stream & {
+ stream_weekly_traffic: number | null;
+ subscribers?: number[];
+};
+
+// This is the raw data we get from the server for a subscription.
+export type ApiStreamSubscription = (Stream & StreamSpecificNotificationSettings) & {
color: string;
email_address: string;
- in_home_view: boolean;
is_muted: boolean;
pin_to_top: boolean;
stream_weekly_traffic: number | null;
subscribers?: number[];
};
+// These properties are added in `stream_data` when hydrating the streams and are not present in the data we get from the server.
+export type ExtraStreamAttrs = {
+ render_subscribers: boolean;
+ newly_subscribed: boolean;
+ subscribed: boolean;
+ previously_subscribed?: boolean;
+};
+
+// This is the actual type of subscription objects we use in the app.
+export type StreamSubscription = PartialBy<
+ Omit<ApiStreamSubscription, "subscribers">,
+ "pin_to_top" | "email_address"
+> &
+ ExtraStreamAttrs;
+
const subs_by_stream_id = new Map<number, StreamSubscription>();
export function get(stream_id: number): StreamSubscription | undefined {