mirror of
https://github.com/zulip/zulip.git
synced 2026-07-09 21:21:47 +08:00
When a user is added to a channel, we send the user that was added a Notification Bot DMs to let them know about it. In this commit, we add an option for whether or not this message is sent. If more than 100 users are added at once, we do not send notification bot DMs since it would be a performance-costly operation. We also send this threshold value of 100 in the initial state data to the clients. Fixes part of #31189
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
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,
|
|
});
|
|
}
|