From 2c3693e4eb8b8af356be6df1a6b3672847ef978c Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 16 Nov 2020 11:31:31 +0100 Subject: [PATCH] fix: resolve some sentry issues --- lib/components/image_bubble.dart | 16 ++++++++++++---- lib/views/chat.dart | 24 ++++++++++++++++++++---- pubspec.lock | 6 +++--- pubspec.yaml | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/components/image_bubble.dart b/lib/components/image_bubble.dart index 8b23f779..c3925619 100644 --- a/lib/components/image_bubble.dart +++ b/lib/components/image_bubble.dart @@ -86,16 +86,24 @@ class _ImageBubbleState extends State { } 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; diff --git a/lib/views/chat.dart b/lib/views/chat.dart index a77049ea..0109e833 100644 --- a/lib/views/chat.dart +++ b/lib/views/chat.dart @@ -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(); diff --git a/pubspec.lock b/pubspec.lock index 63d350fb..95a75c32 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -215,8 +215,8 @@ packages: dependency: "direct main" description: path: "." - ref: "66572bd03209c1c6488cde53a0c72c11faef341d" - resolved-ref: "66572bd03209c1c6488cde53a0c72c11faef341d" + ref: c8d5bbfd144fd4ed36ebb12abc83e7676b9e45b0 + resolved-ref: c8d5bbfd144fd4ed36ebb12abc83e7676b9e45b0 url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" @@ -1151,5 +1151,5 @@ packages: source: hosted version: "0.1.2" sdks: - dart: ">=2.10.2 <2.11.0" + dart: ">=2.10.2 <=2.11.0-161.0.dev" flutter: ">=1.22.2 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 577c3873..47dd9969 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: 66572bd03209c1c6488cde53a0c72c11faef341d + ref: c8d5bbfd144fd4ed36ebb12abc83e7676b9e45b0 localstorage: ^3.0.3+6 file_picker_cross: 4.2.2