stream_data: Rename is_subscribed to is_subscribed_by_name.

Generally the stream_data module aims to do lookup by ID, not name,
wherever possible, so we should represent that in the function names.
This commit is contained in:
Tim Abbott 2021-11-22 15:37:45 -08:00
parent 043d83b434
commit 53d9797044
9 changed files with 18 additions and 18 deletions

View File

@ -311,7 +311,7 @@ run_test("bookend", ({override}) => {
let is_subscribed = true;
let invite_only = false;
override(stream_data, "is_subscribed", () => is_subscribed);
override(stream_data, "is_subscribed_by_name", () => is_subscribed);
override(stream_data, "get_sub", () => ({invite_only}));
{

View File

@ -66,19 +66,19 @@ test("unsubscribe", () => {
stream_data.add_sub(devel);
// verify clean slate
assert.ok(!stream_data.is_subscribed("devel"));
assert.ok(!stream_data.is_subscribed_by_name("devel"));
// set up our subscription
devel.subscribed = true;
peer_data.set_subscribers(devel.stream_id, [me.user_id]);
// ensure our setup is accurate
assert.ok(stream_data.is_subscribed("devel"));
assert.ok(stream_data.is_subscribed_by_name("devel"));
// DO THE UNSUBSCRIBE HERE
stream_data.unsubscribe_myself(devel);
assert.ok(!devel.subscribed);
assert.ok(!stream_data.is_subscribed("devel"));
assert.ok(!stream_data.is_subscribed_by_name("devel"));
assert.ok(!contains_sub(stream_data.subscribed_subs(), devel));
assert.ok(contains_sub(stream_data.unsubscribed_subs(), devel));
@ -96,7 +96,7 @@ test("subscribers", () => {
people.add_active_user(george);
// verify setup
assert.ok(stream_data.is_subscribed(sub.name));
assert.ok(stream_data.is_subscribed_by_name(sub.name));
const stream_id = sub.stream_id;

View File

@ -107,10 +107,10 @@ test("basics", () => {
assert.deepEqual(stream_data.get_colors(), ["red", "yellow"]);
assert.deepEqual(stream_data.subscribed_stream_ids(), [social.stream_id, test.stream_id]);
assert.ok(stream_data.is_subscribed("social"));
assert.ok(stream_data.is_subscribed("Social"));
assert.ok(!stream_data.is_subscribed("Denmark"));
assert.ok(!stream_data.is_subscribed("Rome"));
assert.ok(stream_data.is_subscribed_by_name("social"));
assert.ok(stream_data.is_subscribed_by_name("Social"));
assert.ok(!stream_data.is_subscribed_by_name("Denmark"));
assert.ok(!stream_data.is_subscribed_by_name("Rome"));
assert.equal(stream_data.get_stream_privacy_policy(test.stream_id), "public");
assert.equal(stream_data.get_stream_privacy_policy(social.stream_id), "invite-only");
@ -494,12 +494,12 @@ test("delete_sub", () => {
stream_data.add_sub(canada);
assert.ok(stream_data.is_subscribed("Canada"));
assert.ok(stream_data.is_subscribed_by_name("Canada"));
assert.equal(stream_data.get_sub("Canada").stream_id, canada.stream_id);
assert.equal(sub_store.get(canada.stream_id).name, "Canada");
stream_data.delete_sub(canada.stream_id);
assert.ok(!stream_data.is_subscribed("Canada"));
assert.ok(!stream_data.is_subscribed_by_name("Canada"));
assert.ok(!stream_data.get_sub("Canada"));
assert.ok(!sub_store.get(canada.stream_id));

View File

@ -342,12 +342,12 @@ test("marked_subscribed (emails)", ({override}) => {
const subs_stub = make_stub();
override(stream_settings_ui, "update_settings_for_subscribed", subs_stub.f);
assert.ok(!stream_data.is_subscribed(sub.name));
assert.ok(!stream_data.is_subscribed_by_name(sub.name));
const user_ids = [15, 20, 25, me.user_id];
stream_events.mark_subscribed(sub, user_ids, "");
assert.deepEqual(new Set(peer_data.get_subscribers(sub.stream_id)), new Set(user_ids));
assert.ok(stream_data.is_subscribed(sub.name));
assert.ok(stream_data.is_subscribed_by_name(sub.name));
const args = subs_stub.get_args("sub");
assert.deepEqual(sub, args.sub);

View File

@ -351,7 +351,7 @@ export function respond_to_message(opts) {
const first_operator = first_term.operator;
const first_operand = first_term.operand;
if (first_operator === "stream" && !stream_data.is_subscribed(first_operand)) {
if (first_operator === "stream" && !stream_data.is_subscribed_by_name(first_operand)) {
start("stream", {trigger: "empty_narrow_compose"});
return;
}

View File

@ -467,7 +467,7 @@ export function validation_error(error_type, stream_name) {
}
export function validate_stream_message_address_info(stream_name) {
if (stream_data.is_subscribed(stream_name)) {
if (stream_data.is_subscribed_by_name(stream_name)) {
return true;
}
const autosubscribe = page_params.narrow_stream !== undefined;

View File

@ -263,7 +263,7 @@ export class MessageList {
}
let trailing_bookend_content;
let show_button = true;
const subscribed = stream_data.is_subscribed(stream_name);
const subscribed = stream_data.is_subscribed_by_name(stream_name);
const sub = stream_data.get_sub(stream_name);
if (sub === undefined) {
trailing_bookend_content = this.deactivated_bookend_content();

View File

@ -133,7 +133,7 @@ function pick_empty_narrow_banner() {
// fallthrough to default case if no match is found
break;
case "stream":
if (!stream_data.is_subscribed(first_operand)) {
if (!stream_data.is_subscribed_by_name(first_operand)) {
// You are narrowed to a stream which does not exist or is a private stream
// in which you were never subscribed.

View File

@ -543,7 +543,7 @@ export function can_subscribe_others(sub) {
return !page_params.is_guest && (!sub.invite_only || sub.subscribed);
}
export function is_subscribed(stream_name) {
export function is_subscribed_by_name(stream_name) {
const sub = get_sub(stream_name);
return sub !== undefined && sub.subscribed;
}