/
githubmirror
/
zulip
Обзор
Документация
Войти
/
githubmirror
/
zulip
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
web/src/subscriber_api.ts
61 строка
2 KB
Kislay Verma
channel: Add option to notify users newly added to a channel.
26 июн 2025, 20:08
26 июн 2025, 20:08
f448890
Код
Авторство
О чём код?
import * as channel from "./channel.ts"; import * as people from "./people.ts"; import type {StreamSubscription} from "./sub_store.ts"; /* This module simply encapsulates our legacy API for subscribing or unsubscribing users from streams. Callers don't need to know the strange names of "subscriptions" and "principals", nor how to JSON.stringify things, nor the URL scheme. */ export function add_user_ids_to_stream( user_ids: number[], sub: StreamSubscription, send_new_subscription_messages: boolean, success: (data: unknown) => void, failure: (xhr: JQuery.jqXHR<unknown>) => void, ): void { // 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]))) { // Self subscribe const color = sub.color; void channel.post({ url: "/json/users/me/subscriptions", data: { subscriptions: JSON.stringify([{name: stream_name, color}]), send_new_subscription_messages, }, success, error: failure, }); return; } void channel.post({ url: "/json/users/me/subscriptions", data: { subscriptions: JSON.stringify([{name: stream_name}]), principals: JSON.stringify(user_ids), send_new_subscription_messages, }, success, error: failure, }); } export function remove_user_id_from_stream( user_id: number, sub: StreamSubscription, success: (data: unknown) => void, failure: (xhr: JQuery.jqXHR<unknown>) => void, ): void { // TODO: use stream_id when backend supports it const stream_name = sub.name; void channel.del({ url: "/json/users/me/subscriptions", data: {subscriptions: JSON.stringify([stream_name]), principals: JSON.stringify([user_id])}, success, error: failure, }); }