Add retry for failed media packets

This commit is contained in:
Janez T
2026-03-02 08:04:16 +01:00
parent 790c205541
commit e13143aead
5 changed files with 41 additions and 29 deletions

View File

@@ -457,6 +457,7 @@ class _MessagesTabState extends State<MessagesTab> {
grayscale: grayscale,
);
if (result == null) {
if (!mounted) return;
ToastLogger.error(context, 'Image compression failed');
return;
}
@@ -487,6 +488,7 @@ class _MessagesTabState extends State<MessagesTab> {
);
if (fragments.isEmpty) {
if (!mounted) return;
ToastLogger.error(context, 'Image fragmentation failed');
return;
}
@@ -494,6 +496,7 @@ class _MessagesTabState extends State<MessagesTab> {
// Build envelope.
final deviceKey = connectionProvider.deviceInfo.publicKey;
if (deviceKey == null || deviceKey.length < 6) {
if (!mounted) return;
ToastLogger.error(context, 'Device key unavailable');
return;
}
@@ -513,6 +516,8 @@ class _MessagesTabState extends State<MessagesTab> {
timestampSec: DateTime.now().millisecondsSinceEpoch ~/ 1000,
);
if (!mounted) return;
// Cache for deferred serving.
final imageProvider = context.read<ip.ImageProvider>();
imageProvider.cacheOutgoingSession(sessionId, fragments, envelope);
@@ -555,6 +560,7 @@ class _MessagesTabState extends State<MessagesTab> {
);
if (!sent) {
messagesProvider.markMessageFailed(msgId);
if (!mounted) return;
ToastLogger.error(context, 'Failed to announce image');
}
}
@@ -566,6 +572,7 @@ class _MessagesTabState extends State<MessagesTab> {
);
} catch (e, st) {
debugPrint('❌ [Image] _pickAndSendImage: $e\n$st');
if (!mounted) return;
ToastLogger.error(context, 'Image send failed');
} finally {
if (mounted) setState(() => _isSendingImage = false);

View File

@@ -1206,24 +1206,26 @@ class _SettingsScreenState extends State<SettingsScreen> {
builder: (context) => AlertDialog(
title: const Text('Max image size'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: ImagePreferences.supportedSizes
.map(
(size) => RadioListTile<int>(
value: size,
groupValue: _imageMaxSize,
title: Text('${size}×$size px'),
subtitle: size == ImagePreferences.defaultMaxSize
? const Text('Default')
: null,
onChanged: (value) {
if (value != null) _saveImageMaxSize(value);
Navigator.pop(context);
},
),
)
.toList(),
child: RadioGroup<int>(
groupValue: _imageMaxSize,
onChanged: (value) {
if (value != null) _saveImageMaxSize(value);
Navigator.pop(context);
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: ImagePreferences.supportedSizes
.map(
(size) => RadioListTile<int>(
value: size,
title: Text('$size×$size px'),
subtitle: size == ImagePreferences.defaultMaxSize
? const Text('Default')
: null,
),
)
.toList(),
),
),
),
actions: [