mirror of https://github.com/zulip/zulip.git
stream_settings_api: Convert module to TypeScript.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
1c5321e57f
commit
341ba92f23
|
@ -232,7 +232,7 @@ EXEMPT_FILES = make_set(
|
|||
"web/src/stream_list.js",
|
||||
"web/src/stream_muting.js",
|
||||
"web/src/stream_popover.js",
|
||||
"web/src/stream_settings_api.js",
|
||||
"web/src/stream_settings_api.ts",
|
||||
"web/src/stream_settings_components.js",
|
||||
"web/src/stream_settings_containers.ts",
|
||||
"web/src/stream_settings_ui.js",
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
import * as channel from "./channel";
|
||||
import * as settings_ui from "./settings_ui";
|
||||
import * as sub_store from "./sub_store";
|
||||
|
||||
export function bulk_set_stream_property(sub_data, $status_element) {
|
||||
const url = "/json/users/me/subscriptions/properties";
|
||||
const data = {subscription_data: JSON.stringify(sub_data)};
|
||||
if (!$status_element) {
|
||||
return channel.post({
|
||||
url,
|
||||
data,
|
||||
timeout: 10 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
settings_ui.do_settings_change(channel.post, url, data, $status_element);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function set_stream_property(sub, data, $status_element) {
|
||||
const sub_data = {stream_id: sub.stream_id, ...data};
|
||||
bulk_set_stream_property([sub_data], $status_element);
|
||||
}
|
||||
|
||||
export function set_color(stream_id, color) {
|
||||
const sub = sub_store.get(stream_id);
|
||||
set_stream_property(sub, {property: "color", value: color});
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
import assert from "minimalistic-assert";
|
||||
|
||||
import * as channel from "./channel";
|
||||
import * as settings_ui from "./settings_ui";
|
||||
import type {StreamProperties, StreamSubscription} from "./sub_store";
|
||||
import * as sub_store from "./sub_store";
|
||||
|
||||
export function bulk_set_stream_property(
|
||||
sub_data: {
|
||||
[Property in keyof StreamProperties]: {
|
||||
stream_id: number;
|
||||
property: Property;
|
||||
value: StreamProperties[Property];
|
||||
};
|
||||
}[keyof StreamProperties][],
|
||||
$status_element?: JQuery,
|
||||
): void {
|
||||
const url = "/json/users/me/subscriptions/properties";
|
||||
const data = {subscription_data: JSON.stringify(sub_data)};
|
||||
if (!$status_element) {
|
||||
return void channel.post({
|
||||
url,
|
||||
data,
|
||||
timeout: 10 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
settings_ui.do_settings_change(channel.post, url, data, $status_element);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function set_stream_property(
|
||||
sub: StreamSubscription,
|
||||
data: {
|
||||
[Property in keyof StreamProperties]: {
|
||||
property: Property;
|
||||
value: StreamProperties[Property];
|
||||
};
|
||||
}[keyof StreamProperties],
|
||||
$status_element?: JQuery,
|
||||
): void {
|
||||
const sub_data = {stream_id: sub.stream_id, ...data};
|
||||
bulk_set_stream_property([sub_data], $status_element);
|
||||
}
|
||||
|
||||
export function set_color(stream_id: number, color: string): void {
|
||||
const sub = sub_store.get(stream_id);
|
||||
assert(sub !== undefined);
|
||||
set_stream_property(sub, {property: "color", value: color});
|
||||
}
|
|
@ -39,12 +39,15 @@ export type NeverSubscribedStream = Stream & {
|
|||
subscribers?: number[];
|
||||
};
|
||||
|
||||
// This is the raw data we get from the server for a subscription.
|
||||
export type ApiStreamSubscription = (Stream & StreamSpecificNotificationSettings) & {
|
||||
export type StreamProperties = StreamSpecificNotificationSettings & {
|
||||
color: string;
|
||||
email_address: string;
|
||||
is_muted: boolean;
|
||||
pin_to_top: boolean;
|
||||
};
|
||||
|
||||
// This is the raw data we get from the server for a subscription.
|
||||
export type ApiStreamSubscription = (Stream & StreamProperties) & {
|
||||
email_address: string;
|
||||
stream_weekly_traffic: number | null;
|
||||
subscribers?: number[];
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue