Getting user avatar from cloud
shredlocker opened this issue · 4 comments
What is the recordTypeId for the users record? When I try a record type of "Users", I get an error saying I can't query system types... I just want the avatar for specific users.
Looks like you can't query the "Users" type, you can only find them by ID. This is OK - we should be to find the ID using the "createdBy" field of Performance records.
I added a simple-ish solution as follows:
func getAvatar(forPerformance performance: ChirpPerformance) {
guard let creatorID = performance.creatorID else {
print("WJTVC: No creator for: \(performance.title())")
return
}
let publicDB = container.publicCloudDatabase
publicDB.fetch(withRecordID: creatorID) { [unowned self] (record: CKRecord?, error: Error?) in
if let e = error {
print("WJTVC: Avatar Error: \(e)")
}
if let rec = record {
print("WJTVC: Avatar Record Found.")
DispatchQueue.main.async {
self.localProfileStore[creatorID] = PerformerProfile(fromRecord: rec)
self.modelUpdated()
}
}
}
}
Ok, good.
I got it somewhat working. I think we need another singleton storage class for PerformerProfiles, I've started this a bit in the WorldJamsTableViewController. Basically it's a dictionary from CKRecordIDs to PerformerProfiles, so that you can ask for a profile, and if it's not found, it is downloaded automatically.
Next step from here - add some more interesting avatars!
closed by #67