Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message-list-view: Remove hack for undefined StreamSubscription.
Lauryn Menard350d7c5d2d89
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.tsindex 80992d1b92e..e1bf4b72892 100644--- a/web/src/message_list_view.ts+++ b/web/src/message_list_view.ts@@ -385,73 +385,44 @@ export function populate_group_from_message(assert(message.type === "stream");// stream messages have string display_recipientassert(typeof display_recipient === "string");- const color = stream_data.get_color(message.stream_id);- const recipient_bar_color = stream_color.get_recipient_bar_color(color);- const stream_privacy_icon_color = stream_color.get_stream_privacy_icon_color(color);- const invite_only = stream_data.is_invite_only_by_stream_id(message.stream_id);- const is_web_public = stream_data.is_web_public(message.stream_id);+ const stream_id = message.stream_id;const topic = message.topic;- const topic_display_name = util.get_final_topic_display_name(topic);- const is_empty_string_topic = topic === "";- const match_topic_html = util.get_match_topic(message);- const stream_url = hash_util.channel_url_by_user_setting(message.stream_id);- const is_archived = stream_data.is_stream_archived_by_id(message.stream_id);- const topic_url = internal_url.by_stream_topic_url(- message.stream_id,- message.topic,- sub_store.maybe_get_stream_name,- message.id,- );-- const sub = sub_store.get(message.stream_id);- let stream_id;- if (sub === undefined) {- // Hack to handle unusual cases like the tutorial where- // the streams used don't actually exist in the subs- // module. Ideally, we'd clean this up by making the- // tutorial populate stream_settings_ui.ts "properly".- stream_id = -1;- } else {- stream_id = sub.stream_id;- }-- const is_subscribed = stream_data.is_subscribed(stream_id);- const topic_is_resolved = resolved_topic.is_resolved(topic);- const user_can_resolve_topic = stream_data.can_resolve_topics(sub);- const visibility_policy = user_topics.get_topic_visibility_policy(stream_id, topic);- // The following field is not specific to this group, but this is the- // easiest way we've figured out for passing the data to the template rendering.- const all_visibility_policies = user_topics.all_visibility_policies;-- const topic_links = message.topic_links;-+ const sub = sub_store.get(stream_id);+ assert(sub !== undefined);return {message_group_id,message_containers: [],is_stream,...get_topic_edit_properties(message),- user_can_resolve_topic,+ user_can_resolve_topic: stream_data.can_resolve_topics(sub),...subscription_markers,date_html,display_recipient,date_unchanged,- topic_links,+ topic_links: message.topic_links,topic,- topic_display_name,- is_empty_string_topic,- recipient_bar_color,- stream_privacy_icon_color,- invite_only,- is_web_public,- match_topic_html,- stream_url,- is_archived,- topic_url,+ topic_display_name: util.get_final_topic_display_name(topic),+ is_empty_string_topic: topic === "",+ recipient_bar_color: stream_color.get_recipient_bar_color(sub.color),+ stream_privacy_icon_color: stream_color.get_stream_privacy_icon_color(sub.color),+ invite_only: sub.invite_only,+ is_web_public: sub.is_web_public,+ match_topic_html: util.get_match_topic(message),+ stream_url: hash_util.channel_url_by_user_setting(stream_id),+ is_archived: sub.is_archived,+ topic_url: internal_url.by_stream_topic_url(+ stream_id,+ topic,+ sub_store.maybe_get_stream_name,+ message.id,+ ),stream_id,- is_subscribed,- topic_is_resolved,- visibility_policy,- all_visibility_policies,+ is_subscribed: sub.subscribed,+ topic_is_resolved: resolved_topic.is_resolved(topic),+ visibility_policy: user_topics.get_topic_visibility_policy(stream_id, topic),+ // The following field is not specific to this group, but this is the+ // easiest way we've figured out for passing the data to the template rendering.+ all_visibility_policies: user_topics.all_visibility_policies,always_display_date,};}diff --git a/web/src/stream_data.ts b/web/src/stream_data.tsindex 7e87cb77f5c..de7eca3b69a 100644--- a/web/src/stream_data.ts+++ b/web/src/stream_data.ts@@ -811,8 +811,8 @@ export function can_subscribe_others(sub: StreamSubscription): boolean {);}-export function can_resolve_topics(sub: StreamSubscription | undefined): boolean {- if (sub?.is_archived) {+export function can_resolve_topics(sub: StreamSubscription): boolean {+ if (sub.is_archived) {return false;}@@ -820,12 +820,6 @@ export function can_resolve_topics(sub: StreamSubscription | undefined): booleanreturn true;}- if (sub === undefined) {- // If we're in a context without a channel, only the global- // permission is relevant.- return false;- }-return settings_data.user_has_permission_for_group_setting(sub.can_resolve_topics_group,"can_resolve_topics_group",diff --git a/web/tests/stream_data.test.cjs b/web/tests/stream_data.test.cjsindex 8a9ead9fcfa..ad9f8cc8896 100644--- a/web/tests/stream_data.test.cjs+++ b/web/tests/stream_data.test.cjs@@ -1651,9 +1651,7 @@ test("can_resolve_topics", ({override}) => {};stream_data.add_sub_for_tests(archived_sub);- assert.equal(stream_data.can_resolve_topics(undefined), false);initialize_and_override_current_user(admin_user_id, override);- assert.equal(stream_data.can_resolve_topics(undefined), true);assert.equal(stream_data.can_resolve_topics(sub), true);initialize_and_override_current_user(moderator_user_id, override);assert.equal(stream_data.can_resolve_topics(sub), false);