diff --git a/frontend_tests/node_tests/compose_validate.js b/frontend_tests/node_tests/compose_validate.js index 52e5641f05..d4cbe5991a 100644 --- a/frontend_tests/node_tests/compose_validate.js +++ b/frontend_tests/node_tests/compose_validate.js @@ -770,7 +770,7 @@ test_ui("test warn_if_topic_resolved", ({override, mock_template}) => { mock_template("compose_resolved_topic.hbs", false, (context) => { assert.ok(context.can_move_topic); - assert.ok(context.topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX)); + assert.ok(resolved_topic.is_resolved(context.topic_name)); return "fake-compose_resolved_topic"; }); diff --git a/frontend_tests/node_tests/resolved_topic.js b/frontend_tests/node_tests/resolved_topic.js new file mode 100644 index 0000000000..3136fb84cf --- /dev/null +++ b/frontend_tests/node_tests/resolved_topic.js @@ -0,0 +1,20 @@ +"use strict"; + +const {strict: assert} = require("assert"); + +const {zrequire} = require("../zjsunit/namespace"); +const {run_test} = require("../zjsunit/test"); + +const resolved_topic = zrequire("../shared/js/resolved_topic"); + +const topic_name = "asdf"; +const resolved_name = "✔ " + topic_name; +const overresolved_name = "✔ ✔✔ " + topic_name; +const pseudoresolved_name = "✔" + topic_name; // check mark, but no space + +run_test("is_resolved", () => { + assert.ok(!resolved_topic.is_resolved(topic_name)); + assert.ok(resolved_topic.is_resolved(resolved_name)); + assert.ok(resolved_topic.is_resolved(overresolved_name)); + assert.ok(!resolved_topic.is_resolved(pseudoresolved_name)); +}); diff --git a/static/js/compose_validate.js b/static/js/compose_validate.js index 5abb6ed64f..40586d7716 100644 --- a/static/js/compose_validate.js +++ b/static/js/compose_validate.js @@ -178,7 +178,7 @@ export function warn_if_topic_resolved() { const sub = stream_data.get_sub(stream_name); - if (sub && topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX)) { + if (sub && resolved_topic.is_resolved(topic_name)) { const error_area = $("#compose_resolved_topic"); if (error_area.html()) { diff --git a/static/js/filter.js b/static/js/filter.js index fb73d281a5..ccc83320f1 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -96,10 +96,7 @@ function message_matches_search_term(message, operator, operand) { case "unread": return unread.message_unread(message); case "resolved": - return ( - message.type === "stream" && - message.topic.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX) - ); + return message.type === "stream" && resolved_topic.is_resolved(message.topic); default: return false; // is:whatever returns false } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 0f5b52779d..6ea6a13f61 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -182,7 +182,7 @@ function populate_group_from_message_container(group, message_container) { } else { group.stream_id = sub.stream_id; } - group.topic_is_resolved = group.topic.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX); + group.topic_is_resolved = resolved_topic.is_resolved(group.topic); group.topic_muted = muted_topics.is_topic_muted(group.stream_id, group.topic); } else if (group.is_private) { group.pm_with_url = message_container.pm_with_url; diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js index 58a0a52b15..a20dc8ac02 100644 --- a/static/js/stream_popover.js +++ b/static/js/stream_popover.js @@ -291,7 +291,7 @@ function build_topic_popover(opts) { topic_muted, can_move_topic, is_realm_admin: page_params.is_admin, - topic_is_resolved: topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX), + topic_is_resolved: resolved_topic.is_resolved(topic_name), color: sub.color, has_starred_messages, }); diff --git a/static/shared/js/resolved_topic.js b/static/shared/js/resolved_topic.js index 6175cd1639..404beca973 100644 --- a/static/shared/js/resolved_topic.js +++ b/static/shared/js/resolved_topic.js @@ -1,2 +1,6 @@ /** The canonical form of the resolved-topic prefix. */ export const RESOLVED_TOPIC_PREFIX = "✔ "; + +export function is_resolved(topic_name) { + return topic_name.startsWith(RESOLVED_TOPIC_PREFIX); +} diff --git a/static/shared/js/resolved_topic.js.flow b/static/shared/js/resolved_topic.js.flow index cbe6e066c7..a3f754d82e 100644 --- a/static/shared/js/resolved_topic.js.flow +++ b/static/shared/js/resolved_topic.js.flow @@ -1,3 +1,5 @@ // @flow strict declare export var RESOLVED_TOPIC_PREFIX: string; + +declare export function is_resolved(topic_name: string): boolean;