feat: Added bold mentions in previews, added file names for last message

This commit is contained in:
Deven Joshi
2021-01-06 15:18:12 +05:30
parent 6774680b75
commit 375450e5c1
2 changed files with 90 additions and 14 deletions
+46 -13
View File
@@ -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<User> mentions,
TextStyle normalTextStyle, TextStyle mentionsTextStyle) {
var textList = text.split(' ');
List<TextSpan> 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);
}
}
+44 -1
View File
@@ -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<User> mentions,
TextStyle normalTextStyle, TextStyle mentionsTextStyle) {
var textList = text.split(' ');
List<TextSpan> 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);
}
}