diff --git a/lib/src/visual/views/chats/chat_list_components/group_list_item.comp.dart b/lib/src/visual/views/chats/chat_list_components/group_list_item.comp.dart index 225a3195..2b77f699 100644 --- a/lib/src/visual/views/chats/chat_list_components/group_list_item.comp.dart +++ b/lib/src/visual/views/chats/chat_list_components/group_list_item.comp.dart @@ -203,7 +203,8 @@ class _UserListItem extends State { await startDownloadMedia(mediaFile, true); return; } - if (mediaFile.downloadState! == DownloadState.ready) { + if (mediaFile.downloadState! == DownloadState.ready || + mediaFile.downloadState! == DownloadState.downloaded) { if (!mounted) return; await context.push( Routes.chatsMediaViewer, diff --git a/lib/src/visual/views/chats/chat_messages_components/entries/chat_media_entry.dart b/lib/src/visual/views/chats/chat_messages_components/entries/chat_media_entry.dart index 5e096740..77d752ba 100644 --- a/lib/src/visual/views/chats/chat_messages_components/entries/chat_media_entry.dart +++ b/lib/src/visual/views/chats/chat_messages_components/entries/chat_media_entry.dart @@ -88,7 +88,9 @@ class _ChatMediaEntryState extends State { } Future onTap() async { - if (widget.mediaService.mediaFile.downloadState == DownloadState.ready && + if ((widget.mediaService.mediaFile.downloadState == DownloadState.ready || + widget.mediaService.mediaFile.downloadState == + DownloadState.downloaded) && widget.message.openedAt == null) { if (!mounted) return; await Navigator.push( diff --git a/lib/src/visual/views/chats/media_viewer.view.dart b/lib/src/visual/views/chats/media_viewer.view.dart index 4f604830..46ef723d 100644 --- a/lib/src/visual/views/chats/media_viewer.view.dart +++ b/lib/src/visual/views/chats/media_viewer.view.dart @@ -107,45 +107,43 @@ class _MediaViewerViewState extends State { final Mutex _messageUpdateLock = Mutex(); Future asyncLoadNextMedia(bool firstRun) async { - final messages = twonlyDB.messagesDao.watchMediaNotOpened( - widget.group.groupId, - ); + _subscription = twonlyDB.messagesDao + .watchMediaNotOpened(widget.group.groupId) + .listen((messages) async { + await _messageUpdateLock.protect(() async { + for (final msg in messages) { + if (_alreadyOpenedMediaIds.contains(msg.mediaId)) { + continue; + } + if (msg.mediaId == null) { + continue; + } - _subscription = messages.listen((messages) async { - await _messageUpdateLock.protect(() async { - for (final msg in messages) { - if (_alreadyOpenedMediaIds.contains(msg.mediaId)) { - continue; - } - if (msg.mediaId == null) { - continue; - } + if (msg.mediaId == currentMedia?.mediaFile.mediaId) { + // The update of the current Media in case of a download is done in loadCurrentMediaFile + continue; + } - if (msg.mediaId == currentMedia?.mediaFile.mediaId) { - // The update of the current Media in case of a download is done in loadCurrentMediaFile - continue; - } + /// If the messages was already there just replace it and go to the next... - /// If the messages was already there just replace it and go to the next... + final index = allMediaFiles.indexWhere( + (m) => m.messageId == msg.messageId, + ); - final index = allMediaFiles.indexWhere( - (m) => m.messageId == msg.messageId, - ); - - if (index >= 1) { - allMediaFiles[index] = msg; - } else if (index == -1) { - // If the message does not exist, add it - allMediaFiles.add(msg); - } - } - setState(() {}); - if (firstRun) { - firstRun = false; - await loadCurrentMediaFile(); - } - }); - }); + if (index >= 1) { + allMediaFiles[index] = msg; + } else if (index == -1) { + // If the message does not exist, add it + allMediaFiles.add(msg); + } + } + setState(() {}); + if (firstRun) { + firstRun = false; + await loadCurrentMediaFile(); + } + }); + }); } Future nextMediaOrExit() async {