Skip to content

Commit 5d52b43

Browse files
committed
compose [nfc]: Use realm-relative URL for message link in quoteAndReply
Also, use the same URL type in quoteAndReplyPlaceholder. In inline links, absolute and relative realm URLs are treated the same by web and mobile, so better to use the shorter version.
1 parent 13bf943 commit 5d52b43

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/model/compose.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ String quoteAndReplyPlaceholder(
213213
PerAccountStore store, {
214214
required Message message,
215215
}) {
216-
final url = narrowLink(store,
216+
final relativeUrl = '#${narrowLinkFragment(store,
217217
SendableNarrow.ofMessage(message, selfUserId: store.selfUserId),
218-
nearMessageId: message.id);
218+
nearMessageId: message.id)}';
219219
return '${userMentionFromMessage(message, silent: true, users: store)} '
220-
'${inlineLink('said', url.toString())}: ' // TODO(#1285)
220+
'${inlineLink('said', relativeUrl.toString())}: ' // TODO(#1285)
221221
'*${zulipLocalizations.composeBoxLoadingMessage(message.id)}*\n';
222222
}
223223

@@ -229,18 +229,20 @@ String quoteAndReplyPlaceholder(
229229
/// ```quote
230230
/// message content
231231
/// ```
232+
/// But with a minor difference in that web uses realm-absolute URL and we use
233+
/// the shorter realm-relative URL for the message link.
232234
String quoteAndReply(PerAccountStore store, {
233235
required Message message,
234236
required String rawContent,
235237
}) {
236-
final url = narrowLink(store,
238+
final relativeUrl = '#${narrowLinkFragment(store,
237239
SendableNarrow.ofMessage(message, selfUserId: store.selfUserId),
238-
nearMessageId: message.id);
240+
nearMessageId: message.id)}';
239241
// Could ask userMentionFromMessage to omit the |<id> part unless the mention
240242
// is ambiguous… but that would mean a linear scan through all users,
241243
// and the extra noise won't much matter with the already probably-long
242244
// message link in there too.
243245
return '${userMentionFromMessage(message, silent: true, users: store)} '
244-
'${inlineLink('said', url.toString())}:\n' // TODO(#1285)
246+
'${inlineLink('said', relativeUrl.toString())}:\n' // TODO(#1285)
245247
'${wrapWithBacktickFence(content: rawContent, infoString: 'quote')}';
246248
}

test/model/compose_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ hello
351351

352352
check(quoteAndReplyPlaceholder(
353353
GlobalLocalizations.zulipLocalizations, store, message: message)).equals('''
354-
@_**Full Name|123** [said](${eg.selfAccount.realmUrl}#narrow/channel/1-test-here/topic/some.20topic/near/${message.id}): *(loading message ${message.id})*
354+
@_**Full Name|123** [said](#narrow/channel/1-test-here/topic/some.20topic/near/${message.id}): *(loading message ${message.id})*
355355
''');
356356

357357
check(quoteAndReply(store, message: message, rawContent: 'Hello world!')).equals('''
358-
@_**Full Name|123** [said](${eg.selfAccount.realmUrl}#narrow/channel/1-test-here/topic/some.20topic/near/${message.id}):
358+
@_**Full Name|123** [said](#narrow/channel/1-test-here/topic/some.20topic/near/${message.id}):
359359
```quote
360360
Hello world!
361361
```
@@ -364,11 +364,11 @@ Hello world!
364364
store.connection.zulipFeatureLevel = 249;
365365
check(quoteAndReplyPlaceholder(
366366
GlobalLocalizations.zulipLocalizations, store, message: message)).equals('''
367-
@_**Full Name|123** [said](${eg.selfAccount.realmUrl}#narrow/stream/1-test-here/topic/some.20topic/near/${message.id}): *(loading message ${message.id})*
367+
@_**Full Name|123** [said](#narrow/stream/1-test-here/topic/some.20topic/near/${message.id}): *(loading message ${message.id})*
368368
''');
369369

370370
check(quoteAndReply(store, message: message, rawContent: 'Hello world!')).equals('''
371-
@_**Full Name|123** [said](${eg.selfAccount.realmUrl}#narrow/stream/1-test-here/topic/some.20topic/near/${message.id}):
371+
@_**Full Name|123** [said](#narrow/stream/1-test-here/topic/some.20topic/near/${message.id}):
372372
```quote
373373
Hello world!
374374
```

0 commit comments

Comments
 (0)