fix(ui): fix channel list tile style for mentioned users

Signed-off-by: xsahil03x <xdsahil@gmail.com>
This commit is contained in:
Sahil Kumar
2022-03-17 14:02:51 +05:30
committed by xsahil03x
parent 03fceb04ca
commit 2b09747cb1
2 changed files with 32 additions and 6 deletions
@@ -367,6 +367,11 @@ class ChannelLastMessageText extends StatelessWidget {
final lastMessageAttachments = lastMessage.attachments;
final lastMessageMentionedUsers = lastMessage.mentionedUsers;
final mentionedUsersRegex = RegExp(
lastMessageMentionedUsers.map((it) => '@${it.name}').join('|'),
caseSensitive: false,
);
final messageTextParts = [
...lastMessageAttachments.map((it) {
if (it.type == 'image') {
@@ -380,7 +385,11 @@ class ChannelLastMessageText extends StatelessWidget {
? (it.title ?? 'File')
: '${it.title ?? 'File'} , ';
}),
if (lastMessageText != null) lastMessageText,
if (lastMessageText != null)
if (lastMessageMentionedUsers.isNotEmpty)
...mentionedUsersRegex.allMatchesWithSep(lastMessageText)
else
lastMessageText,
];
final fontStyle = (lastMessage.isSystem || lastMessage.isDeleted)
@@ -399,7 +408,7 @@ class ChannelLastMessageText extends StatelessWidget {
if (lastMessageMentionedUsers.isNotEmpty &&
lastMessageMentionedUsers.any((it) => '@${it.name}' == part))
TextSpan(
text: '$part ',
text: part,
style: mentionsTextStyle,
)
else if (lastMessageAttachments.isNotEmpty &&
@@ -407,12 +416,14 @@ class ChannelLastMessageText extends StatelessWidget {
.where((it) => it.title != null)
.any((it) => it.title == part))
TextSpan(
text: '$part ',
style: regularTextStyle,
text: part,
style: regularTextStyle?.copyWith(
fontStyle: FontStyle.italic,
),
)
else
TextSpan(
text: part == messageTextParts.last ? part : '$part ',
text: part,
style: regularTextStyle,
),
];
@@ -426,3 +437,18 @@ class ChannelLastMessageText extends StatelessWidget {
},
);
}
extension _RegExpX on RegExp {
List<String> allMatchesWithSep(String input, [int start = 0]) {
final result = <String>[];
for (final match in allMatches(input, start)) {
result.add(input.substring(start, match.start));
// ignore: cascade_invocations
result.add(match[0]!);
// ignore: parameter_assignments
start = match.end;
}
result.add(input.substring(start));
return result;
}
}
@@ -71,7 +71,7 @@ void main() {
child: StreamChannel(
channel: channel,
child: Scaffold(
body: StreamChannelPreview(
body: ChannelPreview(
channel: channel,
),
),