Skip to content

Commit f2bca87

Browse files
committed
msglist: Show date in recipient headers
Fixes: zulip#172
1 parent da7f74e commit f2bca87

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

lib/widgets/message_list.dart

+30-6
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ class StreamTopicRecipientHeader extends StatelessWidget {
448448
style: const TextStyle(fontWeight: FontWeight.w600)))),
449449
// TODO topic links?
450450
// Then web also has edit/resolve/mute buttons. Skip those for mobile.
451+
RecipientHeaderDate(message: message),
451452
])));
452453
}
453454
}
@@ -486,17 +487,40 @@ class DmRecipientHeader extends StatelessWidget {
486487
decoration: BoxDecoration(
487488
color: Colors.white,
488489
border: Border.all(color: _kDmRecipientHeaderColor)),
489-
child: Align(
490-
alignment: Alignment.centerLeft,
491-
child: RecipientHeaderChevronContainer(
490+
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
491+
RecipientHeaderChevronContainer(
492492
color: _kDmRecipientHeaderColor,
493493
child: Text(style: const TextStyle(color: Colors.white),
494-
title)))));
494+
title)),
495+
RecipientHeaderDate(message: message),
496+
])));
495497
}
496498
}
497499

498-
final _kDmRecipientHeaderColor =
499-
const HSLColor.fromAHSL(1, 0, 0, 0.27).toColor();
500+
final _kDmRecipientHeaderColor = const HSLColor.fromAHSL(1, 0, 0, 0.27).toColor();
501+
502+
class RecipientHeaderDate extends StatelessWidget {
503+
const RecipientHeaderDate({super.key, required this.message});
504+
505+
final Message message;
506+
507+
@override
508+
Widget build(BuildContext context) {
509+
return Padding(
510+
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
511+
child: Text(
512+
style: _kRecipientHeaderDateStyle,
513+
_kRecipientHeaderDateFormat.format(
514+
DateTime.fromMillisecondsSinceEpoch(message.timestamp * 1000))));
515+
}
516+
}
517+
518+
final _kRecipientHeaderDateStyle = TextStyle(
519+
fontWeight: FontWeight.w600,
520+
color: const HSLColor.fromAHSL(0.75, 0, 0, 0.15).toColor(),
521+
);
522+
523+
final _kRecipientHeaderDateFormat = DateFormat('y-MM-dd', 'en_US'); // TODO(i18n)
500524

501525
/// A widget with the distinctive chevron-tailed shape in Zulip recipient headers.
502526
class RecipientHeaderChevronContainer extends StatelessWidget {

test/widgets/message_list_test.dart

+18
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ void main() {
201201
tester.widget(find.text("You and (unknown user)"));
202202
tester.widget(find.text("You and (unknown user), ${eg.thirdUser.fullName}"));
203203
});
204+
205+
testWidgets('show dates', (tester) async {
206+
await setupMessageListPage(tester, messages: [
207+
eg.streamMessage(timestamp: 1671409088),
208+
eg.dmMessage(timestamp: 1692755322, from: eg.selfUser, to: []),
209+
]);
210+
// We show the dates in the user's timezone. Dart's standard library
211+
// doesn't give us a way to control which timezone is used — only to
212+
// choose between UTC and the user's timezone, whatever that may be.
213+
// So we do the latter, and that means these dates come out differently
214+
// depending on the timezone in the environment running the tests.
215+
// Related upstream issues:
216+
// https://github.com/dart-lang/sdk/issues/28985 (about DateTime.now, not timezone)
217+
// https://github.com/dart-lang/sdk/issues/44928 (about the Dart implementation's own internal tests)
218+
// For this test, just accept outputs corresponding to any possible timezone.
219+
tester.widget(find.textContaining(RegExp("2022-12-1[89]")));
220+
tester.widget(find.textContaining(RegExp("2023-08-2[23]")));
221+
});
204222
});
205223

206224
group('MessageWithSender', () {

0 commit comments

Comments
 (0)