|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
import 'package:scroll_to_index/scroll_to_index.dart';
|
|
|
|
|
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
|
|
|
|
import 'package:fluffychat/pages/chat/chat.dart';
|
|
|
|
@ -12,7 +12,6 @@ import 'package:fluffychat/pages/user_bottom_sheet/user_bottom_sheet.dart';
|
|
|
|
|
import 'package:fluffychat/utils/account_config.dart';
|
|
|
|
|
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
|
|
|
|
import 'package:fluffychat/utils/matrix_sdk_extensions/filtered_timeline_extension.dart';
|
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
|
|
|
|
|
|
class ChatEventList extends StatelessWidget {
|
|
|
|
|
final ChatController controller;
|
|
|
|
@ -41,119 +40,108 @@ class ChatEventList extends StatelessWidget {
|
|
|
|
|
controller.room.client.applicationAccountConfig.wallpaperUrl != null;
|
|
|
|
|
|
|
|
|
|
return SelectionArea(
|
|
|
|
|
child: ListView.custom(
|
|
|
|
|
child: ScrollablePositionedList.builder(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
top: 16,
|
|
|
|
|
bottom: 8,
|
|
|
|
|
left: horizontalPadding,
|
|
|
|
|
right: horizontalPadding,
|
|
|
|
|
),
|
|
|
|
|
itemCount: events.length + 2,
|
|
|
|
|
reverse: true,
|
|
|
|
|
controller: controller.scrollController,
|
|
|
|
|
keyboardDismissBehavior: PlatformInfos.isIOS
|
|
|
|
|
? ScrollViewKeyboardDismissBehavior.onDrag
|
|
|
|
|
: ScrollViewKeyboardDismissBehavior.manual,
|
|
|
|
|
childrenDelegate: SliverChildBuilderDelegate(
|
|
|
|
|
(BuildContext context, int i) {
|
|
|
|
|
// Footer to display typing indicator and read receipts:
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
if (controller.timeline!.isRequestingFuture) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (controller.timeline!.canRequestFuture) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: IconButton(
|
|
|
|
|
onPressed: controller.requestFuture,
|
|
|
|
|
icon: const Icon(Icons.refresh_outlined),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
SeenByRow(controller),
|
|
|
|
|
TypingIndicators(controller),
|
|
|
|
|
],
|
|
|
|
|
itemScrollController: controller.itemScrollController,
|
|
|
|
|
scrollOffsetController: controller.scrollOffsetController,
|
|
|
|
|
itemPositionsListener: controller.itemPositionsListener,
|
|
|
|
|
scrollOffsetListener: controller.scrollOffsetListener,
|
|
|
|
|
itemBuilder: (BuildContext context, int i) {
|
|
|
|
|
// Footer to display typing indicator and read receipts:
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
if (controller.timeline!.isRequestingFuture) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (controller.timeline!.canRequestFuture) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: IconButton(
|
|
|
|
|
onPressed: controller.requestFuture,
|
|
|
|
|
icon: const Icon(Icons.refresh_outlined),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
SeenByRow(controller),
|
|
|
|
|
TypingIndicators(controller),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request history button or progress indicator:
|
|
|
|
|
if (i == events.length + 1) {
|
|
|
|
|
if (controller.timeline!.isRequestingHistory) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (controller.timeline!.canRequestHistory) {
|
|
|
|
|
return Builder(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
WidgetsBinding.instance
|
|
|
|
|
.addPostFrameCallback(controller.requestHistory);
|
|
|
|
|
return Center(
|
|
|
|
|
child: IconButton(
|
|
|
|
|
onPressed: controller.requestHistory,
|
|
|
|
|
icon: const Icon(Icons.refresh_outlined),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
// Request history button or progress indicator:
|
|
|
|
|
if (i == events.length + 1) {
|
|
|
|
|
if (controller.timeline!.isRequestingHistory) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(strokeWidth: 2),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (controller.timeline!.canRequestHistory) {
|
|
|
|
|
return Builder(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
WidgetsBinding.instance
|
|
|
|
|
.addPostFrameCallback(controller.requestHistory);
|
|
|
|
|
return Center(
|
|
|
|
|
child: IconButton(
|
|
|
|
|
onPressed: controller.requestHistory,
|
|
|
|
|
icon: const Icon(Icons.refresh_outlined),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
}
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
|
|
// The message at this index:
|
|
|
|
|
final event = events[i];
|
|
|
|
|
final animateIn = animateInEventIndex != null &&
|
|
|
|
|
controller.timeline!.events.length > animateInEventIndex &&
|
|
|
|
|
event == controller.timeline!.events[animateInEventIndex];
|
|
|
|
|
// The message at this index:
|
|
|
|
|
final event = events[i];
|
|
|
|
|
final animateIn = animateInEventIndex != null &&
|
|
|
|
|
controller.timeline!.events.length > animateInEventIndex &&
|
|
|
|
|
event == controller.timeline!.events[animateInEventIndex];
|
|
|
|
|
|
|
|
|
|
return AutoScrollTag(
|
|
|
|
|
key: ValueKey(event.eventId),
|
|
|
|
|
index: i,
|
|
|
|
|
controller: controller.scrollController,
|
|
|
|
|
child: Message(
|
|
|
|
|
event,
|
|
|
|
|
animateIn: animateIn,
|
|
|
|
|
resetAnimateIn: () {
|
|
|
|
|
controller.animateInEventIndex = null;
|
|
|
|
|
},
|
|
|
|
|
onSwipe: () => controller.replyAction(replyTo: event),
|
|
|
|
|
onInfoTab: controller.showEventInfo,
|
|
|
|
|
onAvatarTab: (Event event) => showAdaptiveBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (c) => UserBottomSheet(
|
|
|
|
|
user: event.senderFromMemoryOrFallback,
|
|
|
|
|
outerContext: context,
|
|
|
|
|
onMention: () => controller.sendController.text +=
|
|
|
|
|
'${event.senderFromMemoryOrFallback.mention} ',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
highlightMarker:
|
|
|
|
|
controller.scrollToEventIdMarker == event.eventId,
|
|
|
|
|
onSelect: controller.onSelectMessage,
|
|
|
|
|
scrollToEventId: (String eventId) =>
|
|
|
|
|
controller.scrollToEventId(eventId),
|
|
|
|
|
longPressSelect: controller.selectedEvents.isNotEmpty,
|
|
|
|
|
selected: controller.selectedEvents
|
|
|
|
|
.any((e) => e.eventId == event.eventId),
|
|
|
|
|
timeline: controller.timeline!,
|
|
|
|
|
displayReadMarker:
|
|
|
|
|
controller.readMarkerEventId == event.eventId &&
|
|
|
|
|
controller.timeline?.allowNewEvent == false,
|
|
|
|
|
nextEvent: i + 1 < events.length ? events[i + 1] : null,
|
|
|
|
|
previousEvent: i > 0 ? events[i - 1] : null,
|
|
|
|
|
avatarPresenceBackgroundColor:
|
|
|
|
|
hasWallpaper ? Colors.transparent : null,
|
|
|
|
|
return Message(
|
|
|
|
|
event,
|
|
|
|
|
animateIn: animateIn,
|
|
|
|
|
resetAnimateIn: () {
|
|
|
|
|
controller.animateInEventIndex = null;
|
|
|
|
|
},
|
|
|
|
|
onSwipe: () => controller.replyAction(replyTo: event),
|
|
|
|
|
onInfoTab: controller.showEventInfo,
|
|
|
|
|
onAvatarTab: (Event event) => showAdaptiveBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (c) => UserBottomSheet(
|
|
|
|
|
user: event.senderFromMemoryOrFallback,
|
|
|
|
|
outerContext: context,
|
|
|
|
|
onMention: () => controller.sendController.text +=
|
|
|
|
|
'${event.senderFromMemoryOrFallback.mention} ',
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
childCount: events.length + 2,
|
|
|
|
|
findChildIndexCallback: (key) =>
|
|
|
|
|
controller.findChildIndexCallback(key, thisEventsKeyMap),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
highlightMarker: controller.scrollToEventIdMarker == event.eventId,
|
|
|
|
|
onSelect: controller.onSelectMessage,
|
|
|
|
|
scrollToEventId: (String eventId) =>
|
|
|
|
|
controller.scrollToEventId(eventId),
|
|
|
|
|
longPressSelect: controller.selectedEvents.isNotEmpty,
|
|
|
|
|
selected: controller.selectedEvents
|
|
|
|
|
.any((e) => e.eventId == event.eventId),
|
|
|
|
|
timeline: controller.timeline!,
|
|
|
|
|
displayReadMarker: controller.readMarkerEventId == event.eventId &&
|
|
|
|
|
controller.timeline?.allowNewEvent == false,
|
|
|
|
|
nextEvent: i + 1 < events.length ? events[i + 1] : null,
|
|
|
|
|
previousEvent: i > 0 ? events[i - 1] : null,
|
|
|
|
|
avatarPresenceBackgroundColor:
|
|
|
|
|
hasWallpaper ? Colors.transparent : null,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|