@@ -687,9 +687,6 @@ class Room {
687687 return sendEvent (event, txid: txid);
688688 }
689689
690- final Map <String , MatrixFile > sendingFilePlaceholders = {};
691- final Map <String , MatrixImageFile > sendingFileThumbnails = {};
692-
693690 /// Sends a [file] to this room after uploading it. Returns the mxc uri of
694691 /// the uploaded file. If [waitUntilSent] is true, the future will wait until
695692 /// the message event has received the server. Otherwise the future will only
@@ -713,10 +710,6 @@ class Room {
713710 String ? threadLastEventId,
714711 }) async {
715712 txid ?? = client.generateUniqueTransactionId ();
716- sendingFilePlaceholders[txid] = file;
717- if (thumbnail != null ) {
718- sendingFileThumbnails[txid] = thumbnail;
719- }
720713
721714 // Create a fake Event object as a placeholder for the uploading file:
722715 final syncUpdate = SyncUpdate (
@@ -753,6 +746,22 @@ class Room {
753746 },
754747 ),
755748 );
749+ await _handleFakeSync (syncUpdate);
750+
751+ if (client.database? .supportsFileStoring == true ) {
752+ await client.database? .storeFile (
753+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
754+ file.bytes,
755+ DateTime .now ().millisecondsSinceEpoch,
756+ );
757+ if (thumbnail != null ) {
758+ await client.database? .storeFile (
759+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
760+ file.bytes,
761+ DateTime .now ().millisecondsSinceEpoch,
762+ );
763+ }
764+ }
756765
757766 MatrixFile uploadFile = file; // ignore: omit_local_variable_types
758767 // computing the thumbnail in case we can
@@ -838,12 +847,22 @@ class Room {
838847 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
839848 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
840849 await _handleFakeSync (syncUpdate);
850+
851+ if (client.database? .supportsFileStoring != true ) {
852+ final sendEvent = await getEventById (txid);
853+ await sendEvent? .cancelSend ();
854+ }
841855 rethrow ;
842856 } catch (_) {
843857 if (DateTime .now ().isAfter (timeoutDate)) {
844858 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
845859 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
846860 await _handleFakeSync (syncUpdate);
861+
862+ if (client.database? .supportsFileStoring != true ) {
863+ final sendEvent = await getEventById (txid);
864+ await sendEvent? .cancelSend ();
865+ }
847866 rethrow ;
848867 }
849868 Logs ().v ('Send File into room failed. Try again...' );
@@ -907,8 +926,13 @@ class Room {
907926 threadRootEventId: threadRootEventId,
908927 threadLastEventId: threadLastEventId,
909928 );
910- sendingFilePlaceholders.remove (txid);
911- sendingFileThumbnails.remove (txid);
929+ await client.database? .deleteFile (
930+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
931+ );
932+ await client.database? .deleteFile (
933+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
934+ );
935+
912936 return eventId;
913937 }
914938
0 commit comments