This commit is contained in:
otsmr 2025-03-30 20:56:42 +02:00
parent 511358d047
commit f485366719
3 changed files with 24 additions and 7 deletions

View file

@ -149,7 +149,7 @@ class _MessageSendStateIconState extends State<MessageSendStateIcon> {
if (message.errorWhileSending) {
icon =
FaIcon(FontAwesomeIcons.circleExclamation, size: 12, color: color);
text = "Error while sending";
text = "Unknown error.";
}
icons.add(icon);

View file

@ -15,7 +15,10 @@ class MessagesDao extends DatabaseAccessor<TwonlyDatabase>
Stream<List<Message>> watchMessageNotOpened(int contactId) {
return (select(messages)
..where((t) => t.openedAt.isNull() & t.contactId.equals(contactId))
..where((t) =>
t.openedAt.isNull() &
t.contactId.equals(contactId) &
t.errorWhileSending.equals(false))
..orderBy([(t) => OrderingTerm.desc(t.sendAt)]))
.watch();
}
@ -55,8 +58,12 @@ class MessagesDao extends DatabaseAccessor<TwonlyDatabase>
Future removeOldMessages() {
return (update(messages)
..where((t) =>
t.openedAt.isSmallerThanValue(
DateTime.now().subtract(Duration(days: 1))) &
(t.openedAt.isSmallerThanValue(
DateTime.now().subtract(Duration(days: 1)),
) |
(t.sendAt.isSmallerThanValue(
DateTime.now().subtract(Duration(days: 1))) &
t.errorWhileSending.equals(true))) &
t.kind.equals(MessageKind.textMessage.name)))
.write(MessagesCompanion(contentJson: Value(null)));
}

View file

@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'package:drift/drift.dart' hide Column;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:lottie/lottie.dart';
import 'package:no_screenshot/no_screenshot.dart';
@ -91,7 +91,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
Future loadCurrentMediaFile({bool showTwonly = false}) async {
await _noScreenshot.screenshotOff();
if (!context.mounted || allMediaFiles.isEmpty) return;
if (!context.mounted || allMediaFiles.isEmpty) return nextMediaOrExit();
final current = allMediaFiles.first;
final MediaMessageContent content =
@ -137,14 +137,24 @@ class _MediaViewerViewState extends State<MediaViewerView> {
do {
if (isDownloading) {
await Future.delayed(Duration(milliseconds: 10));
if (!apiProvider.isConnected) break;
}
if (content.downloadToken == null) break;
imageBytes = await getDownloadedMedia(current, content.downloadToken!);
} while (isDownloading && imageBytes == null);
isDownloading = false;
if (imageBytes == null) {
if (current.downloadState == DownloadState.downloaded) {
// When the message should be downloaded but imageBytes are null then a error happened
await twonlyDatabase.messagesDao.updateMessageByMessageId(
current.messageId,
MessagesCompanion(
errorWhileSending: Value(true),
),
);
}
nextMediaOrExit();
return;
}