File tree 2 files changed +17
-15
lines changed
app/src/main/java/com/infomaniak/mail
2 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -780,13 +780,22 @@ class NewMessageViewModel @Inject constructor(
780
780
if (recipient.isDisplayedAsExternal) appContext.trackExternalEvent(" deleteRecipient" )
781
781
}
782
782
783
- fun deleteAttachment (position : Int ) = runCatching {
784
- val attachments = attachmentsLiveData.valueOrEmpty().toMutableList()
785
- val attachment = attachments[position]
786
- attachment.getUploadLocalFile()?.delete()
787
- LocalStorageUtils .deleteAttachmentUploadDir(appContext, draftLocalUuid!! , attachment.localUuid)
788
- attachments.removeAt(position)
789
- attachmentsLiveData.value = attachments
783
+ fun deleteAttachment (position : Int ) = viewModelScope.launch(ioCoroutineContext) {
784
+ runCatching {
785
+ val attachments = attachmentsLiveData.valueOrEmpty().toMutableList()
786
+ val attachment = attachments[position]
787
+ attachment.getUploadLocalFile()?.delete()
788
+ LocalStorageUtils .deleteAttachmentUploadDir(appContext, draftLocalUuid!! , attachment.localUuid)
789
+
790
+ mailboxContentRealm().write {
791
+ draftController.updateDraft(draftLocalUuid!! , realm = this ) {
792
+ it.attachments.findSpecificAttachment(attachment)?.let (::delete)
793
+ }
794
+ }
795
+
796
+ attachments.removeAt(position)
797
+ attachmentsLiveData.postValue(attachments)
798
+ }
790
799
}
791
800
792
801
fun updateIsSendingAllowed (
Original file line number Diff line number Diff line change @@ -208,14 +208,7 @@ object AttachmentExtensions {
208
208
}
209
209
}
210
210
211
- fun List<Attachment>.findSpecificAttachment (attachment : Attachment ) = this
212
- .filter { it.localUuid == attachment.localUuid }
213
- .also {
214
- // TODO: If this Sentry never triggers, remove it and replace the
215
- // `filter { … }.also { … }.firstOrNull()` with `singleOrNull { … }`
216
- if (it.count() > 1 ) Sentry .captureMessage(" Found several Attachments with the same localUuid" )
217
- }
218
- .firstOrNull()
211
+ fun List<Attachment>.findSpecificAttachment (attachment : Attachment ) = singleOrNull { it.localUuid == attachment.localUuid }
219
212
220
213
enum class AttachmentIntentType {
221
214
OPEN_WITH ,
You can’t perform that action at this time.
0 commit comments