Skip to content

Commit c16f1ba

Browse files
committed
msglist: Consolidate avatar, name, and time in message sender
Adjusted 'fetch older messages on scroll' test as adjusted layout is more compact given consecutive messages with the same sender.
1 parent 7bd88af commit c16f1ba

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

lib/widgets/message_list.dart

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,9 @@ String formatHeaderDate(
841841
}
842842

843843
/// A Zulip message, showing the sender's name and avatar if specified.
844+
// Design referenced from:
845+
// - https://github.com/zulip/zulip-mobile/issues/5511
846+
// - https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?type=design&node-id=144-12134&mode=design&t=Vkvdz5hmNVd5um1u-0
844847
class MessageWithPossibleSender extends StatelessWidget {
845848
const MessageWithPossibleSender({super.key, required this.item});
846849

@@ -850,62 +853,65 @@ class MessageWithPossibleSender extends StatelessWidget {
850853
Widget build(BuildContext context) {
851854
final message = item.message;
852855

853-
final senderRow = item.showSender
856+
final Widget? senderRow = item.showSender
854857
? Padding(
855858
padding: const EdgeInsets.fromLTRB(3, 6, 11, 0),
856-
child: GestureDetector(
857-
onTap: () => Navigator.push(context,
858-
ProfilePage.buildRoute(context: context,
859-
userId: message.senderId)),
860-
child: Avatar(size: 35, borderRadius: 4,
861-
userId: message.senderId)))
862-
: const SizedBox(width: 3 + 35 + 11);
859+
child: Row(
860+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
861+
crossAxisAlignment: CrossAxisAlignment.baseline,
862+
textBaseline: TextBaseline.alphabetic,
863+
children: [
864+
Flexible(
865+
child: GestureDetector(
866+
onTap: () => Navigator.push(context,
867+
ProfilePage.buildRoute(context: context,
868+
userId: message.senderId)),
869+
child: Row(
870+
children: [
871+
Avatar(size: 32, borderRadius: 3, userId: message.senderId),
872+
const SizedBox(width: 8),
873+
Flexible(
874+
child: Text(message.senderFullName, // TODO get from user data
875+
style: const TextStyle(
876+
fontFamily: 'Source Sans 3',
877+
fontSize: 18,
878+
height: (22 / 18),
879+
).merge(weightVariableTextStyle(context, wght: 600,
880+
wghtIfPlatformRequestsBold: 900)),
881+
overflow: TextOverflow.ellipsis)),
882+
]))),
883+
Text(
884+
_kMessageTimestampFormat.format(
885+
DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp)),
886+
style: TextStyle(
887+
color: _kMessageTimestampColor,
888+
fontFamily: 'Source Sans 3',
889+
fontSize: 16,
890+
height: (18 / 16),
891+
fontFeatures: const [FontFeature.enable('c2sc'), FontFeature.enable('smcp')],
892+
).merge(weightVariableTextStyle(context))),
893+
]))
894+
: null;
863895

864896
return GestureDetector(
865897
behavior: HitTestBehavior.translucent,
866898
onLongPress: () => showMessageActionSheet(context: context, message: message),
867-
// TODO clean up this layout, by less precisely imitating web
868899
child: Padding(
869900
padding: const EdgeInsets.only(top: 2, bottom: 3, left: 8, right: 8),
870901
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
871-
senderRow,
872902
Expanded(
873903
child: Column(
874904
crossAxisAlignment: CrossAxisAlignment.stretch,
875905
children: [
876-
if (item.showSender) ...[
906+
if (senderRow != null) ...[
877907
const SizedBox(height: 3),
878-
GestureDetector(
879-
onTap: () => Navigator.push(context,
880-
ProfilePage.buildRoute(context: context,
881-
userId: message.senderId)),
882-
child: Text(message.senderFullName, // TODO get from user data
883-
style: const TextStyle(
884-
fontFamily: 'Source Sans 3',
885-
fontSize: 18,
886-
height: (22 / 18),
887-
).merge(weightVariableTextStyle(context, wght: 600,
888-
wghtIfPlatformRequestsBold: 900)))),
908+
senderRow,
889909
const SizedBox(height: 4),
890910
],
891911
MessageContent(message: message, content: item.content),
892912
if ((message.reactions?.total ?? 0) > 0)
893913
ReactionChipsList(messageId: message.id, reactions: message.reactions!)
894914
])),
895-
Container(
896-
width: 80,
897-
padding: const EdgeInsets.only(top: 4, right: 16 - 8),
898-
alignment: Alignment.topRight,
899-
child: Text(
900-
_kMessageTimestampFormat.format(
901-
DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp)),
902-
style: TextStyle(
903-
color: _kMessageTimestampColor,
904-
fontFamily: 'Source Sans 3',
905-
fontSize: 16,
906-
height: (18 / 16),
907-
fontFeatures: const [FontFeature.enable('c2sc'), FontFeature.enable('smcp')],
908-
).merge(weightVariableTextStyle(context)))),
909915
])));
910916
}
911917
}

test/widgets/message_list_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void main() {
8686

8787
testWidgets('basic', (tester) async {
8888
await setupMessageListPage(tester, foundOldest: false,
89-
messages: List.generate(200, (i) => eg.streamMessage(id: 950 + i, sender: eg.selfUser)));
90-
check(itemCount(tester)).equals(203);
89+
messages: List.generate(300, (i) => eg.streamMessage(id: 950 + i, sender: eg.selfUser)));
90+
check(itemCount(tester)).equals(303);
9191

9292
// Fling-scroll upward...
9393
await tester.fling(find.byType(MessageListPage), const Offset(0, 300), 8000);
@@ -100,7 +100,7 @@ void main() {
100100
await tester.pump(Duration.zero); // Allow a frame for the response to arrive.
101101

102102
// Now we have more messages.
103-
check(itemCount(tester)).equals(303);
103+
check(itemCount(tester)).equals(403);
104104
});
105105

106106
testWidgets('observe double-fetch glitch', (tester) async {

0 commit comments

Comments
 (0)