|
|
|
@ -121,6 +121,9 @@ class _ChatState extends State<_Chat> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _updateScrollController() {
|
|
|
|
|
if (!mounted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_scrollController.position.pixels ==
|
|
|
|
|
_scrollController.position.maxScrollExtent &&
|
|
|
|
|
timeline.events.isNotEmpty &&
|
|
|
|
@ -176,17 +179,27 @@ class _ChatState extends State<_Chat> {
|
|
|
|
|
if (timeline == null) {
|
|
|
|
|
timeline = await room.getTimeline(onUpdate: updateView);
|
|
|
|
|
if (timeline.events.isNotEmpty) {
|
|
|
|
|
unawaited(room.sendReadReceipt(timeline.events.first.eventId));
|
|
|
|
|
unawaited(room
|
|
|
|
|
.sendReadReceipt(timeline.events.first.eventId)
|
|
|
|
|
.catchError((err) {
|
|
|
|
|
if (err is MatrixException && err.errcode == 'M_FORBIDDEN') {
|
|
|
|
|
// ignore if the user is not in the room (still joining)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
throw err;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when the scroll controller is attached we want to scroll to an event id, if specified
|
|
|
|
|
// and update the scroll controller...which will trigger a request history, if the
|
|
|
|
|
// "load more" button is visible on the screen
|
|
|
|
|
SchedulerBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
|
if (widget.scrollToEventId != null) {
|
|
|
|
|
_scrollToEventId(widget.scrollToEventId, context: context);
|
|
|
|
|
if (mounted) {
|
|
|
|
|
if (widget.scrollToEventId != null) {
|
|
|
|
|
_scrollToEventId(widget.scrollToEventId, context: context);
|
|
|
|
|
}
|
|
|
|
|
_updateScrollController();
|
|
|
|
|
}
|
|
|
|
|
_updateScrollController();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
updateView();
|
|
|
|
@ -406,6 +419,9 @@ class _ChatState extends State<_Chat> {
|
|
|
|
|
await task;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!mounted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await _scrollController.scrollToIndex(eventIndex,
|
|
|
|
|
preferPosition: AutoScrollPosition.middle);
|
|
|
|
|
_updateScrollController();
|
|
|
|
|