From 940aeaf7ae504c071c337c27c1ceb5067a43889a Mon Sep 17 00:00:00 2001 From: Greg Price Date: Thu, 20 Mar 2025 16:21:19 -0700 Subject: [PATCH 1/2] compose [nfc]: Pull out method for computing topic for hint text This method is trivial for now, but provides a home for logic to be added next. In particular this separates the computation of how the topic should appear in the hint text from what the topic should be in the API, in `destination`. --- lib/widgets/compose_box.dart | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/widgets/compose_box.dart b/lib/widgets/compose_box.dart index 7f47046d11..3d05308860 100644 --- a/lib/widgets/compose_box.dart +++ b/lib/widgets/compose_box.dart @@ -579,23 +579,31 @@ class _StreamContentInputState extends State<_StreamContentInput> { super.dispose(); } + /// The topic name to use in the hint text. + TopicName _hintTopic() { + return TopicName(widget.controller.topic.textNormalized); + } + @override Widget build(BuildContext context) { final store = PerAccountStoreWidget.of(context); final zulipLocalizations = ZulipLocalizations.of(context); + final streamName = store.streams[widget.narrow.streamId]?.name ?? zulipLocalizations.unknownChannelName; - final topic = TopicName(widget.controller.topic.textNormalized); + final hintDestination = + // No i18n of this use of "#" and ">" string; those are part of how + // Zulip expresses channels and topics, not any normal English punctuation, + // so don't make sense to translate. See: + // https://github.com/zulip/zulip-flutter/pull/1148#discussion_r1941990585 + '#$streamName > ${_hintTopic().displayName}'; + return _ContentInput( narrow: widget.narrow, - destination: TopicNarrow(widget.narrow.streamId, topic), + destination: TopicNarrow(widget.narrow.streamId, + TopicName(widget.controller.topic.textNormalized)), controller: widget.controller, - hintText: zulipLocalizations.composeBoxChannelContentHint( - // No i18n of this use of "#" and ">" string; those are part of how - // Zulip expresses channels and topics, not any normal English punctuation, - // so don't make sense to translate. See: - // https://github.com/zulip/zulip-flutter/pull/1148#discussion_r1941990585 - '#$streamName > ${topic.displayName}')); + hintText: zulipLocalizations.composeBoxChannelContentHint(hintDestination)); } } From 750a233bafc69aa46a43afbfc2da7f6f327ed75b Mon Sep 17 00:00:00 2001 From: Greg Price Date: Thu, 20 Mar 2025 16:10:51 -0700 Subject: [PATCH 2/2] WIP compose: Omit "(no topic)" from hint when not allowed to send there; TODO fix tests, add tests --- lib/widgets/compose_box.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/widgets/compose_box.dart b/lib/widgets/compose_box.dart index 3d05308860..32d16006ab 100644 --- a/lib/widgets/compose_box.dart +++ b/lib/widgets/compose_box.dart @@ -579,8 +579,15 @@ class _StreamContentInputState extends State<_StreamContentInput> { super.dispose(); } - /// The topic name to use in the hint text. - TopicName _hintTopic() { + /// The topic name to show in the hint text, or null to show no topic. + TopicName? _hintTopic() { + if (widget.controller.topic.isTopicVacuous) { + if (widget.controller.topic.mandatory) { + // The chosen topic can't be sent to, so don't show it. + return null; + } + } + return TopicName(widget.controller.topic.textNormalized); } @@ -591,12 +598,13 @@ class _StreamContentInputState extends State<_StreamContentInput> { final streamName = store.streams[widget.narrow.streamId]?.name ?? zulipLocalizations.unknownChannelName; - final hintDestination = + final hintTopic = _hintTopic(); + final hintDestination = hintTopic == null ? // No i18n of this use of "#" and ">" string; those are part of how // Zulip expresses channels and topics, not any normal English punctuation, // so don't make sense to translate. See: // https://github.com/zulip/zulip-flutter/pull/1148#discussion_r1941990585 - '#$streamName > ${_hintTopic().displayName}'; + '#$streamName' : '#$streamName > ${hintTopic.displayName}'; return _ContentInput( narrow: widget.narrow,