-
Notifications
You must be signed in to change notification settings - Fork 5
fix attachments not loading in dev environment #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm having some issues with my simulator and can't reliably reproduce this. But my understanding is that:
To me, it sounds like step 2 is the issue. I think the |
I might either be repeating or misunderstanding Simon's recommendation. Here are my thoughts. I haven't tested this with this specific issue yet, but I'd propose a third solution where the private func verifyAttachments(context: AttachmentContext) async throws {
let attachments = try await context.getAttachments()
var updates: [Attachment] = []
for attachment in attachments {
guard let localUri = attachment.localUri else {
continue
}
let exists = try await localStorage.fileExists(filePath: localUri)
if exists {
// The file exists, this is correct
continue
}
if attachment.state == AttachmentState.queuedUpload {
// The file must have been removed from the local storage before upload was completed
updates.append(attachment.with(
state: .archived,
localUri: .some(nil) // Clears the value
))
} else if attachment.state == AttachmentState.synced {
// The file was downloaded, but removed - trigger redownload
updates.append(attachment.with(
state: .queuedDownload
))
}
}
try await context.saveAttachments(attachments: updates)
} |
Tested both approaches: Added the following if existingQueueItem.state == AttachmentState.synced && existingQueueItem.localUri == nil {
attachmentUpdates.append(
existingQueueItem.with(state: AttachmentState.queuedDownload)
)
} Works like a charm. Also tested the guard let localUri = attachment.localUri else {
if attachment.state == AttachmentState.synced {
updates.append(attachment.with(state: .queuedDownload))
}
continue
} or even private func verifyAttachments(context: AttachmentContext) async throws {
let attachments = try await context.getAttachments()
var updates: [Attachment] = []
for attachment in attachments {
let exists: Bool
if let localUri = attachment.localUri {
exists = try await localStorage.fileExists(filePath: localUri)
} else {
exists = false
}
if exists {
// The file exists, this is correct
continue
}
if attachment.state == AttachmentState.queuedUpload {
// The file must have been removed from the local storage before upload was completed
updates.append(attachment.with(
state: .archived,
localUri: .some(nil) // Clears the value
))
} else if attachment.state == AttachmentState.synced {
// The file was downloaded, but removed - trigger redownload
updates.append(attachment.with(
state: .queuedDownload
))
}
}
try await context.saveAttachments(attachments: updates)
} Not too sure which approach you guys would recommend? |
Is this from a clean state? I'm not sure how assets manage to be in |
Cleared sqlite and tested it again and you are right Simon, there were some lingering malformed attachments throwing it off. After testing it with Steven's fix the attachment always goes through the correct flow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me - thank you Joshua!
Just a note. A changelog entry for this fix would still be required. |
Problem
Attachments files fail to load on IOS builds. This can be seen by following these steps in the Demo app:
Refer to this discussion for more details:
https://discord.com/channels/1138230179878154300/1387703779662631004