Skip to content

Commit c971bb6

Browse files
committed
internal_link [nfc]: Factor out constructing fragment in its own method
This will make it easy to use the fragment string in several other places, such as in the next commits where we need to create a fallback markdown link for a channel.
1 parent 854f58a commit c971bb6

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/model/internal_link.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ String? decodeHashComponent(String str) {
5858
// When you want to point the server to a location in a message list, you
5959
// you do so by passing the `anchor` param.
6060
Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
61+
final fragment = narrowLinkFragment(store, narrow, nearMessageId: nearMessageId);
62+
Uri result = store.realmUrl.replace(fragment: fragment);
63+
if (result.path.isEmpty) {
64+
// Always ensure that there is a '/' right after the hostname.
65+
// A generated URL without '/' looks odd,
66+
// and if used in a Zulip message does not get automatically linkified.
67+
result = result.replace(path: '/');
68+
}
69+
return result;
70+
}
71+
72+
String narrowLinkFragment(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
6173
// TODO(server-7)
6274
final apiNarrow = resolveApiNarrowForServer(
6375
narrow.apiEncode(), store.zulipFeatureLevel);
@@ -101,14 +113,7 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
101113
fragment.write('/near/$nearMessageId');
102114
}
103115

104-
Uri result = store.realmUrl.replace(fragment: fragment.toString());
105-
if (result.path.isEmpty) {
106-
// Always ensure that there is a '/' right after the hostname.
107-
// A generated URL without '/' looks odd,
108-
// and if used in a Zulip message does not get automatically linkified.
109-
result = result.replace(path: '/');
110-
}
111-
return result;
116+
return fragment.toString();
112117
}
113118

114119
/// The result of parsing some URL within a Zulip realm,

0 commit comments

Comments
 (0)