in facebook-core/src/main/java/com/facebook/internal/NativeAppCallAttachmentStore.kt [91:128]
fun addAttachments(attachments: Collection<Attachment>?) {
if (attachments == null || attachments.isEmpty()) {
return
}
// If this is the first time we've been instantiated, clean up any existing attachments.
if (attachmentsDirectory == null) {
cleanupAllAttachments()
}
ensureAttachmentsDirectoryExists()
val filesToCleanup: MutableList<File?> = ArrayList()
try {
for (attachment in attachments) {
if (!attachment.shouldCreateFile) {
continue
}
val file = getAttachmentFile(attachment.callId, attachment.attachmentName, true)
if (file != null) {
filesToCleanup.add(file)
if (attachment.bitmap != null) {
processAttachmentBitmap(attachment.bitmap, file)
} else if (attachment.originalUri != null) {
processAttachmentFile(attachment.originalUri, attachment.isContentUri, file)
}
}
}
} catch (exception: IOException) {
Log.e(TAG, "Got unexpected exception:$exception")
for (file in filesToCleanup) {
try {
file?.delete()
} catch (e: Exception) {
// Always try to delete other files.
}
}
throw FacebookException(exception)
}
}