Skip to content

Commit 50eba89

Browse files
Khader-1gnprice
authored andcommitted
internal_link: Recognize channel operator in narrow links
Fixes: zulip#632
1 parent 09316ba commit 50eba89

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

lib/model/internal_link.dart

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Narrow? _interpretNarrowSegments(List<String> segments, PerAccountStore store) {
159159
final operand = segments[i + 1];
160160
switch (operator) {
161161
case _NarrowOperator.stream:
162+
case _NarrowOperator.channel:
162163
if (streamElement != null) return null;
163164
final streamId = _parseStreamOperand(operand, store);
164165
if (streamId == null) return null;
@@ -207,6 +208,7 @@ enum _NarrowOperator {
207208
near,
208209
pmWith,
209210
stream,
211+
channel,
210212
subject,
211213
topic,
212214
unknown;

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

+35-12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import 'package:zulip/model/store.dart';
99
import '../example_data.dart' as eg;
1010
import 'test_store.dart';
1111

12+
// Using Set instead of List in to avoid any duplicated test urls.
13+
Set<String> getUrlSyntaxVariants(String urlString) {
14+
final urlWithChannelSyntax = urlString.replaceFirst('#narrow/stream', '#narrow/channel');
15+
final urlWithStreamSyntax = urlString.replaceFirst('#narrow/channel', '#narrow/stream');
16+
return {urlWithStreamSyntax, urlWithChannelSyntax};
17+
}
18+
1219
Future<PerAccountStore> setupStore({
1320
required Uri realmUrl,
1421
List<ZulipStream>? streams,
@@ -36,12 +43,14 @@ void main() {
3643
assert(streams != null || users != null);
3744
for (final testCase in testCases) {
3845
final String urlString = testCase.$1;
39-
final Narrow? expected = testCase.$2;
40-
test(urlString, () async {
41-
final store = await setupStore(realmUrl: realmUrl, streams: streams, users: users);
42-
final url = store.tryResolveUrl(urlString)!;
43-
check(parseInternalLink(url, store)).equals(expected);
44-
});
46+
for (final urlString in getUrlSyntaxVariants(urlString)) {
47+
final Narrow? expected = testCase.$2;
48+
test(urlString, () async {
49+
final store = await setupStore(realmUrl: realmUrl, streams: streams, users: users);
50+
final url = store.tryResolveUrl(urlString)!;
51+
check(parseInternalLink(url, store)).equals(expected);
52+
});
53+
}
4554
}
4655
}
4756

@@ -131,12 +140,14 @@ void main() {
131140
final String description = testCase.$2;
132141
final String urlString = testCase.$3;
133142
final Uri realmUrl = testCase.$4;
134-
test('${expected ? 'accepts': 'rejects'} $description: $urlString', () async {
135-
final store = await setupStore(realmUrl: realmUrl, streams: streams);
136-
final url = store.tryResolveUrl(urlString)!;
137-
final result = parseInternalLink(url, store);
138-
check(result != null).equals(expected);
139-
});
143+
for (final urlString in getUrlSyntaxVariants(urlString)) {
144+
test('${expected ? 'accepts': 'rejects'} $description: $urlString', () async {
145+
final store = await setupStore(realmUrl: realmUrl, streams: streams);
146+
final url = store.tryResolveUrl(urlString)!;
147+
final result = parseInternalLink(url, store);
148+
check(result != null).equals(expected);
149+
});
150+
}
140151
}
141152
});
142153

@@ -169,6 +180,18 @@ void main() {
169180
testExpectedNarrows(testCases, streams: streams);
170181
});
171182

183+
group('Both `stream` and `channel` can be used interchangeably', () {
184+
const testCases = [
185+
('/#narrow/stream/check', StreamNarrow(1)),
186+
('/#narrow/channel/check', StreamNarrow(1)),
187+
('/#narrow/stream/check/topic/test', TopicNarrow(1, 'test')),
188+
('/#narrow/channel/check/topic/test', TopicNarrow(1, 'test')),
189+
('/#narrow/stream/check/topic/test/near/378333', TopicNarrow(1, 'test')),
190+
('/#narrow/channel/check/topic/test/near/378333', TopicNarrow(1, 'test')),
191+
];
192+
testExpectedNarrows(testCases, streams: streams);
193+
});
194+
172195
group('"/#narrow/dm/<...>" returns expected DmNarrow', () {
173196
final expectedNarrow = DmNarrow.withUsers([1, 2],
174197
selfUserId: eg.selfUser.userId);

0 commit comments

Comments
 (0)