Skip to content

Commit

Permalink
msglist: Use distinct background colors for DM messages.
Browse files Browse the repository at this point in the history
This commit modifies DmMessage and its DateSeparator to use a
different background color from StreamMessage.

Fixes #681.
  • Loading branch information
E-m-i-n-e-n-c-e committed Jan 29, 2025
1 parent 55fdfd3 commit c160864
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
static final light = MessageListTheme._(
dateSeparator: Colors.black,
dateSeparatorText: const HSLColor.fromAHSL(0.75, 0, 0, 0.15).toColor(),
dmMessageBgDefault: const HSLColor.fromAHSL(1, 45, 0.20, 0.96).toColor(),
dmRecipientHeaderBg: const HSLColor.fromAHSL(1, 46, 0.35, 0.93).toColor(),
messageTimestamp: const HSLColor.fromAHSL(0.8, 0, 0, 0.2).toColor(),
recipientHeaderText: const HSLColor.fromAHSL(1, 0, 0, 0.15).toColor(),
Expand All @@ -55,6 +56,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
static final dark = MessageListTheme._(
dateSeparator: Colors.white,
dateSeparatorText: const HSLColor.fromAHSL(0.75, 0, 0, 1).toColor(),
dmMessageBgDefault: const HSLColor.fromAHSL(1, 46, 0.07, 0.16).toColor(),
dmRecipientHeaderBg: const HSLColor.fromAHSL(1, 46, 0.15, 0.2).toColor(),
messageTimestamp: const HSLColor.fromAHSL(0.8, 0, 0, 0.85).toColor(),
recipientHeaderText: const HSLColor.fromAHSL(0.8, 0, 0, 1).toColor(),
Expand All @@ -79,6 +81,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
MessageListTheme._({
required this.dateSeparator,
required this.dateSeparatorText,
required this.dmMessageBgDefault,
required this.dmRecipientHeaderBg,
required this.messageTimestamp,
required this.recipientHeaderText,
Expand All @@ -103,6 +106,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {

final Color dateSeparator;
final Color dateSeparatorText;
final Color dmMessageBgDefault;
final Color dmRecipientHeaderBg;
final Color messageTimestamp;
final Color recipientHeaderText;
Expand All @@ -118,6 +122,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
MessageListTheme copyWith({
Color? dateSeparator,
Color? dateSeparatorText,
Color? dmMessageBgDefault,
Color? dmRecipientHeaderBg,
Color? messageTimestamp,
Color? recipientHeaderText,
Expand All @@ -132,6 +137,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
return MessageListTheme._(
dateSeparator: dateSeparator ?? this.dateSeparator,
dateSeparatorText: dateSeparatorText ?? this.dateSeparatorText,
dmMessageBgDefault: dmMessageBgDefault ?? this.dmMessageBgDefault,
dmRecipientHeaderBg: dmRecipientHeaderBg ?? this.dmRecipientHeaderBg,
messageTimestamp: messageTimestamp ?? this.messageTimestamp,
recipientHeaderText: recipientHeaderText ?? this.recipientHeaderText,
Expand All @@ -153,6 +159,7 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
return MessageListTheme._(
dateSeparator: Color.lerp(dateSeparator, other.dateSeparator, t)!,
dateSeparatorText: Color.lerp(dateSeparatorText, other.dateSeparatorText, t)!,
dmMessageBgDefault: Color.lerp(dmMessageBgDefault, other.dmMessageBgDefault, t)!,
dmRecipientHeaderBg: Color.lerp(streamMessageBgDefault, other.dmRecipientHeaderBg, t)!,
messageTimestamp: Color.lerp(messageTimestamp, other.messageTimestamp, t)!,
recipientHeaderText: Color.lerp(recipientHeaderText, other.recipientHeaderText, t)!,
Expand All @@ -167,6 +174,14 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
}
}

/// Helper function to get the background color for a message based on its type.
Color getMessageBackgroundColor(Message message, MessageListTheme messageListTheme) {
return switch (message) {
StreamMessage() => messageListTheme.streamMessageBgDefault,
DmMessage() => messageListTheme.dmMessageBgDefault,
};
}

/// The interface for the state of a [MessageListPage].
///
/// To obtain one of these, see [MessageListPage.ancestorOf].
Expand Down Expand Up @@ -924,8 +939,9 @@ class DateSeparator extends StatelessWidget {

final line = BorderSide(width: 0, color: messageListTheme.dateSeparator);

// TODO(#681) use different color for DM messages
return ColoredBox(color: messageListTheme.streamMessageBgDefault,
final backgroundColor = getMessageBackgroundColor(message, messageListTheme);

return ColoredBox(color: backgroundColor,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 2),
child: Row(children: [
Expand Down Expand Up @@ -966,13 +982,16 @@ class MessageItem extends StatelessWidget {
Widget build(BuildContext context) {
final message = item.message;
final messageListTheme = MessageListTheme.of(context);

final backgroundColor = getMessageBackgroundColor(message, messageListTheme);

return StickyHeaderItem(
allowOverflow: !item.isLastInBlock,
header: header,
child: _UnreadMarker(
isRead: message.flags.contains(MessageFlag.read),
child: ColoredBox(
color: messageListTheme.streamMessageBgDefault,
color: backgroundColor,
child: Column(children: [
MessageWithPossibleSender(item: item),
if (trailingWhitespace != null && item.isLastInBlock) SizedBox(height: trailingWhitespace!),
Expand Down

0 comments on commit c160864

Please sign in to comment.