@@ -177,10 +177,16 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
177
177
return store.account.realmUrl.replace (fragment: fragment.toString ());
178
178
}
179
179
180
- // TODO like web, use just the name, no ID, when that wouldn't be ambiguous.
181
- // It looks nicer while the user's still composing and looking at the source.
182
- String mention (User user, {bool silent = false }) {
183
- return '@${silent ? '_' : '' }**${user .fullName }|${user .userId }**' ;
180
+ /// An @-mention, like @**Chris Bobbe|13313**.
181
+ ///
182
+ /// To omit the user ID part ("|13313") whenever the name part is unambiguous,
183
+ /// pass a Map of all users we know about. This means accepting a linear scan
184
+ /// through all users; avoid it in performance-sensitive codepaths.
185
+ String mention (User user, {bool silent = false , Map <int , User >? users}) {
186
+ bool includeUserId = users == null
187
+ || users.values.takeWhile ((u) => u.fullName == user.fullName).take (2 ).length == 2 ;
188
+
189
+ return '@${silent ? '_' : '' }**${user .fullName }${includeUserId ? '|${user .userId }' : '' }**' ;
184
190
}
185
191
186
192
/// https://spec.commonmark.org/0.30/#inline-link
@@ -214,6 +220,7 @@ String quoteAndReplyPlaceholder(PerAccountStore store, {
214
220
final url = narrowLink (store,
215
221
SendableNarrow .ofMessage (message, selfUserId: store.account.userId),
216
222
nearMessageId: message.id);
223
+ // See note in [quoteAndReply] about asking `mention` to omit the |<id> part.
217
224
return '${mention (sender !, silent : true )} ${inlineLink ('said' , url )}: ' // TODO(i18n) ?
218
225
'*(loading message ${message .id })*\n ' ; // TODO(i18n) ?
219
226
}
@@ -235,6 +242,9 @@ String quoteAndReply(PerAccountStore store, {
235
242
final url = narrowLink (store,
236
243
SendableNarrow .ofMessage (message, selfUserId: store.account.userId),
237
244
nearMessageId: message.id);
245
+ // Could ask `mention` to omit the |<id> part unless the mention is ambiguous…
246
+ // but that would mean a linear scan through all users, and the extra noise
247
+ // won't much matter with the already probably-long message link in there too.
238
248
return '${mention (sender !, silent : true )} ${inlineLink ('said' , url )}:\n ' // TODO(i18n) ?
239
249
'${wrapWithBacktickFence (content : rawContent , infoString : 'quote' )}' ;
240
250
}
0 commit comments