mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 03:42:13 +00:00
fix: media file not opened if downloaded
This commit is contained in:
parent
a29af4c914
commit
eed5d292c6
3 changed files with 38 additions and 37 deletions
|
|
@ -203,7 +203,8 @@ class _UserListItem extends State<GroupListItemComp> {
|
||||||
await startDownloadMedia(mediaFile, true);
|
await startDownloadMedia(mediaFile, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mediaFile.downloadState! == DownloadState.ready) {
|
if (mediaFile.downloadState! == DownloadState.ready ||
|
||||||
|
mediaFile.downloadState! == DownloadState.downloaded) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await context.push(
|
await context.push(
|
||||||
Routes.chatsMediaViewer,
|
Routes.chatsMediaViewer,
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,9 @@ class _ChatMediaEntryState extends State<ChatMediaEntry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onTap() async {
|
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) {
|
widget.message.openedAt == null) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
|
|
|
||||||
|
|
@ -107,45 +107,43 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
final Mutex _messageUpdateLock = Mutex();
|
final Mutex _messageUpdateLock = Mutex();
|
||||||
|
|
||||||
Future<void> asyncLoadNextMedia(bool firstRun) async {
|
Future<void> asyncLoadNextMedia(bool firstRun) async {
|
||||||
final messages = twonlyDB.messagesDao.watchMediaNotOpened(
|
_subscription = twonlyDB.messagesDao
|
||||||
widget.group.groupId,
|
.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 {
|
if (msg.mediaId == currentMedia?.mediaFile.mediaId) {
|
||||||
await _messageUpdateLock.protect(() async {
|
// The update of the current Media in case of a download is done in loadCurrentMediaFile
|
||||||
for (final msg in messages) {
|
continue;
|
||||||
if (_alreadyOpenedMediaIds.contains(msg.mediaId)) {
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (msg.mediaId == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.mediaId == currentMedia?.mediaFile.mediaId) {
|
/// If the messages was already there just replace it and go to the next...
|
||||||
// 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...
|
final index = allMediaFiles.indexWhere(
|
||||||
|
(m) => m.messageId == msg.messageId,
|
||||||
|
);
|
||||||
|
|
||||||
final index = allMediaFiles.indexWhere(
|
if (index >= 1) {
|
||||||
(m) => m.messageId == msg.messageId,
|
allMediaFiles[index] = msg;
|
||||||
);
|
} else if (index == -1) {
|
||||||
|
// If the message does not exist, add it
|
||||||
if (index >= 1) {
|
allMediaFiles.add(msg);
|
||||||
allMediaFiles[index] = msg;
|
}
|
||||||
} else if (index == -1) {
|
}
|
||||||
// If the message does not exist, add it
|
setState(() {});
|
||||||
allMediaFiles.add(msg);
|
if (firstRun) {
|
||||||
}
|
firstRun = false;
|
||||||
}
|
await loadCurrentMediaFile();
|
||||||
setState(() {});
|
}
|
||||||
if (firstRun) {
|
});
|
||||||
firstRun = false;
|
});
|
||||||
await loadCurrentMediaFile();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> nextMediaOrExit() async {
|
Future<void> nextMediaOrExit() async {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue