Skip to content

Commit 71b23f5

Browse files
PIG208gnprice
authored andcommitted
internal_link: Parse "/is/mentioned" internal links.
As of now, we don't have generic for the "is" operator, but it will be a easy refactor once we do. Fixes #250. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 3e5c438 commit 71b23f5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/model/internal_link.dart

+12-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
154154
ApiNarrowStream? streamElement;
155155
ApiNarrowTopic? topicElement;
156156
ApiNarrowDm? dmElement;
157+
ApiNarrowIsMentioned? isMentionedElement;
157158

158159
for (var i = 0; i < segments.length; i += 2) {
159160
final (operator, negated) = _parseOperator(segments[i]);
@@ -181,6 +182,10 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
181182
if (dmIds == null) return null;
182183
dmElement = ApiNarrowDm(dmIds, negated: negated);
183184

185+
case _NarrowOperator.is_:
186+
if (isMentionedElement != null) return null;
187+
if (operand == 'mentioned') isMentionedElement = ApiNarrowIsMentioned();
188+
184189
case _NarrowOperator.near: // TODO(#82): support for near
185190
case _NarrowOperator.with_: // TODO(#683): support for with
186191
continue;
@@ -190,7 +195,10 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
190195
}
191196
}
192197

193-
if (dmElement != null) {
198+
if (isMentionedElement != null) {
199+
if (streamElement != null || topicElement != null || dmElement != null) return null;
200+
return const MentionsNarrow();
201+
} else if (dmElement != null) {
194202
if (streamElement != null || topicElement != null) return null;
195203
return DmNarrow.withUsers(dmElement.operand, selfUserId: store.selfUserId);
196204
} else if (streamElement != null) {
@@ -212,6 +220,9 @@ enum _NarrowOperator {
212220
// cannot use `with` as it is a reserved keyword in Dart
213221
@JsonValue('with')
214222
with_,
223+
// cannot use `is` as it is a reserved keyword in Dart
224+
@JsonValue('is')
225+
is_,
215226
pmWith,
216227
stream,
217228
channel,

lib/model/internal_link.g.dart

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/model/internal_link_test.dart

+14
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ void main() {
221221
testExpectedNarrows(testCases, streams: streams);
222222
});
223223

224+
group('"/#narrow/is/mentioned returns expected MentionsNarrow', () {
225+
final testCases = [
226+
('/#narrow/is/mentioned', const MentionsNarrow()),
227+
('/#narrow/is/mentioned/near/1', const MentionsNarrow()),
228+
('/#narrow/is/mentioned/with/2', const MentionsNarrow()),
229+
('/#narrow/channel/7-test-here/is/mentioned', null),
230+
('/#narrow/channel/check/topic/test/is/mentioned', null),
231+
('/#narrow/topic/test/is/mentioned', null),
232+
('/#narrow/dm/17327-Chris-Bobbe-(Test-Account)/is/mentioned', null),
233+
('/#narrow/-is/mentioned', null),
234+
];
235+
testExpectedNarrows(testCases, streams: streams);
236+
});
237+
224238
group('unexpected link shapes are rejected', () {
225239
final testCases = [
226240
('/#narrow/stream/name/topic/', null), // missing operand

0 commit comments

Comments
 (0)