@@ -689,9 +689,6 @@ class Room {
689689 return sendEvent (event, txid: txid);
690690 }
691691
692- final Map <String , MatrixFile > sendingFilePlaceholders = {};
693- final Map <String , MatrixImageFile > sendingFileThumbnails = {};
694-
695692 /// Sends a [file] to this room after uploading it. Returns the mxc uri of
696693 /// the uploaded file. If [waitUntilSent] is true, the future will wait until
697694 /// the message event has received the server. Otherwise the future will only
@@ -715,10 +712,6 @@ class Room {
715712 String ? threadLastEventId,
716713 }) async {
717714 txid ?? = client.generateUniqueTransactionId ();
718- sendingFilePlaceholders[txid] = file;
719- if (thumbnail != null ) {
720- sendingFileThumbnails[txid] = thumbnail;
721- }
722715
723716 // Create a fake Event object as a placeholder for the uploading file:
724717 final syncUpdate = SyncUpdate (
@@ -755,6 +748,22 @@ class Room {
755748 },
756749 ),
757750 );
751+ await _handleFakeSync (syncUpdate);
752+
753+ if (client.database? .supportsFileStoring == true ) {
754+ await client.database? .storeFile (
755+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
756+ file.bytes,
757+ DateTime .now ().millisecondsSinceEpoch,
758+ );
759+ if (thumbnail != null ) {
760+ await client.database? .storeFile (
761+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
762+ file.bytes,
763+ DateTime .now ().millisecondsSinceEpoch,
764+ );
765+ }
766+ }
758767
759768 MatrixFile uploadFile = file; // ignore: omit_local_variable_types
760769 // computing the thumbnail in case we can
@@ -840,12 +849,22 @@ class Room {
840849 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
841850 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
842851 await _handleFakeSync (syncUpdate);
852+
853+ if (client.database? .supportsFileStoring != true ) {
854+ final sendEvent = await getEventById (txid);
855+ await sendEvent? .cancelSend ();
856+ }
843857 rethrow ;
844858 } catch (_) {
845859 if (DateTime .now ().isAfter (timeoutDate)) {
846860 syncUpdate.rooms! .join! .values.first.timeline! .events! .first
847861 .unsigned! [messageSendingStatusKey] = EventStatus .error.intValue;
848862 await _handleFakeSync (syncUpdate);
863+
864+ if (client.database? .supportsFileStoring != true ) {
865+ final sendEvent = await getEventById (txid);
866+ await sendEvent? .cancelSend ();
867+ }
849868 rethrow ;
850869 }
851870 Logs ().v ('Send File into room failed. Try again...' );
@@ -909,8 +928,13 @@ class Room {
909928 threadRootEventId: threadRootEventId,
910929 threadLastEventId: threadLastEventId,
911930 );
912- sendingFilePlaceholders.remove (txid);
913- sendingFileThumbnails.remove (txid);
931+ await client.database? .deleteFile (
932+ Uri .parse ('com.famedly.sendingAttachment://file/$txid ' ),
933+ );
934+ await client.database? .deleteFile (
935+ Uri .parse ('com.famedly.sendingAttachment://thumbnail/$txid ' ),
936+ );
937+
914938 return eventId;
915939 }
916940
0 commit comments