mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 13:05:11 +00:00
refactor: Event list
This commit is contained in:
parent
aedc1c4123
commit
e6fa844519
2 changed files with 38 additions and 39 deletions
|
@ -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,46 +91,43 @@ 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,
|
onAvatarTab: (Event event) => showAdaptiveBottomSheet(
|
||||||
onAvatarTab: (Event event) => showAdaptiveBottomSheet(
|
context: context,
|
||||||
context: context,
|
builder: (c) => UserBottomSheet(
|
||||||
builder: (c) => UserBottomSheet(
|
user: event.senderFromMemoryOrFallback,
|
||||||
user: event.senderFromMemoryOrFallback,
|
outerContext: context,
|
||||||
outerContext: context,
|
onMention: () => controller.sendController.text +=
|
||||||
onMention: () => controller.sendController.text +=
|
'${event.senderFromMemoryOrFallback.mention} ',
|
||||||
'${event.senderFromMemoryOrFallback.mention} ',
|
),
|
||||||
),
|
),
|
||||||
),
|
onSelect: controller.onSelectMessage,
|
||||||
onSelect: controller.onSelectMessage,
|
scrollToEventId: (String eventId) =>
|
||||||
scrollToEventId: (String eventId) =>
|
controller.scrollToEventId(eventId),
|
||||||
controller.scrollToEventId(eventId),
|
longPressSelect: controller.selectedEvents.isNotEmpty,
|
||||||
longPressSelect: controller.selectedEvents.isNotEmpty,
|
selected: controller.selectedEvents
|
||||||
selected: controller.selectedEvents
|
.any((e) => e.eventId == event.eventId),
|
||||||
.any((e) => e.eventId == event.eventId),
|
timeline: controller.timeline!,
|
||||||
timeline: controller.timeline!,
|
displayReadMarker:
|
||||||
displayReadMarker:
|
controller.readMarkerEventId == event.eventId &&
|
||||||
controller.readMarkerEventId == event.eventId &&
|
controller.timeline?.allowNewEvent == false,
|
||||||
controller.timeline?.allowNewEvent == false,
|
nextEvent: i + 1 < events.length ? events[i + 1] : null,
|
||||||
nextEvent: i < controller.timeline!.events.length
|
),
|
||||||
? 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),
|
||||||
),
|
),
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in a new issue