subscriber_api: Don't return unused channel request objects.

This commit is contained in:
Varun Singh 2024-06-19 00:35:10 +05:30 committed by Tim Abbott
parent 5230aada2b
commit 5891a9ef24

View File

@ -14,20 +14,21 @@ export function add_user_ids_to_stream(
sub: StreamSubscription,
success: () => void,
failure: (xhr: JQuery.jqXHR<unknown>) => void,
): JQuery.jqXHR<unknown> | undefined {
): 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;
return channel.post({
void channel.post({
url: "/json/users/me/subscriptions",
data: {subscriptions: JSON.stringify([{name: stream_name, color}])},
success,
error: failure,
});
return;
}
return channel.post({
void channel.post({
url: "/json/users/me/subscriptions",
data: {
subscriptions: JSON.stringify([{name: stream_name}]),
@ -43,10 +44,10 @@ export function remove_user_id_from_stream(
sub: StreamSubscription,
success: () => void,
failure: (xhr: JQuery.jqXHR<unknown>) => void,
): JQuery.jqXHR<unknown> | undefined {
): void {
// TODO: use stream_id when backend supports it
const stream_name = sub.name;
return channel.del({
void channel.del({
url: "/json/users/me/subscriptions",
data: {subscriptions: JSON.stringify([stream_name]), principals: JSON.stringify([user_id])},
success,