Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
resolved_topic: Start module, in shared package.
Greg Price624cdb0a1442
diff --git a/frontend_tests/node_tests/compose_validate.js b/frontend_tests/node_tests/compose_validate.jsindex 8d4bd9710b4..52e5641f05b 100644--- a/frontend_tests/node_tests/compose_validate.js+++ b/frontend_tests/node_tests/compose_validate.js@@ -16,9 +16,9 @@ const ui_util = mock_esm("../../static/js/ui_util");const compose_pm_pill = zrequire("compose_pm_pill");const compose_validate = zrequire("compose_validate");-const message_edit = zrequire("message_edit");const peer_data = zrequire("peer_data");const people = zrequire("people");+const resolved_topic = zrequire("../shared/js/resolved_topic");const settings_config = zrequire("settings_config");const settings_data = mock_esm("../../static/js/settings_data");const stream_data = zrequire("stream_data");@@ -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(message_edit.RESOLVED_TOPIC_PREFIX));+ assert.ok(context.topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX));return "fake-compose_resolved_topic";});@@ -786,7 +786,7 @@ test_ui("test warn_if_topic_resolved", ({override, mock_template}) => {compose_state.set_message_type("stream");compose_state.stream_name("Do not exist");- compose_state.topic(message_edit.RESOLVED_TOPIC_PREFIX + "hello");+ compose_state.topic(resolved_topic.RESOLVED_TOPIC_PREFIX + "hello");// Do not show a warning if stream name does not existcompose_validate.warn_if_topic_resolved();diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.jsindex 0ae7406f96a..9e4e908e828 100644--- a/frontend_tests/node_tests/filter.js+++ b/frontend_tests/node_tests/filter.js@@ -7,9 +7,9 @@ const {run_test} = require("../zjsunit/test");const $ = require("../zjsunit/zjquery");const {page_params} = require("../zjsunit/zpage_params");-const message_edit = mock_esm("../../static/js/message_edit");const message_store = mock_esm("../../static/js/message_store");+const resolved_topic = zrequire("../shared/js/resolved_topic");const stream_data = zrequire("stream_data");const people = zrequire("people");const {Filter} = zrequire("../js/filter");@@ -685,7 +685,7 @@ test("predicate_basics", () => {assert.ok(predicate({}));predicate = get_predicate([["is", "resolved"]]);- const resolved_topic_name = message_edit.RESOLVED_TOPIC_PREFIX + "foo";+ const resolved_topic_name = resolved_topic.RESOLVED_TOPIC_PREFIX + "foo";assert.ok(predicate({type: "stream", topic: resolved_topic_name}));assert.ok(!predicate({topic: resolved_topic_name}));assert.ok(!predicate({type: "stream", topic: "foo"}));diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.jsindex a7e807bfec3..d907d392e15 100644--- a/frontend_tests/node_tests/narrow_local.js+++ b/frontend_tests/node_tests/narrow_local.js@@ -6,12 +6,12 @@ const {mock_esm, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");const all_messages_data = mock_esm("../../static/js/all_messages_data");-const message_edit = mock_esm("../../static/js/message_edit");const {Filter} = zrequire("../js/filter");const {MessageListData} = zrequire("../js/message_list_data");const narrow_state = zrequire("narrow_state");const narrow = zrequire("narrow");+const resolved_topic = zrequire("../shared/js/resolved_topic");function test_with(fixture) {const filter = new Filter(fixture.filter_terms);@@ -302,7 +302,7 @@ run_test("is:alerted with no unreads and one match", () => {});run_test("is:resolved with one unread", () => {- const resolved_topic_name = message_edit.RESOLVED_TOPIC_PREFIX + "foo";+ const resolved_topic_name = resolved_topic.RESOLVED_TOPIC_PREFIX + "foo";const fixture = {filter_terms: [{operator: "is", operand: "resolved"}],unread_info: {@@ -327,7 +327,7 @@ run_test("is:resolved with one unread", () => {});run_test("is:resolved with no unreads", () => {- const resolved_topic_name = message_edit.RESOLVED_TOPIC_PREFIX + "foo";+ const resolved_topic_name = resolved_topic.RESOLVED_TOPIC_PREFIX + "foo";const fixture = {filter_terms: [{operator: "is", operand: "resolved"}],unread_info: {diff --git a/static/js/compose_validate.js b/static/js/compose_validate.jsindex d8c7873ce7c..5abb6ed64fa 100644--- a/static/js/compose_validate.js+++ b/static/js/compose_validate.js@@ -1,5 +1,6 @@import $ from "jquery";+import * as resolved_topic from "../shared/js/resolved_topic";import render_compose_all_everyone from "../templates/compose_all_everyone.hbs";import render_compose_announce from "../templates/compose_announce.hbs";import render_compose_invite_users from "../templates/compose_invite_users.hbs";@@ -13,7 +14,6 @@ import * as compose_pm_pill from "./compose_pm_pill";import * as compose_state from "./compose_state";import * as compose_ui from "./compose_ui";import {$t_html} from "./i18n";-import * as message_edit from "./message_edit";import {page_params} from "./page_params";import * as peer_data from "./peer_data";import * as people from "./people";@@ -178,7 +178,7 @@ export function warn_if_topic_resolved() {const sub = stream_data.get_sub(stream_name);- if (sub && topic_name.startsWith(message_edit.RESOLVED_TOPIC_PREFIX)) {+ if (sub && topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX)) {const error_area = $("#compose_resolved_topic");if (error_area.html()) {diff --git a/static/js/filter.js b/static/js/filter.jsindex 178d1524304..fb73d281a58 100644--- a/static/js/filter.js+++ b/static/js/filter.js@@ -1,9 +1,10 @@import Handlebars from "handlebars/runtime";import _ from "lodash";+import * as resolved_topic from "../shared/js/resolved_topic";+import * as hash_util from "./hash_util";import {$t} from "./i18n";-import * as message_edit from "./message_edit";import * as message_parser from "./message_parser";import * as message_store from "./message_store";import {page_params} from "./page_params";@@ -97,7 +98,7 @@ function message_matches_search_term(message, operator, operand) {case "resolved":return (message.type === "stream" &&- message.topic.startsWith(message_edit.RESOLVED_TOPIC_PREFIX)+ message.topic.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX));default:return false; // is:whatever returns falsediff --git a/static/js/message_edit.js b/static/js/message_edit.jsindex 352e3b1a7da..ba4adba3ca4 100644--- a/static/js/message_edit.js+++ b/static/js/message_edit.js@@ -2,6 +2,7 @@ import ClipboardJS from "clipboard";import $ from "jquery";import _ from "lodash";+import * as resolved_topic from "../shared/js/resolved_topic";import render_delete_message_modal from "../templates/confirm_dialog/confirm_delete_message.hbs";import render_message_edit_form from "../templates/message_edit_form.hbs";import render_topic_edit_form from "../templates/topic_edit_form.hbs";@@ -38,7 +39,6 @@ const currently_editing_messages = new Map();let currently_deleting_messages = [];let currently_topic_editing_messages = [];const currently_echoing_messages = new Map();-export const RESOLVED_TOPIC_PREFIX = "✔ ";// These variables are designed to preserve the user's most recent// choices when editing a group of messages, to make it convenient to@@ -641,10 +641,10 @@ export function start(row, edit_box_open_callback) {export function toggle_resolve_topic(message_id, old_topic_name) {let new_topic_name;- if (old_topic_name.startsWith(RESOLVED_TOPIC_PREFIX)) {- new_topic_name = _.trimStart(old_topic_name, RESOLVED_TOPIC_PREFIX);+ if (old_topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX)) {+ new_topic_name = _.trimStart(old_topic_name, resolved_topic.RESOLVED_TOPIC_PREFIX);} else {- new_topic_name = RESOLVED_TOPIC_PREFIX + old_topic_name;+ new_topic_name = resolved_topic.RESOLVED_TOPIC_PREFIX + old_topic_name;}const request = {diff --git a/static/js/message_list_view.js b/static/js/message_list_view.jsindex 2a116795ba4..0f5b52779d1 100644--- a/static/js/message_list_view.js+++ b/static/js/message_list_view.js@@ -2,6 +2,7 @@ import {isSameDay} from "date-fns";import $ from "jquery";import _ from "lodash";+import * as resolved_topic from "../shared/js/resolved_topic";import render_bookend from "../templates/bookend.hbs";import render_message_group from "../templates/message_group.hbs";import render_recipient_row from "../templates/recipient_row.hbs";@@ -181,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(message_edit.RESOLVED_TOPIC_PREFIX);+ group.topic_is_resolved = group.topic.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX);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.jsindex 8f943ec3b1e..58a0a52b15e 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -1,6 +1,7 @@import ClipboardJS from "clipboard";import $ from "jquery";+import * as resolved_topic from "../shared/js/resolved_topic";import render_all_messages_sidebar_actions from "../templates/all_messages_sidebar_actions.hbs";import render_delete_topic_modal from "../templates/confirm_dialog/confirm_delete_topic.hbs";import render_drafts_sidebar_actions from "../templates/drafts_sidebar_action.hbs";@@ -290,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(message_edit.RESOLVED_TOPIC_PREFIX),+ topic_is_resolved: topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX),color: sub.color,has_starred_messages,});diff --git a/static/js/topic_list_data.js b/static/js/topic_list_data.jsindex eee8402f34f..7f4b935d656 100644--- a/static/js/topic_list_data.js+++ b/static/js/topic_list_data.js@@ -1,5 +1,6 @@+import * as resolved_topic from "../shared/js/resolved_topic";+import * as hash_util from "./hash_util";-import * as message_edit from "./message_edit";import * as muted_topics from "./muted_topics";import * as narrow_state from "./narrow_state";import * as stream_topic_history from "./stream_topic_history";@@ -32,12 +33,12 @@ export function get_list_info(stream_id, zoomed) {const num_unread = unread.num_unread_for_topic(stream_id, topic_name);const is_active_topic = active_topic === topic_name.toLowerCase();const is_topic_muted = muted_topics.is_topic_muted(stream_id, topic_name);- const resolved = topic_name.startsWith(message_edit.RESOLVED_TOPIC_PREFIX);+ const resolved = topic_name.startsWith(resolved_topic.RESOLVED_TOPIC_PREFIX);let topic_display_name = topic_name;if (resolved) {topic_display_name = topic_display_name.slice(- message_edit.RESOLVED_TOPIC_PREFIX.length,+ resolved_topic.RESOLVED_TOPIC_PREFIX.length,);}@@ -107,7 +108,7 @@ export function get_list_info(stream_id, zoomed) {is_active_topic,url: hash_util.by_stream_topic_url(stream_id, topic_name),resolved,- resolved_topic_prefix: message_edit.RESOLVED_TOPIC_PREFIX,+ resolved_topic_prefix: resolved_topic.RESOLVED_TOPIC_PREFIX,};items.push(topic_info);diff --git a/static/shared/js/resolved_topic.js b/static/shared/js/resolved_topic.jsnew file mode 100644index 00000000000..6175cd1639c--- /dev/null+++ b/static/shared/js/resolved_topic.js@@ -0,0 +1,2 @@+/** The canonical form of the resolved-topic prefix. */+export const RESOLVED_TOPIC_PREFIX = "✔ ";diff --git a/static/shared/js/resolved_topic.js.flow b/static/shared/js/resolved_topic.js.flownew file mode 100644index 00000000000..cbe6e066c78--- /dev/null+++ b/static/shared/js/resolved_topic.js.flow@@ -0,0 +1,3 @@+// @flow strict++declare export var RESOLVED_TOPIC_PREFIX: string;