Skip to content

Commit

Permalink
internal_link [nfc]: Make encodeHashComponent public
Browse files Browse the repository at this point in the history
Prep for handling notification-open via intent URIs.
  • Loading branch information
rajveermalviya committed Oct 18, 2024
1 parent 5bf5ad8 commit b3b6041
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/model/internal_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const _hashReplacements = {

final _encodeHashComponentRegex = RegExp(r'[%().]');

/// Perform Zulip's url hash dot-encoding on the given string.
// Corresponds to encodeHashComponent in Zulip web;
// see web/shared/src/internal_url.ts.
String _encodeHashComponent(String str) {
@visibleForTesting
String encodeHashComponent(String str) {
return Uri.encodeComponent(str)
.replaceAllMapped(_encodeHashComponentRegex, (Match m) => _hashReplacements[m[0]!]!);
}
Expand Down Expand Up @@ -73,10 +75,10 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
case ApiNarrowStream():
final streamId = element.operand;
final name = store.streams[streamId]?.name ?? 'unknown';
final slugifiedName = _encodeHashComponent(name.replaceAll(' ', '-'));
final slugifiedName = encodeHashComponent(name.replaceAll(' ', '-'));
fragment.write('$streamId-$slugifiedName');
case ApiNarrowTopic():
fragment.write(_encodeHashComponent(element.operand));
fragment.write(encodeHashComponent(element.operand));
case ApiNarrowDmModern():
final suffix = element.operand.length >= 3 ? 'group' : 'dm';
fragment.write('${element.operand.join(',')}-$suffix');
Expand Down

0 comments on commit b3b6041

Please sign in to comment.