backendTextFormat property
String
get
backendTextFormat
Converts the text to the format required by the backend.
The text is scanned for tags, and the display name of the tagged user is replaced by the user's ID.
Implementation
String get backendTextFormat {
String backendText = text;
List<(Match?, Match?)> matches = getTagMatchPairs(backendText);
while (matches.isNotEmpty) {
final (start as Match, end as Match) = matches[0];
final String tagName = backendText.substring(start.end, end.start);
if (_tagsToTaggables.containsKey(tagName)) {
final (String prefix, T taggable) = _tagsToTaggables[tagName]!;
if (taggable == null) {
// This should never happen, but it is better to be safe than sorry
backendText = backendText.replaceRange(start.start, end.end, '');
continue;
}
backendText = backendText.replaceRange(
start.start,
end.end,
'$prefix${toBackendConverter(taggable)} ',
);
}
// Redefine the matches because the replacement changed the text
matches = getTagMatchPairs(backendText);
}
return backendText;
}