Skip to content

Commit 0edabbf

Browse files
content: Handle @-topic mentions
Fixes: #892
1 parent 28b3536 commit 0edabbf

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

lib/model/content.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,9 @@ class _ZulipContentParser {
876876
final debugHtmlNode = kDebugMode ? element : null;
877877

878878
final classes = element.className.split(' ')..sort();
879-
assert(classes.contains('user-mention')
880-
|| classes.contains('user-group-mention'));
879+
assert(classes.contains('topic-mention')
880+
|| classes.contains('user-mention')
881+
|| classes.contains('user-group-mention'));
881882
int i = 0;
882883

883884
if (i >= classes.length) return null;
@@ -895,12 +896,14 @@ class _ZulipContentParser {
895896
}
896897

897898
if (i >= classes.length) return null;
898-
if (classes[i] == 'user-mention'
899+
if ((classes[i] == 'topic-mention' && !hasChannelWildcardClass)
900+
|| classes[i] == 'user-mention'
899901
|| (classes[i] == 'user-group-mention' && !hasChannelWildcardClass)) {
900902
// The class we already knew we'd find before we called this function.
901903
// We ignore the distinction between these; see [UserMentionNode].
902904
// Also, we don't expect "user-group-mention" and "channel-wildcard-mention"
903-
// to be in the list at the same time.
905+
// to be in the list at the same time and neither we expect "topic-mention"
906+
// and "channel-wildcard-mention" to be in the list at the same time.
904907
i++;
905908
}
906909

@@ -931,9 +934,9 @@ class _ZulipContentParser {
931934
/// Matches all className values that could be a UserMentionNode,
932935
/// and no className values that could be any other type of node.
933936
// Specifically, checks for `user-mention` or `user-group-mention`
934-
// as a member of the list.
937+
// or `topic-mention` as a member of the list.
935938
static final _userMentionClassNameRegexp = RegExp(
936-
r"(^| )" r"user(?:-group)?-mention" r"( |$)");
939+
r"(^| )" r"(?:user(?:-group)?|topic)-mention" r"( |$)");
937940

938941
static final _emojiClassNameRegexp = () {
939942
const specificEmoji = r"emoji(?:-[0-9a-f]+)+";

test/model/content_test.dart

+25
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ class ContentExample {
181181
'<p><span class="silent user-mention" data-user-id="*">all</span></p>',
182182
const UserMentionNode(nodes: [TextNode('all')]));
183183

184+
static final topicMentionPlain = ContentExample.inline(
185+
'plain @-topic',
186+
"@**topic**",
187+
expectedText: '@topic',
188+
'<p><span class="topic-mention">@topic</span></p>',
189+
const UserMentionNode(nodes: [TextNode('@topic')]));
190+
191+
static final topicMentionSilent = ContentExample.inline(
192+
'silent @-topic',
193+
"@_**topic**",
194+
expectedText: 'topic',
195+
'<p><span class="topic-mention silent">topic</span></p>',
196+
const UserMentionNode(nodes: [TextNode('topic')]));
197+
198+
static final topicMentionSilentClassOrderReversed = ContentExample.inline(
199+
'silent @-topic, class order reversed',
200+
"@_**topic**", // (hypothetical server variation)
201+
expectedText: 'topic',
202+
'<p><span class="silent topic-mention">topic</span></p>',
203+
const UserMentionNode(nodes: [TextNode('topic')]));
204+
184205
static final emojiUnicode = ContentExample.inline(
185206
'Unicode emoji, encoded in span element',
186207
":thumbs_up:",
@@ -1262,6 +1283,10 @@ void main() {
12621283
testParseExample(ContentExample.legacyChannelWildcardMentionPlain);
12631284
testParseExample(ContentExample.legacyChannelWildcardMentionSilent);
12641285
testParseExample(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);
1286+
1287+
testParseExample(ContentExample.topicMentionPlain);
1288+
testParseExample(ContentExample.topicMentionSilent);
1289+
testParseExample(ContentExample.topicMentionSilentClassOrderReversed);
12651290
});
12661291

12671292
testParseExample(ContentExample.emojiUnicode);

test/widgets/content_test.dart

+3
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ void main() {
669669
testContentSmoke(ContentExample.legacyChannelWildcardMentionPlain);
670670
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilent);
671671
testContentSmoke(ContentExample.legacyChannelWildcardMentionSilentClassOrderReversed);
672+
testContentSmoke(ContentExample.topicMentionPlain);
673+
testContentSmoke(ContentExample.topicMentionSilent);
674+
testContentSmoke(ContentExample.topicMentionSilentClassOrderReversed);
672675

673676
UserMention? findUserMentionInSpan(InlineSpan rootSpan) {
674677
UserMention? result;

0 commit comments

Comments
 (0)