diff --git a/lib/src/event.dart b/lib/src/event.dart index 85170d09..4cc0866b 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -327,13 +327,20 @@ class Event extends MatrixEvent { /// Try to send this event again. Only works with events of status -1. Future sendAgain({String? txid}) async { if (!status.isError) return null; + // If this is a failed file sending event, try to fetch the file from the + // database first. + final url = getAttachmentUrl(); + if (url?.scheme == 'local') { + final file = await downloadAndDecryptAttachment(); + return await room.sendFileEvent(file, extraContent: content); + } + // we do not remove the event here. It will automatically be updated // in the `sendEvent` method to transition -1 -> 0 -> 1 -> 2 - final newEventId = await room.sendEvent( + return await room.sendEvent( content, txid: txid ?? unsigned?['transaction_id'] ?? eventId, ); - return newEventId; } /// Whether the client is allowed to redact this event. diff --git a/lib/src/room.dart b/lib/src/room.dart index c6a1d1e1..edbf1729 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -695,7 +695,7 @@ class Room { /// Set [shrinkImageMaxDimension] to for example `1600` if you want to shrink /// your image before sending. This is ignored if the File is not a /// [MatrixImageFile]. - Future sendFileEvent( + Future sendFileEvent( MatrixFile file, { String? txid, Event? inReplyTo, @@ -755,6 +755,7 @@ class Room { name: file.name, maxDimension: shrinkImageMaxDimension, customImageResizer: client.customImageResizer, + compute: client.runInBackground, ); } } @@ -859,14 +860,14 @@ class Room { }, if (extraContent != null) ...extraContent, }; - await sendEvent( + final eventId = await sendEvent( content, txid: txid, inReplyTo: inReplyTo, editEventId: editEventId, ); sendingFilePlaceholders.remove(txid); - return uploadResp; + return eventId; } Future _sendContent( diff --git a/test/room_test.dart b/test/room_test.dart index 56894bfb..b60c16e7 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -745,7 +745,7 @@ void main() { test('sendFileEvent', () async { final testFile = MatrixFile(bytes: Uint8List(0), name: 'file.jpeg'); final dynamic resp = await room.sendFileEvent(testFile, txid: 'testtxid'); - expect(resp.toString(), 'mxc://example.com/AQwafuaFswefuhsfAFAgsw'); + expect(resp.toString(), '\$event10'); }); test('pushRuleState', () async {