mirror of https://github.com/zulip/zulip.git
bookend: Simplify can_toggle_subscription variable flow.
This commit is contained in:
parent
2b59148e21
commit
6065d66d3d
|
@ -312,6 +312,7 @@ run_test("bookend", ({override}) => {
|
|||
|
||||
override(stream_data, "is_subscribed_by_name", () => is_subscribed);
|
||||
override(stream_data, "get_sub", () => ({invite_only}));
|
||||
override(stream_data, "can_toggle_subscription", () => true);
|
||||
|
||||
{
|
||||
const stub = make_stub();
|
||||
|
@ -323,13 +324,11 @@ run_test("bookend", ({override}) => {
|
|||
"subscribed",
|
||||
"deactivated",
|
||||
"just_unsubscribed",
|
||||
"show_button",
|
||||
);
|
||||
assert.equal(bookend.stream_name, "IceCream");
|
||||
assert.equal(bookend.subscribed, true);
|
||||
assert.equal(bookend.deactivated, false);
|
||||
assert.equal(bookend.just_unsubscribed, false);
|
||||
assert.equal(bookend.show_button, true);
|
||||
}
|
||||
|
||||
list.last_message_historical = false;
|
||||
|
@ -345,13 +344,11 @@ run_test("bookend", ({override}) => {
|
|||
"subscribed",
|
||||
"deactivated",
|
||||
"just_unsubscribed",
|
||||
"show_button",
|
||||
);
|
||||
assert.equal(bookend.stream_name, "IceCream");
|
||||
assert.equal(bookend.subscribed, false);
|
||||
assert.equal(bookend.deactivated, false);
|
||||
assert.equal(bookend.just_unsubscribed, true);
|
||||
assert.equal(bookend.show_button, true);
|
||||
}
|
||||
|
||||
// Test when the stream is privates (invite only)
|
||||
|
@ -367,13 +364,11 @@ run_test("bookend", ({override}) => {
|
|||
"subscribed",
|
||||
"deactivated",
|
||||
"just_unsubscribed",
|
||||
"show_button",
|
||||
);
|
||||
assert.equal(bookend.stream_name, "IceCream");
|
||||
assert.equal(bookend.subscribed, false);
|
||||
assert.equal(bookend.deactivated, false);
|
||||
assert.equal(bookend.just_unsubscribed, true);
|
||||
assert.equal(bookend.show_button, false);
|
||||
}
|
||||
|
||||
list.last_message_historical = true;
|
||||
|
@ -388,13 +383,11 @@ run_test("bookend", ({override}) => {
|
|||
"subscribed",
|
||||
"deactivated",
|
||||
"just_unsubscribed",
|
||||
"show_button",
|
||||
);
|
||||
assert.equal(bookend.stream_name, "IceCream");
|
||||
assert.equal(bookend.subscribed, false);
|
||||
assert.equal(bookend.deactivated, false);
|
||||
assert.equal(bookend.just_unsubscribed, false);
|
||||
assert.equal(bookend.show_button, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -244,23 +244,21 @@ export class MessageList {
|
|||
|
||||
let deactivated = false;
|
||||
let just_unsubscribed = false;
|
||||
let show_button = true;
|
||||
const subscribed = stream_data.is_subscribed_by_name(stream_name);
|
||||
const sub = stream_data.get_sub(stream_name);
|
||||
const can_toggle_subscription =
|
||||
sub !== undefined && stream_data.can_toggle_subscription(sub);
|
||||
if (sub === undefined) {
|
||||
deactivated = true;
|
||||
// Hide the resubscribe button for streams that no longer exist.
|
||||
show_button = false;
|
||||
} else if (!subscribed && !this.last_message_historical) {
|
||||
just_unsubscribed = true;
|
||||
show_button = stream_data.can_toggle_subscription(sub);
|
||||
}
|
||||
this.view.render_trailing_bookend(
|
||||
stream_name,
|
||||
subscribed,
|
||||
deactivated,
|
||||
just_unsubscribed,
|
||||
show_button,
|
||||
can_toggle_subscription,
|
||||
page_params.is_spectator,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1300,13 +1300,13 @@ export class MessageListView {
|
|||
subscribed,
|
||||
deactivated,
|
||||
just_unsubscribed,
|
||||
show_button,
|
||||
can_toggle_subscription,
|
||||
is_spectator,
|
||||
) {
|
||||
const rendered_trailing_bookend = $(
|
||||
render_bookend({
|
||||
stream_name,
|
||||
trailing: show_button,
|
||||
can_toggle_subscription,
|
||||
subscribed,
|
||||
deactivated,
|
||||
just_unsubscribed,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{! Client-side Mustache template for rendering the trailing bookend.}}
|
||||
<div class="{{#if trailing}}trailing_bookend{{/if}} bookend sub-unsub-message">
|
||||
<div class="{{#if can_toggle_subscription}}trailing_bookend{{/if}} bookend sub-unsub-message">
|
||||
{{#if is_spectator}}
|
||||
<span class="recent-topics-link">
|
||||
<a href="#recent_topics">{{t "Browse recent topics" }}</a>
|
||||
|
@ -17,7 +17,7 @@
|
|||
{{/if}}
|
||||
</span>
|
||||
{{/if}}
|
||||
{{#if trailing}}
|
||||
{{#if can_toggle_subscription}}
|
||||
<div class="sub_button_row new-style">
|
||||
<button class="button white rounded stream_sub_unsub_button {{#unless subscribed}}sea-green{{/unless}}" type="button" name="subscription">
|
||||
{{#if subscribed}}
|
||||
|
|
Loading…
Reference in New Issue