From 3c4996ca1268e35867c7a15ce687f909d8381613 Mon Sep 17 00:00:00 2001 From: Sayed Mahmood Sayedi Date: Tue, 11 Jun 2024 19:01:55 +0430 Subject: [PATCH] internal_link: Parse topic permalinks These links (`/with/NNNN`) are just accepted and ignored in this PR, they will be interpreted in #683. Fixes: #684 --- lib/model/internal_link.dart | 7 +++++-- lib/model/internal_link.g.dart | 1 + test/model/internal_link_test.dart | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/model/internal_link.dart b/lib/model/internal_link.dart index 72762256032..af6139ad52c 100644 --- a/lib/model/internal_link.dart +++ b/lib/model/internal_link.dart @@ -178,8 +178,9 @@ Narrow? _interpretNarrowSegments(List segments, PerAccountStore store) { if (dmIds == null) return null; dmElement = ApiNarrowDm(dmIds, negated: negated); - case _NarrowOperator.near: - continue; // TODO(#82): support for near + case _NarrowOperator.near: // TODO(#82): support for near + case _NarrowOperator.With: // TODO(#683): support for with + continue; case _NarrowOperator.unknown: return null; @@ -205,6 +206,8 @@ enum _NarrowOperator { // 'dm' is new in server-7.0; means the same as 'pm-with' dm, near, + // cannot use lowerCamelCase `with` as it is a reserved keyword in Dart + With, pmWith, stream, subject, diff --git a/lib/model/internal_link.g.dart b/lib/model/internal_link.g.dart index 7a6952c5d52..c28306414c0 100644 --- a/lib/model/internal_link.g.dart +++ b/lib/model/internal_link.g.dart @@ -11,6 +11,7 @@ part of 'internal_link.dart'; const _$_NarrowOperatorEnumMap = { _NarrowOperator.dm: 'dm', _NarrowOperator.near: 'near', + _NarrowOperator.With: 'with', _NarrowOperator.pmWith: 'pm-with', _NarrowOperator.stream: 'stream', _NarrowOperator.subject: 'subject', diff --git a/test/model/internal_link_test.dart b/test/model/internal_link_test.dart index 4b4a4b625e9..12633b6673e 100644 --- a/test/model/internal_link_test.dart +++ b/test/model/internal_link_test.dart @@ -161,9 +161,12 @@ void main() { const testCases = [ ('/#narrow/stream/check/topic/test', TopicNarrow(1, 'test')), ('/#narrow/stream/mobile/subject/topic/near/378333', TopicNarrow(3, 'topic')), + ('/#narrow/stream/mobile/subject/topic/with/1', TopicNarrow(3, 'topic')), ('/#narrow/stream/mobile/topic/topic/', TopicNarrow(3, 'topic')), ('/#narrow/stream/stream/topic/topic/near/1', TopicNarrow(5, 'topic')), + ('/#narrow/stream/stream/topic/topic/with/22', TopicNarrow(5, 'topic')), ('/#narrow/stream/stream/subject/topic/near/1', TopicNarrow(5, 'topic')), + ('/#narrow/stream/stream/subject/topic/with/333', TopicNarrow(5, 'topic')), ('/#narrow/stream/stream/subject/topic', TopicNarrow(5, 'topic')), ]; testExpectedNarrows(testCases, streams: streams); @@ -175,7 +178,9 @@ void main() { final testCases = [ ('/#narrow/dm/1,2-group', expectedNarrow), ('/#narrow/dm/1,2-group/near/1', expectedNarrow), + ('/#narrow/dm/1,2-group/with/2', expectedNarrow), ('/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3', null), + ('/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/4', null), ]; testExpectedNarrows(testCases, streams: streams); }); @@ -186,7 +191,9 @@ void main() { final testCases = [ ('/#narrow/pm-with/1,2-group', expectedNarrow), ('/#narrow/pm-with/1,2-group/near/1', expectedNarrow), + ('/#narrow/pm-with/1,2-group/with/2', expectedNarrow), ('/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3', null), + ('/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/3', null), ]; testExpectedNarrows(testCases, streams: streams); });