Skip to content

Commit 8f46f0c

Browse files
committed
compose [nfc]: Explain why quote-and-reply uses absolute URLs
In discussion on this PR, this related area looked to me like something we should change, until I learned more: #1902 (comment) #1902 (comment) Write that further context down, so that it's visible for the next person who wonders the same thing. Also explain why conversely we use relative URLs for the fallback form of #-mention links.
1 parent b794393 commit 8f46f0c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/model/compose.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,17 @@ final _channelAvoidedCharsRegex = RegExp(r'[`>*&[\]]|\$\$');
210210
String _channelFallbackMarkdownLink(ZulipStream channel, {
211211
required PerAccountStore store,
212212
}) {
213+
// Like Zulip web, we use a relative URL here, unlike [quoteAndReply] which
214+
// uses an absolute URL. There'd be little benefit to an absolute URL here
215+
// because this isn't a likely flow when a user wants something to copy-paste
216+
// elsewhere: this flow normally produces `#**…**` syntax, which wouldn't work
217+
// for that at all. And conversely, it's nice to keep reasonably short the
218+
// markup that we put into the text box and which the user sees. Discussion:
219+
// https://chat.zulip.org/#narrow/channel/101-design/topic/.22quote.20message.22.20uses.20absolute.20URL.20instead.20of.20realm-relative/near/2325588
220+
final relativeLink = '#${narrowLinkFragment(store, ChannelNarrow(channel.streamId))}';
221+
213222
final text = '#${channel.name.replaceAllMapped(_channelAvoidedCharsRegex,
214223
(match) => _channelAvoidedCharsReplacements[match[0]]!)}';
215-
final relativeLink = '#${narrowLinkFragment(store, ChannelNarrow(channel.streamId))}';
216224
return inlineLink(text.toString(), relativeLink);
217225
}
218226

@@ -250,6 +258,8 @@ String inlineLink(String visibleText, String destination) {
250258
}
251259

252260
/// What we show while fetching the target message's raw Markdown.
261+
///
262+
/// Like [quoteAndReply], but the message content is replaced with a placeholder.
253263
String quoteAndReplyPlaceholder(
254264
ZulipLocalizations zulipLocalizations,
255265
PerAccountStore store, {
@@ -271,13 +281,23 @@ String quoteAndReplyPlaceholder(
271281
/// ```quote
272282
/// message content
273283
/// ```
284+
///
285+
/// See also:
286+
/// * [quoteAndReplyPlaceholder].
274287
String quoteAndReply(PerAccountStore store, {
275288
required Message message,
276289
required String rawContent,
277290
}) {
291+
// Just like the Zulip web app, we use an absolute URL in these "said" links,
292+
// not relative. That's (a) harmless even if the realm later moves, because
293+
// the server turns such links into relative URLs in the message HTML anyway;
294+
// and (b) helpful in case the user copy-pastes this outside of Zulip,
295+
// including to a different Zulip realm, instead of sending the message here.
296+
// Discussion: https://chat.zulip.org/#narrow/channel/101-design/topic/.22quote.20message.22.20uses.20absolute.20URL.20instead.20of.20realm-relative/near/2322862
278297
final url = narrowLink(store,
279298
SendableNarrow.ofMessage(message, selfUserId: store.selfUserId),
280299
nearMessageId: message.id);
300+
281301
// Could ask userMentionFromMessage to omit the |<id> part unless the mention
282302
// is ambiguous… but that would mean a linear scan through all users,
283303
// and the extra noise won't much matter with the already probably-long

0 commit comments

Comments
 (0)