@@ -109,6 +109,22 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
109109 return result;
110110}
111111
112+ /// The result of parsing some URL within a Zulip realm,
113+ /// when the URL corresponds to some page in this app.
114+ sealed class InternalLink {
115+ InternalLink ({required this .realmUrl});
116+
117+ final Uri realmUrl;
118+ }
119+
120+ /// The result of parsing some URL that points to a narrow on a Zulip realm,
121+ /// when the narrow is of a type that this app understands.
122+ class NarrowLink extends InternalLink {
123+ NarrowLink (this .narrow, {required super .realmUrl});
124+
125+ final Narrow narrow;
126+ }
127+
112128/// A [Narrow] from a given URL, on `store` 's realm.
113129///
114130/// `url` must already be a result from [PerAccountStore.tryResolveUrl]
@@ -131,7 +147,7 @@ Narrow? parseInternalLink(Uri url, PerAccountStore store) {
131147 switch (category) {
132148 case 'narrow' :
133149 if (segments.isEmpty || ! segments.length.isEven) return null ;
134- return _interpretNarrowSegments (segments, store);
150+ return _interpretNarrowSegments (segments, store)? .narrow ;
135151 }
136152 return null ;
137153}
@@ -155,7 +171,7 @@ bool _isInternalLink(Uri url, Uri realmUrl) {
155171 return (category, segments);
156172}
157173
158- Narrow ? _interpretNarrowSegments (List <String > segments, PerAccountStore store) {
174+ NarrowLink ? _interpretNarrowSegments (List <String > segments, PerAccountStore store) {
159175 assert (segments.isNotEmpty);
160176 assert (segments.length.isEven);
161177
@@ -209,16 +225,17 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
209225 }
210226 }
211227
228+ final Narrow ? narrow;
212229 if (isElementOperands.isNotEmpty) {
213230 if (streamElement != null || topicElement != null || dmElement != null || withElement != null ) {
214231 return null ;
215232 }
216233 if (isElementOperands.length > 1 ) return null ;
217234 switch (isElementOperands.single) {
218235 case IsOperand .mentioned:
219- return const MentionsNarrow ();
236+ narrow = const MentionsNarrow ();
220237 case IsOperand .starred:
221- return const StarredMessagesNarrow ();
238+ narrow = const StarredMessagesNarrow ();
222239 case IsOperand .dm:
223240 case IsOperand .private:
224241 case IsOperand .alerted:
@@ -230,17 +247,20 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
230247 }
231248 } else if (dmElement != null ) {
232249 if (streamElement != null || topicElement != null || withElement != null ) return null ;
233- return DmNarrow .withUsers (dmElement.operand, selfUserId: store.selfUserId);
250+ narrow = DmNarrow .withUsers (dmElement.operand, selfUserId: store.selfUserId);
234251 } else if (streamElement != null ) {
235252 final streamId = streamElement.operand;
236253 if (topicElement != null ) {
237- return TopicNarrow (streamId, topicElement.operand, with_: withElement? .operand);
254+ narrow = TopicNarrow (streamId, topicElement.operand, with_: withElement? .operand);
238255 } else {
239256 if (withElement != null ) return null ;
240- return ChannelNarrow (streamId);
257+ narrow = ChannelNarrow (streamId);
241258 }
259+ } else {
260+ return null ;
242261 }
243- return null ;
262+
263+ return NarrowLink (narrow, realmUrl: store.realmUrl);
244264}
245265
246266@JsonEnum (fieldRename: FieldRename .kebab, alwaysCreate: true )
0 commit comments