refactor: Event list

This commit is contained in:
krille-chan 2023-12-01 20:10:15 +01:00
parent aedc1c4123
commit e6fa844519
No known key found for this signature in database
2 changed files with 38 additions and 39 deletions

View file

@ -24,11 +24,15 @@ class ChatEventList extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0; final horizontalPadding = FluffyThemes.isColumnMode(context) ? 8.0 : 0.0;
final events = controller.timeline!.events
.where((event) => event.isVisibleInGui)
.toList();
// create a map of eventId --> index to greatly improve performance of // create a map of eventId --> index to greatly improve performance of
// ListView's findChildIndexCallback // ListView's findChildIndexCallback
final thisEventsKeyMap = <String, int>{}; final thisEventsKeyMap = <String, int>{};
for (var i = 0; i < controller.timeline!.events.length; i++) { for (var i = 0; i < events.length; i++) {
thisEventsKeyMap[controller.timeline!.events[i].eventId] = i; thisEventsKeyMap[events[i].eventId] = i;
} }
return SelectionArea( return SelectionArea(
@ -71,7 +75,7 @@ class ChatEventList extends StatelessWidget {
} }
// Request history button or progress indicator: // Request history button or progress indicator:
if (i == controller.timeline!.events.length + 1) { if (i == events.length + 1) {
if (controller.timeline!.isRequestingHistory) { if (controller.timeline!.isRequestingHistory) {
return const Center( return const Center(
child: CircularProgressIndicator.adaptive(strokeWidth: 2), child: CircularProgressIndicator.adaptive(strokeWidth: 2),
@ -87,16 +91,16 @@ class ChatEventList extends StatelessWidget {
} }
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
i--;
// The message at this index: // The message at this index:
final event = controller.timeline!.events[i - 1]; final event = events[i];
return AutoScrollTag( return AutoScrollTag(
key: ValueKey(event.eventId), key: ValueKey(event.eventId),
index: i - 1, index: i,
controller: controller.scrollController, controller: controller.scrollController,
child: event.isVisibleInGui child: Message(
? Message(
event, event,
onSwipe: () => controller.replyAction(replyTo: event), onSwipe: () => controller.replyAction(replyTo: event),
onInfoTab: controller.showEventInfo, onInfoTab: controller.showEventInfo,
@ -119,14 +123,11 @@ class ChatEventList extends StatelessWidget {
displayReadMarker: displayReadMarker:
controller.readMarkerEventId == event.eventId && controller.readMarkerEventId == event.eventId &&
controller.timeline?.allowNewEvent == false, controller.timeline?.allowNewEvent == false,
nextEvent: i < controller.timeline!.events.length nextEvent: i + 1 < events.length ? events[i + 1] : null,
? controller.timeline!.events[i] ),
: null,
)
: const SizedBox.shrink(),
); );
}, },
childCount: controller.timeline!.events.length + 2, childCount: events.length + 2,
findChildIndexCallback: (key) => findChildIndexCallback: (key) =>
controller.findChildIndexCallback(key, thisEventsKeyMap), controller.findChildIndexCallback(key, thisEventsKeyMap),
), ),

View file

@ -66,7 +66,7 @@ class Message extends StatelessWidget {
final client = Matrix.of(context).client; final client = Matrix.of(context).client;
final ownMessage = event.senderId == client.userID; final ownMessage = event.senderId == client.userID;
final alignment = ownMessage ? Alignment.topRight : Alignment.topLeft; final alignment = ownMessage ? Alignment.topRight : Alignment.topLeft;
var color = Theme.of(context).colorScheme.onInverseSurface; var color = Theme.of(context).colorScheme.surfaceVariant;
final displayTime = event.type == EventTypes.RoomCreate || final displayTime = event.type == EventTypes.RoomCreate ||
nextEvent == null || nextEvent == null ||
!event.originServerTs.sameEnvironment(nextEvent!.originServerTs); !event.originServerTs.sameEnvironment(nextEvent!.originServerTs);
@ -294,9 +294,7 @@ class Message extends StatelessWidget {
if (displayTime || selected) if (displayTime || selected)
Padding( Padding(
padding: displayTime padding: displayTime
? const EdgeInsets.symmetric( ? const EdgeInsets.symmetric(vertical: 8.0)
vertical: 8.0,
)
: EdgeInsets.zero, : EdgeInsets.zero,
child: Center( child: Center(
child: Material( child: Material(