Skip to content

Commit 964df02

Browse files
committed
content: Support the new class of channel wildcard mentions
For channel wildcard mentions, the class in the corresponding HTML used to be the same as the user mentions (class="user-mention"), but now there's an additional class added. Now it looks like the following: class="user-mention channel-wildcard-mention". Fixes: zulip#1064
1 parent 9e42f26 commit 964df02

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

lib/model/content.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,12 @@ class _ZulipContentParser {
808808
}
809809

810810
static final _userMentionClassNameRegexp = () {
811-
// This matches a class `user-mention` or `user-group-mention`,
812-
// plus an optional class `silent`, appearing in either order.
813-
const mentionClass = r"user(?:-group)?-mention";
814-
return RegExp("^(?:$mentionClass(?: silent)?|silent $mentionClass)\$");
811+
// This matches the classes `user-mention`, `user-group-mention`,
812+
// or `user-mention channel-wildcard-mention`, plus an optional
813+
// class `silent`, appearing in either order.
814+
const mentionClass = r"user(?:-group)?-mention|"
815+
"(?:user-mention channel-wildcard-mention)";
816+
return RegExp("^(?:$mentionClass)(?: silent)?|silent (?:$mentionClass)\$");
815817
}();
816818

817819
static final _emojiClassNameRegexp = () {

test/model/content_test.dart

+49-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,48 @@ class ContentExample {
139139
'<p><span class="silent user-group-mention" data-user-group-id="186">test-empty</span></p>',
140140
const UserMentionNode(nodes: [TextNode('test-empty')]));
141141

142+
static final channelWildcardMentionPlain = ContentExample.inline(
143+
'plain channel wildcard @-mention',
144+
"@**all**",
145+
expectedText: '@all',
146+
'<p><span class="user-mention channel-wildcard-mention" data-user-id="*">@all</span></p>',
147+
const UserMentionNode(nodes: [TextNode('@all')]));
148+
149+
static final channelWildcardMentionSilent = ContentExample.inline(
150+
'silent channel wildcard @-mention',
151+
"@_**everyone**",
152+
expectedText: 'everyone',
153+
'<p><span class="user-mention channel-wildcard-mention silent" data-user-id="*">everyone</span></p>',
154+
const UserMentionNode(nodes: [TextNode('everyone')]));
155+
156+
static final channelWildcardMentionSilentClassOrderReversed = ContentExample.inline(
157+
'silent channel wildcard @-mention, class order reversed',
158+
"@_**channel**", // (hypothetical server variation)
159+
expectedText: 'channel',
160+
'<p><span class="silent user-mention channel-wildcard-mention" data-user-id="*">channel</span></p>',
161+
const UserMentionNode(nodes: [TextNode('channel')]));
162+
163+
static final legacyChannelWildcardMentionPlain = ContentExample.inline(
164+
'legacy plain channel wildcard @-mention',
165+
"@**channel**",
166+
expectedText: '@channel',
167+
'<p><span class="user-mention" data-user-id="*">@channel</span></p>',
168+
const UserMentionNode(nodes: [TextNode('@channel')]));
169+
170+
static final legacyChannelWildcardMentionSilent = ContentExample.inline(
171+
'legacy silent channel wildcard @-mention',
172+
"@_**stream**",
173+
expectedText: 'stream',
174+
'<p><span class="user-mention silent" data-user-id="*">stream</span></p>',
175+
const UserMentionNode(nodes: [TextNode('stream')]));
176+
177+
static final legacyChannelWildcardMentionSilentClassOrderReversed = ContentExample.inline(
178+
'legacy silent channel wildcard @-mention, class order reversed',
179+
"@_**all**", // (hypothetical server variation)
180+
expectedText: 'all',
181+
'<p><span class="silent user-mention" data-user-id="*">all</span></p>',
182+
const UserMentionNode(nodes: [TextNode('all')]));
183+
142184
static final emojiUnicode = ContentExample.inline(
143185
'Unicode emoji, encoded in span element',
144186
":thumbs_up:",
@@ -1013,7 +1055,13 @@ void main() {
10131055
testParseExample(ContentExample.groupMentionSilent);
10141056
testParseExample(ContentExample.groupMentionSilentClassOrderReversed);
10151057

1016-
// TODO test wildcard mentions
1058+
testParseExample(ContentExample.channelWildcardMentionPlain);
1059+
testParseExample(ContentExample.channelWildcardMentionSilent);
1060+
testParseExample(ContentExample.channelWildcardMentionSilentClassOrderReversed);
1061+
1062+
testParseExample(ContentExample.legacyChannelWildcardMentionPlain);
1063+
testParseExample(ContentExample.legacyChannelWildcardMentionSilent);
1064+
testParseExample(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);
10171065
});
10181066

10191067
testParseExample(ContentExample.emojiUnicode);

test/widgets/content_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@ void main() {
626626
testContentSmoke(ContentExample.userMentionSilent);
627627
testContentSmoke(ContentExample.groupMentionPlain);
628628
testContentSmoke(ContentExample.groupMentionSilent);
629+
testContentSmoke(ContentExample.channelWildcardMentionPlain);
630+
testContentSmoke(ContentExample.channelWildcardMentionSilent);
631+
testContentSmoke(ContentExample.channelWildcardMentionSilentClassOrderReversed);
632+
testContentSmoke(ContentExample.legacyChannelWildcardMentionPlain);
633+
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilent);
634+
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);
629635

630636
UserMention? findUserMentionInSpan(InlineSpan rootSpan) {
631637
UserMention? result;

0 commit comments

Comments
 (0)