@@ -665,9 +665,6 @@ class Room {
665665 return sendEvent (event, txid: txid);
666666 }
667667
668- final Map <String , MatrixFile > sendingFilePlaceholders = {};
669- final Map <String , MatrixImageFile > sendingFileThumbnails = {};
670-
671668 /// Sends a [file] to this room after uploading it. Returns the mxc uri of
672669 /// the uploaded file. If [waitUntilSent] is true, the future will wait until
673670 /// the message event has received the server. Otherwise the future will only
@@ -691,10 +688,6 @@ class Room {
691688 String ? threadLastEventId,
692689 }) async {
693690 txid ?? = client.generateUniqueTransactionId ();
694- sendingFilePlaceholders[txid] = file;
695- if (thumbnail != null ) {
696- sendingFileThumbnails[txid] = thumbnail;
697- }
698691
699692 // Create a fake Event object as a placeholder for the uploading file:
700693 final syncUpdate = SyncUpdate (
@@ -731,6 +724,22 @@ class Room {
731724 },
732725 ),
733726 );
727+ await _handleFakeSync (syncUpdate);
728+
729+ if (client.database? .supportsFileStoring == true ) {
730+ await client.database? .storeFile (
731+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
732+ file.bytes,
733+ DateTime .now ().millisecondsSinceEpoch,
734+ );
735+ if (thumbnail != null ) {
736+ await client.database? .storeFile (
737+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
738+ file.bytes,
739+ DateTime .now ().millisecondsSinceEpoch,
740+ );
741+ }
742+ }
734743
735744 MatrixFile uploadFile = file; // ignore: omit_local_variable_types
736745 // computing the thumbnail in case we can
@@ -816,12 +825,22 @@ class Room {
816825 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
817826 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
818827 await _handleFakeSync (syncUpdate);
828+
829+ if (client.database? .supportsFileStoring != true ) {
830+ final sendEvent = await getEventById (txid);
831+ await sendEvent? .cancelSend ();
832+ }
819833 rethrow ;
820834 } catch (_) {
821835 if (DateTime .now ().isAfter (timeoutDate)) {
822836 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
823837 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
824838 await _handleFakeSync (syncUpdate);
839+
840+ if (client.database? .supportsFileStoring != true ) {
841+ final sendEvent = await getEventById (txid);
842+ await sendEvent? .cancelSend ();
843+ }
825844 rethrow ;
826845 }
827846 Logs ().v ('Send File into room failed. Try again...' );
@@ -885,8 +904,13 @@ class Room {
885904 threadRootEventId: threadRootEventId,
886905 threadLastEventId: threadLastEventId,
887906 );
888- sendingFilePlaceholders.remove (txid);
889- sendingFileThumbnails.remove (txid);
907+ await client.database? .deleteFile (
908+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
909+ );
910+ await client.database? .deleteFile (
911+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
912+ );
913+
890914 return eventId;
891915 }
892916
0 commit comments