Skip to content

Commit d21d76b

Browse files
committed
content [nfc]: Expand parseUserMention to a more sequential structure
This should further help make space for adding more logic here, both for the "channel-wildcard-mention" class (#1064) and for distinguishing different types of mentions (#646, #647).
1 parent 07f882d commit d21d76b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

lib/model/content.dart

+18-6
Original file line numberDiff line numberDiff line change
@@ -878,12 +878,24 @@ class _ZulipContentParser {
878878
final classes = element.className.split(' ')..sort();
879879
assert(classes.contains('user-mention')
880880
|| classes.contains('user-group-mention'));
881-
switch (classes) {
882-
case ['user-mention' || 'user-group-mention']:
883-
case ['silent', 'user-mention' || 'user-group-mention']:
884-
break;
885-
default:
886-
return null;
881+
int i = 0;
882+
883+
if (i >= classes.length) return null;
884+
if (classes[i] == 'silent') {
885+
// A silent @-mention. We ignore this flag; see [UserMentionNode].
886+
i++;
887+
}
888+
889+
if (i >= classes.length) return null;
890+
if (classes[i] == 'user-mention' || classes[i] == 'user-group-mention') {
891+
// The class we already knew we'd find before we called this function.
892+
// We ignore the distinction between these; see [UserMentionNode].
893+
i++;
894+
}
895+
896+
if (i != classes.length) {
897+
// There was some class we didn't expect.
898+
return null;
887899
}
888900

889901
// TODO assert UserMentionNode can't contain LinkNode;

0 commit comments

Comments
 (0)