mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
resolved_topic: Add and use predicate is_resolved.
We leave in place a couple of sites where the `startsWith` is entangled with other string manipulation. We'll handle those next.
This commit is contained in:
parent
624cdb0a14
commit
7bf0fd3fa3
@ -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";
|
||||
});
|
||||
|
||||
|
||||
20
frontend_tests/node_tests/resolved_topic.js
Normal file
20
frontend_tests/node_tests/resolved_topic.js
Normal file
@ -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));
|
||||
});
|
||||
@ -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()) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
// @flow strict
|
||||
|
||||
declare export var RESOLVED_TOPIC_PREFIX: string;
|
||||
|
||||
declare export function is_resolved(topic_name: string): boolean;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user