fix: resolve some sentry issues

This commit is contained in:
Sorunome 2020-11-16 11:31:31 +01:00
commit 3afb4a9366
4 changed files with 36 additions and 12 deletions

View file

@ -86,16 +86,24 @@ class _ImageBubbleState extends State<ImageBubble> {
}
if (_thumbnail == null && !_requestedThumbnail && !isUnencrypted) {
_getThumbnail().then((MatrixFile thumbnail) {
setState(() => _thumbnail = thumbnail);
if (mounted) {
setState(() => _thumbnail = thumbnail);
}
}, onError: (error, stacktrace) {
setState(() => _error = error);
if (mounted) {
setState(() => _error = error);
}
});
}
if (_file == null && !widget.thumbnailOnly && !_requestedFile) {
_getFile().then((MatrixFile file) {
setState(() => _file = file);
if (mounted) {
setState(() => _file = file);
}
}, onError: (error, stacktrace) {
setState(() => _error = error);
if (mounted) {
setState(() => _error = error);
}
});
}
final display = _file ?? _thumbnail;

View file

@ -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();