From 29fb5ff93456067db415ec6ea62169232e2b71a3 Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Mon, 27 Jan 2025 15:46:34 -0500 Subject: [PATCH] compose: Update textarea placeholder with general chat. --- web/src/compose_ui.ts | 16 +++++++++++++--- web/src/server_events_dispatch.js | 4 ++++ web/tests/dispatch.test.cjs | 3 +++ web/tests/lib/events.cjs | 7 +++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts index 52a611866d..4c0bb0fcf9 100644 --- a/web/src/compose_ui.ts +++ b/web/src/compose_ui.ts @@ -25,7 +25,7 @@ import * as people from "./people.ts"; import {postprocess_content} from "./postprocess_content.ts"; import * as rendered_markdown from "./rendered_markdown.ts"; import * as rtl from "./rtl.ts"; -import {current_user} from "./state_data.ts"; +import {current_user, realm} from "./state_data.ts"; import * as stream_data from "./stream_data.ts"; import * as user_status from "./user_status.ts"; import * as util from "./util.ts"; @@ -426,10 +426,20 @@ export function compute_placeholder_text(opts: ComposePlaceholderOptions): strin } } - if (stream_name && opts.topic) { + let topic_display_name: string | undefined; + if (opts.topic !== "") { + topic_display_name = opts.topic; + } else if ( + !realm.realm_mandatory_topics && + !$("input#stream_message_recipient_topic").is(":focus") + ) { + topic_display_name = util.get_final_topic_display_name(opts.topic); + } + + if (stream_name && topic_display_name !== undefined) { return $t( {defaultMessage: "Message #{channel_name} > {topic_name}"}, - {channel_name: stream_name, topic_name: opts.topic}, + {channel_name: stream_name, topic_name: topic_display_name}, ); } else if (stream_name) { return $t({defaultMessage: "Message #{channel_name}"}, {channel_name: stream_name}); diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js index 225eaa6664..672d3aa485 100644 --- a/web/src/server_events_dispatch.js +++ b/web/src/server_events_dispatch.js @@ -283,6 +283,10 @@ export function dispatch_normal_event(event) { "can_create_web_public_channel_group", ); } + + if (event.property === "mandatory_topics") { + compose_recipient.update_compose_area_placeholder_text(); + } } break; case "update_dict": diff --git a/web/tests/dispatch.test.cjs b/web/tests/dispatch.test.cjs index 693ae86805..b6e5b9cabc 100644 --- a/web/tests/dispatch.test.cjs +++ b/web/tests/dispatch.test.cjs @@ -524,6 +524,9 @@ run_test("realm settings", ({override}) => { }); assert_same(realm.realm_name, "new_realm_name"); + event = event_fixtures.realm__update__mandatory_topics; + test_realm_boolean(event, "realm_mandatory_topics"); + event = event_fixtures.realm__update__org_type; dispatch(event); assert_same(realm.realm_org_type, 50); diff --git a/web/tests/lib/events.cjs b/web/tests/lib/events.cjs index c14884149f..83120376f4 100644 --- a/web/tests/lib/events.cjs +++ b/web/tests/lib/events.cjs @@ -347,6 +347,13 @@ exports.fixtures = { value: false, }, + realm__update__mandatory_topics: { + type: "realm", + op: "update", + property: "mandatory_topics", + value: false, + }, + realm__update__name: { type: "realm", op: "update",