Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content: Support the new class of channel wildcard mentions #1073

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,12 @@ class _ZulipContentParser {
}

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

static final _emojiClassNameRegexp = () {
Expand Down
50 changes: 49 additions & 1 deletion test/model/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,48 @@ class ContentExample {
'<p><span class="silent user-group-mention" data-user-group-id="186">test-empty</span></p>',
const UserMentionNode(nodes: [TextNode('test-empty')]));

static final channelWildcardMentionPlain = ContentExample.inline(
'plain channel wildcard @-mention',
"@**all**",
expectedText: '@all',
'<p><span class="user-mention channel-wildcard-mention" data-user-id="*">@all</span></p>',
const UserMentionNode(nodes: [TextNode('@all')]));

static final channelWildcardMentionSilent = ContentExample.inline(
'silent channel wildcard @-mention',
"@_**everyone**",
expectedText: 'everyone',
'<p><span class="user-mention channel-wildcard-mention silent" data-user-id="*">everyone</span></p>',
const UserMentionNode(nodes: [TextNode('everyone')]));

static final channelWildcardMentionSilentClassOrderReversed = ContentExample.inline(
'silent channel wildcard @-mention, class order reversed',
"@_**channel**", // (hypothetical server variation)
expectedText: 'channel',
'<p><span class="silent user-mention channel-wildcard-mention" data-user-id="*">channel</span></p>',
const UserMentionNode(nodes: [TextNode('channel')]));

static final legacyChannelWildcardMentionPlain = ContentExample.inline(
'legacy plain channel wildcard @-mention',
"@**channel**",
expectedText: '@channel',
'<p><span class="user-mention" data-user-id="*">@channel</span></p>',
const UserMentionNode(nodes: [TextNode('@channel')]));

static final legacyChannelWildcardMentionSilent = ContentExample.inline(
'legacy silent channel wildcard @-mention',
"@_**stream**",
expectedText: 'stream',
'<p><span class="user-mention silent" data-user-id="*">stream</span></p>',
const UserMentionNode(nodes: [TextNode('stream')]));

static final legacyChannelWildcardMentionSilentClassOrderReversed = ContentExample.inline(
'legacy silent channel wildcard @-mention, class order reversed',
"@_**all**", // (hypothetical server variation)
expectedText: 'all',
'<p><span class="silent user-mention" data-user-id="*">all</span></p>',
const UserMentionNode(nodes: [TextNode('all')]));

static final emojiUnicode = ContentExample.inline(
'Unicode emoji, encoded in span element',
":thumbs_up:",
Expand Down Expand Up @@ -1013,7 +1055,13 @@ void main() {
testParseExample(ContentExample.groupMentionSilent);
testParseExample(ContentExample.groupMentionSilentClassOrderReversed);

// TODO test wildcard mentions
testParseExample(ContentExample.channelWildcardMentionPlain);
testParseExample(ContentExample.channelWildcardMentionSilent);
testParseExample(ContentExample.channelWildcardMentionSilentClassOrderReversed);

testParseExample(ContentExample.legacyChannelWildcardMentionPlain);
testParseExample(ContentExample.legacyChannelWildcardMentionSilent);
testParseExample(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);
});

testParseExample(ContentExample.emojiUnicode);
Expand Down
6 changes: 6 additions & 0 deletions test/widgets/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,12 @@ void main() {
testContentSmoke(ContentExample.userMentionSilent);
testContentSmoke(ContentExample.groupMentionPlain);
testContentSmoke(ContentExample.groupMentionSilent);
testContentSmoke(ContentExample.channelWildcardMentionPlain);
testContentSmoke(ContentExample.channelWildcardMentionSilent);
testContentSmoke(ContentExample.channelWildcardMentionSilentClassOrderReversed);
testContentSmoke(ContentExample.legacyChannelWildcardMentionPlain);
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilent);
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);

UserMention? findUserMentionInSpan(InlineSpan rootSpan) {
UserMention? result;
Expand Down