stream_data: Extend comments for can_toggle_subscription.

The previous comments were a bit simple and I wanted to add an
important detail about how deactivated streams interact with this
feature.

Fixes #20262.
This commit is contained in:
Tim Abbott 2021-11-24 17:43:43 -08:00
parent 74b4640727
commit b9629d72a9
1 changed files with 9 additions and 3 deletions

View File

@ -519,9 +519,15 @@ export function is_notifications_stream_muted() {
}
export function can_toggle_subscription(sub) {
// If stream is public then any user can subscribe. If stream is private then only
// subscribed users can unsubscribe.
// Guest users can't subscribe themselves to any stream.
// You can always remove your subscription if you're subscribed.
//
// One can only join a stream if it is public (!invite_only) and
// your role is Member or above (!is_guest).
//
// Note that the correctness of this logic relies on the fact that
// one cannot be subscribed to a deactivated stream, and
// deactivated streams are automatically made private during the
// archive stream process.
return sub.subscribed || (!page_params.is_guest && !sub.invite_only);
}