chore: Only load last event sender if necessary

pull/1146/head
Krille 2 years ago
parent 5829446afa
commit 147a741aef
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -89,6 +89,11 @@ class ChatListItem extends StatelessWidget {
if (filter != null && !displayname.toLowerCase().contains(filter)) {
return const SizedBox.shrink();
}
final needLastEventSender = lastEvent == null
? false
: room.getState(EventTypes.RoomMember, lastEvent.senderId) == null;
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
@ -226,12 +231,21 @@ class ChatListItem extends StatelessWidget {
maxLines: 1,
softWrap: false,
)
: Text(
room.membership == Membership.invite
? isDirectChat
? L10n.of(context)!.invitePrivateChat
: L10n.of(context)!.inviteGroupChat
: room.lastEvent?.calcLocalizedBodyFallback(
: FutureBuilder(
future: needLastEventSender
? room.lastEvent?.calcLocalizedBody(
MatrixLocals(L10n.of(context)!),
hideReply: true,
hideEdit: true,
plaintextBody: true,
removeMarkdown: true,
withSenderNamePrefix: !isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId,
)
: null,
initialData:
room.lastEvent?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)!),
hideReply: true,
hideEdit: true,
@ -240,7 +254,13 @@ class ChatListItem extends StatelessWidget {
withSenderNamePrefix: !isDirectChat ||
directChatMatrixId !=
room.lastEvent?.senderId,
) ??
),
builder: (context, snapshot) => Text(
room.membership == Membership.invite
? isDirectChat
? L10n.of(context)!.invitePrivateChat
: L10n.of(context)!.inviteGroupChat
: snapshot.data ??
L10n.of(context)!.emptyChat,
softWrap: false,
maxLines: 1,
@ -256,6 +276,7 @@ class ChatListItem extends StatelessWidget {
),
),
),
),
const SizedBox(width: 8),
AnimatedContainer(
duration: FluffyThemes.animationDuration,

Loading…
Cancel
Save