From 375450e5c10aacd8fca4a39d0e793def9f5deebc Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Wed, 6 Jan 2021 15:18:12 +0530 Subject: [PATCH] feat: Added bold mentions in previews, added file names for last message --- lib/src/channel_preview.dart | 59 +++++++++++++++++++++++++------- lib/src/message_search_item.dart | 45 +++++++++++++++++++++++- 2 files changed, 90 insertions(+), 14 deletions(-) diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart index fe602b4a..840ff8c4 100644 --- a/lib/src/channel_preview.dart +++ b/lib/src/channel_preview.dart @@ -220,7 +220,9 @@ class ChannelPreview extends StatelessWidget { } else if (e.type == 'giphy') { return '[GIF]'; } - return null; + return e == lastMessage.attachments.last + ? e.title + : '${e.title}, '; }).where((e) => e != null), lastMessage.text ?? '', ]; @@ -228,22 +230,53 @@ class ChannelPreview extends StatelessWidget { text = parts.join(' '); } - return Text( - text, + return RichText( maxLines: 1, overflow: TextOverflow.ellipsis, - style: - StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( - color: StreamChatTheme.of(context) - .channelPreviewTheme - .subtitle - .color, - fontStyle: (lastMessage.isSystem || lastMessage.isDeleted) - ? FontStyle.italic - : FontStyle.normal, - ), + text: _getDisplayText( + text, + lastMessage.mentionedUsers, + StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( + color: StreamChatTheme.of(context) + .channelPreviewTheme + .subtitle + .color, + fontStyle: (lastMessage.isSystem || lastMessage.isDeleted) + ? FontStyle.italic + : FontStyle.normal), + StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( + color: StreamChatTheme.of(context) + .channelPreviewTheme + .subtitle + .color, + fontStyle: (lastMessage.isSystem || lastMessage.isDeleted) + ? FontStyle.italic + : FontStyle.normal, + fontWeight: FontWeight.bold), + ), ); }, ); } + + TextSpan _getDisplayText(String text, List mentions, + TextStyle normalTextStyle, TextStyle mentionsTextStyle) { + var textList = text.split(' '); + List resList = []; + for (var e in textList) { + if (mentions.any((element) => '@${element.name}' == e)) { + resList.add(TextSpan( + text: '$e ', + style: mentionsTextStyle, + )); + } else { + resList.add(TextSpan( + text: '$e ', + style: normalTextStyle, + )); + } + } + + return TextSpan(children: resList); + } } diff --git a/lib/src/message_search_item.dart b/lib/src/message_search_item.dart index 851659e1..be257578 100644 --- a/lib/src/message_search_item.dart +++ b/lib/src/message_search_item.dart @@ -113,7 +113,9 @@ class MessageSearchItem extends StatelessWidget { } else if (e.type == 'giphy') { return '[GIF]'; } - return null; + return e == message.attachments.last + ? (e.title ?? 'File') + : '${e.title ?? 'File'}, '; }).where((e) => e != null), message.text ?? '', ]; @@ -121,6 +123,26 @@ class MessageSearchItem extends StatelessWidget { text = parts.join(' '); } + return RichText( + maxLines: 1, + overflow: TextOverflow.ellipsis, + text: _getDisplayText( + text, + message.mentionedUsers, + StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( + fontStyle: (message.isSystem || message.isDeleted) + ? FontStyle.italic + : FontStyle.normal, + ), + StreamChatTheme.of(context).channelPreviewTheme.subtitle.copyWith( + fontStyle: (message.isSystem || message.isDeleted) + ? FontStyle.italic + : FontStyle.normal, + fontWeight: FontWeight.bold, + ), + ), + ); + return Text( text, maxLines: 1, @@ -132,4 +154,25 @@ class MessageSearchItem extends StatelessWidget { ), ); } + + TextSpan _getDisplayText(String text, List mentions, + TextStyle normalTextStyle, TextStyle mentionsTextStyle) { + var textList = text.split(' '); + List resList = []; + for (var e in textList) { + if (mentions.any((element) => '@${element.name}' == e)) { + resList.add(TextSpan( + text: '$e ', + style: mentionsTextStyle, + )); + } else { + resList.add(TextSpan( + text: '$e ', + style: normalTextStyle, + )); + } + } + + return TextSpan(children: resList); + } }