subscriber_api: Convert module to TypeScript.

This commit is contained in:
Varun Singh 2023-12-05 18:39:32 +05:30 committed by Anders Kaseorg
parent 6157d83d3a
commit 62a636068e
2 changed files with 14 additions and 3 deletions

View File

@ -240,7 +240,7 @@ EXEMPT_FILES = make_set(
"web/src/stream_settings_ui.js",
"web/src/stream_ui_updates.js",
"web/src/submessage.js",
"web/src/subscriber_api.js",
"web/src/subscriber_api.ts",
"web/src/timerender.ts",
"web/src/tippyjs.ts",
"web/src/todo_widget.js",

View File

@ -1,5 +1,6 @@
import * as channel from "./channel";
import * as people from "./people";
import type {StreamSubscription} from "./sub_store";
/*
This module simply encapsulates our legacy API for subscribing
@ -8,7 +9,12 @@ import * as people from "./people";
nor how to JSON.stringify things, nor the URL scheme.
*/
export function add_user_ids_to_stream(user_ids, sub, success, failure) {
export function add_user_ids_to_stream(
user_ids: number[],
sub: StreamSubscription,
success: () => void,
failure: (xhr: JQuery.jqXHR<unknown>) => void,
): JQuery.jqXHR<unknown> | undefined {
// TODO: use stream_id when backend supports it
const stream_name = sub.name;
if (user_ids.length === 1 && people.is_my_user_id(Number(user_ids[0]))) {
@ -32,7 +38,12 @@ export function add_user_ids_to_stream(user_ids, sub, success, failure) {
});
}
export function remove_user_id_from_stream(user_id, sub, success, failure) {
export function remove_user_id_from_stream(
user_id: number[],
sub: StreamSubscription,
success: () => void,
failure: (xhr: JQuery.jqXHR<unknown>) => void,
): JQuery.jqXHR<unknown> | undefined {
// TODO: use stream_id when backend supports it
const stream_name = sub.name;
return channel.del({