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.

ts: Convert sub_store module to TypeScript.

Priyank Patel397821660f24
diff --git a/package.json b/package.json
index a6634a4a878..2dcebf012d7 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/preset-env": "^7.5.5",
- "@babel/preset-typescript": "^7.3.3",
+ "@babel/preset-typescript": "^7.15.0",
"@babel/register": "^7.6.2",
"@formatjs/intl": "^1.9.7",
"@giphy/js-components": "^5.0.5",
diff --git a/static/js/sub_store.js b/static/js/sub_store.js
deleted file mode 100644
index ec8f55949d6..00000000000
--- a/static/js/sub_store.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import * as blueslip from "./blueslip";
-
-const subs_by_stream_id = new Map();
-
-export function get(stream_id) {
- return subs_by_stream_id.get(stream_id);
-}
-
-export function validate_stream_ids(stream_ids) {
- const good_ids = [];
- const bad_ids = [];
-
- for (const stream_id of stream_ids) {
- if (subs_by_stream_id.has(stream_id)) {
- good_ids.push(stream_id);
- } else {
- bad_ids.push(stream_id);
- }
- }
-
- if (bad_ids.length > 0) {
- blueslip.warn(`We have untracked stream_ids: ${bad_ids}`);
- }
-
- return good_ids;
-}
-
-export function clear() {
- subs_by_stream_id.clear();
-}
-
-export function delete_sub(stream_id) {
- subs_by_stream_id.delete(stream_id);
-}
-
-export function add_hydrated_sub(stream_id, sub) {
- // The only code that should call this directly is
- // in stream_data.js. Grep there to find callers.
- subs_by_stream_id.set(stream_id, sub);
-}
diff --git a/static/js/sub_store.ts b/static/js/sub_store.ts
new file mode 100644
index 00000000000..6bc3e6a946a
--- /dev/null
+++ b/static/js/sub_store.ts
@@ -0,0 +1,83 @@
+import * as blueslip from "./blueslip";
+
+export const enum StreamPostPolicy {
+ EVERYONE = 1,
+ ADMINS = 2,
+ RESTRICT_NEW_MEMBERS = 3,
+ MODERATORS = 4,
+}
+
+export const enum SubscriptionRole {
+ STREAM_ADMINISTRATOR = 20,
+ MEMBER = 50,
+}
+
+export type Stream = {
+ date_created: number;
+ description: string;
+ first_message_id: number | null;
+ history_public_to_subscribers: boolean;
+ invite_only: boolean;
+ is_announcement_only: boolean;
+ is_web_public: boolean;
+ message_retention_days: number | null;
+ name: string;
+ rendered_description: string;
+ stream_id: number;
+ stream_post_policy: StreamPostPolicy;
+};
+
+export type StreamSubscription = Stream & {
+ audible_notifications: boolean | null;
+ color: string;
+ desktop_notifications: boolean | null;
+ email_address: string;
+ email_notifications: boolean | null;
+ in_home_view: boolean;
+ is_muted: boolean;
+ pin_to_top: boolean;
+ push_notifications: boolean | null;
+ role: SubscriptionRole;
+ stream_weekly_traffic: number | null;
+ subscribers?: number[];
+ wildcard_mentions_notify: boolean | null;
+};
+
+const subs_by_stream_id = new Map<number, StreamSubscription>();
+
+export function get(stream_id: number): StreamSubscription | undefined {
+ return subs_by_stream_id.get(stream_id);
+}
+
+export function validate_stream_ids(stream_ids: number[]): number[] {
+ const good_ids = [];
+ const bad_ids = [];
+
+ for (const stream_id of stream_ids) {
+ if (subs_by_stream_id.has(stream_id)) {
+ good_ids.push(stream_id);
+ } else {
+ bad_ids.push(stream_id);
+ }
+ }
+
+ if (bad_ids.length > 0) {
+ blueslip.warn(`We have untracked stream_ids: ${bad_ids}`);
+ }
+
+ return good_ids;
+}
+
+export function clear(): void {
+ subs_by_stream_id.clear();
+}
+
+export function delete_sub(stream_id: number): void {
+ subs_by_stream_id.delete(stream_id);
+}
+
+export function add_hydrated_sub(stream_id: number, sub: StreamSubscription): void {
+ // The only code that should call this directly is
+ // in stream_data.js. Grep there to find callers.
+ subs_by_stream_id.set(stream_id, sub);
+}
diff --git a/yarn.lock b/yarn.lock
index d30a7a427c1..8e8a5af3abd 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -908,7 +908,7 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"
-"@babel/preset-typescript@^7.3.3":
+"@babel/preset-typescript@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.15.0.tgz#e8fca638a1a0f64f14e1119f7fe4500277840945"
integrity sha512-lt0Y/8V3y06Wq/8H/u0WakrqciZ7Fz7mwPDHWUJAXlABL5hiUG42BNlRXiELNjeWjO5rWmnNKlx+yzJvxezHow==