Skip to content

Commit aab5089

Browse files
committed
internal_link: Parse /near/ in narrow links
1 parent cb94d4e commit aab5089

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/model/internal_link.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ sealed class InternalLink {
120120
/// The result of parsing some URL that points to a narrow on a Zulip realm,
121121
/// when the narrow is of a type that this app understands.
122122
class NarrowLink extends InternalLink {
123-
NarrowLink(this.narrow, {required super.realmUrl});
123+
NarrowLink(this.narrow, this.nearMessageId, {required super.realmUrl});
124124

125125
final Narrow narrow;
126+
final int? nearMessageId;
126127
}
127128

128129
/// Try to parse the given URL as a page in this app, on `store`'s realm.
@@ -184,6 +185,7 @@ NarrowLink? _interpretNarrowSegments(List<String> segments, PerAccountStore stor
184185
ApiNarrowDm? dmElement;
185186
ApiNarrowWith? withElement;
186187
Set<IsOperand> isElementOperands = {};
188+
int? nearMessageId;
187189

188190
for (var i = 0; i < segments.length; i += 2) {
189191
final (operator, negated) = _parseOperator(segments[i]);
@@ -221,8 +223,11 @@ NarrowLink? _interpretNarrowSegments(List<String> segments, PerAccountStore stor
221223
// It is fine to have duplicates of the same [IsOperand].
222224
isElementOperands.add(IsOperand.fromRawString(operand));
223225

224-
case _NarrowOperator.near: // TODO(#82): support for near
225-
continue;
226+
case _NarrowOperator.near:
227+
if (nearMessageId != null) return null;
228+
final messageId = int.tryParse(operand, radix: 10);
229+
if (messageId == null) return null;
230+
nearMessageId = messageId;
226231

227232
case _NarrowOperator.unknown:
228233
return null;
@@ -264,7 +269,7 @@ NarrowLink? _interpretNarrowSegments(List<String> segments, PerAccountStore stor
264269
return null;
265270
}
266271

267-
return NarrowLink(narrow, realmUrl: store.realmUrl);
272+
return NarrowLink(narrow, nearMessageId, realmUrl: store.realmUrl);
268273
}
269274

270275
@JsonEnum(fieldRename: FieldRename.kebab, alwaysCreate: true)

test/model/internal_link_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ void main() {
380380
}
381381
});
382382

383+
// TODO(#1570): test parsing /near/ operator
384+
383385
group('unexpected link shapes are rejected', () {
384386
final testCases = [
385387
('/#narrow/stream/name/topic/', null), // missing operand

0 commit comments

Comments
 (0)