Skip to content

Commit

Permalink
Handle read receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
Airyzz committed Jun 5, 2024
1 parent f7233dc commit d9d8209
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class TimelineOverlayState extends State<TimelineOverlay> {
});
}

void setAttatchedToBottom(bool value) {
void setAttachedToBottom(bool value) {
if (value != isAttatchedToBottom) {
setState(() {
isAttatchedToBottom = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _RoomTimelineWidgetState extends State<RoomTimelineWidget> {
key: timelineViewKey,
timeline: widget.timeline,
onViewScrolled: onViewScrolled,
onAttachedToBottom: onAttachedToBottom,
setReplyingEvent: widget.setReplyingEvent,
setEditingEvent: widget.setEditingEvent,
);
Expand All @@ -50,6 +51,14 @@ class _RoomTimelineWidgetState extends State<RoomTimelineWidget> {
if (offset > maxScrollExtent - loadingThreshold && loadingHistory == null) {
loadMoreHistory();
}

if (state?.attachedToBottom == true) {}
}

void onAttachedToBottom() {
if (widget.timeline.events.isNotEmpty) {
widget.timeline.markAsRead(widget.timeline.events.first);
}
}

void loadMoreHistory() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class RoomTimelineWidgetView extends StatefulWidget {
this.onViewScrolled,
this.setEditingEvent,
this.setReplyingEvent,
this.onAttachedToBottom,
super.key});
final Timeline timeline;
final Function(TimelineEvent event)? markAsRead;
final Function(TimelineEvent? event)? setReplyingEvent;
final Function(TimelineEvent? event)? setEditingEvent;
final Function()? onAttachedToBottom;

final Function({required double offset, required double maxScrollExtent})?
onViewScrolled;
Expand Down Expand Up @@ -53,6 +55,8 @@ class RoomTimelineWidgetViewState extends State<RoomTimelineWidgetView> {

late List<StreamSubscription> subscriptions;

bool wasLastScrollAttachedToBottom = false;

bool get attachedToBottom => controller.hasClients
? controller.offset - controller.positions.first.minScrollExtent < 50 ||
animatingToBottom
Expand Down Expand Up @@ -147,6 +151,7 @@ class RoomTimelineWidgetViewState extends State<RoomTimelineWidgetView> {
double extent = controller.position.minScrollExtent;
controller = ScrollController(initialScrollOffset: extent);
controller.addListener(onScroll);
widget.onAttachedToBottom?.call();
setState(() {
firstFrame = false;
});
Expand All @@ -159,14 +164,21 @@ class RoomTimelineWidgetViewState extends State<RoomTimelineWidgetView> {
maxScrollExtent: controller.position.maxScrollExtent);

var overlayState = overlayKey.currentState as TimelineOverlayState?;
overlayState?.setAttatchedToBottom(attachedToBottom);
overlayState?.setAttachedToBottom(attachedToBottom);

if (wasLastScrollAttachedToBottom == false && attachedToBottom) {
widget.onAttachedToBottom?.call();
}

wasLastScrollAttachedToBottom = attachedToBottom;
}

void animateAndSnapToBottom() {
controller.position.hold(() {});

var overlayState = overlayKey.currentState as TimelineOverlayState?;
overlayState?.setAttatchedToBottom(attachedToBottom);
overlayState?.setAttachedToBottom(attachedToBottom);
widget.onAttachedToBottom?.call();

animatingToBottom = true;

Expand Down

0 comments on commit d9d8209

Please sign in to comment.