fix: media file not opened if downloaded

This commit is contained in:
otsmr 2026-04-24 11:29:42 +02:00
parent a29af4c914
commit eed5d292c6
3 changed files with 38 additions and 37 deletions

View file

@ -203,7 +203,8 @@ class _UserListItem extends State<GroupListItemComp> {
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,

View file

@ -88,7 +88,9 @@ class _ChatMediaEntryState extends State<ChatMediaEntry> {
}
Future<void> 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(

View file

@ -107,45 +107,43 @@ class _MediaViewerViewState extends State<MediaViewerView> {
final Mutex _messageUpdateLock = Mutex();
Future<void> 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<void> nextMediaOrExit() async {