@@ -109,6 +109,22 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
109
109
return result;
110
110
}
111
111
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
+
112
128
/// A [Narrow] from a given URL, on `store` 's realm.
113
129
///
114
130
/// `url` must already be a result from [PerAccountStore.tryResolveUrl]
@@ -131,7 +147,7 @@ Narrow? parseInternalLink(Uri url, PerAccountStore store) {
131
147
switch (category) {
132
148
case 'narrow' :
133
149
if (segments.isEmpty || ! segments.length.isEven) return null ;
134
- return _interpretNarrowSegments (segments, store);
150
+ return _interpretNarrowSegments (segments, store)? .narrow ;
135
151
}
136
152
return null ;
137
153
}
@@ -155,7 +171,7 @@ bool _isInternalLink(Uri url, Uri realmUrl) {
155
171
return (category, segments);
156
172
}
157
173
158
- Narrow ? _interpretNarrowSegments (List <String > segments, PerAccountStore store) {
174
+ NarrowLink ? _interpretNarrowSegments (List <String > segments, PerAccountStore store) {
159
175
assert (segments.isNotEmpty);
160
176
assert (segments.length.isEven);
161
177
@@ -209,16 +225,17 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
209
225
}
210
226
}
211
227
228
+ final Narrow ? narrow;
212
229
if (isElementOperands.isNotEmpty) {
213
230
if (streamElement != null || topicElement != null || dmElement != null || withElement != null ) {
214
231
return null ;
215
232
}
216
233
if (isElementOperands.length > 1 ) return null ;
217
234
switch (isElementOperands.single) {
218
235
case IsOperand .mentioned:
219
- return const MentionsNarrow ();
236
+ narrow = const MentionsNarrow ();
220
237
case IsOperand .starred:
221
- return const StarredMessagesNarrow ();
238
+ narrow = const StarredMessagesNarrow ();
222
239
case IsOperand .dm:
223
240
case IsOperand .private:
224
241
case IsOperand .alerted:
@@ -230,17 +247,20 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
230
247
}
231
248
} else if (dmElement != null ) {
232
249
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);
234
251
} else if (streamElement != null ) {
235
252
final streamId = streamElement.operand;
236
253
if (topicElement != null ) {
237
- return TopicNarrow (streamId, topicElement.operand, with_: withElement? .operand);
254
+ narrow = TopicNarrow (streamId, topicElement.operand, with_: withElement? .operand);
238
255
} else {
239
256
if (withElement != null ) return null ;
240
- return ChannelNarrow (streamId);
257
+ narrow = ChannelNarrow (streamId);
241
258
}
259
+ } else {
260
+ return null ;
242
261
}
243
- return null ;
262
+
263
+ return NarrowLink (narrow, realmUrl: store.realmUrl);
244
264
}
245
265
246
266
@JsonEnum (fieldRename: FieldRename .kebab, alwaysCreate: true )
0 commit comments