Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Packages/ConfCore/ConfCore/AppleAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public final class AppleAPIClient: Logging, Signposting {
}

currentConfigRequest?.cancel()
currentConfigRequest = configResource.loadIfNeeded()
currentConfigRequest = configResource.load()
}

}
Expand Down
22 changes: 13 additions & 9 deletions Packages/ConfCore/ConfCore/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,23 @@ public final class Storage: Logging, Signposting {
return
}

performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { backgroundRealm in
performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { [weak self] backgroundRealm in
guard let self else { return }

// We currently only care about whatever the latest event hero is.
let existingHeroData = backgroundRealm.objects(EventHero.self)
backgroundRealm.delete(existingHeroData)
}
if !existingHeroData.isEmpty {
self.log.info("Removing existing event hero")
backgroundRealm.delete(existingHeroData)
}

guard let hero = response.eventHero else {
log.debug("Config response didn't contain an event hero")
return
}
if let hero = response.eventHero {
self.log.info("Storing event hero \(hero.identifier, privacy: .public)")

performSerializedBackgroundWrite(disableAutorefresh: false, completionBlock: completion) { backgroundRealm in
backgroundRealm.add(hero, update: .modified)
backgroundRealm.add(hero, update: .modified)
} else {
self.log.info("Config response had no event hero")
}
}
}

Expand Down
29 changes: 25 additions & 4 deletions WWDC/LiveObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,43 @@ private final class CloudKitLiveObserver: Logging {
private func store(_ records: [CKRecord]) {
log.debug("Storing live records")

storage.backgroundUpdate { realm in
storage.backgroundUpdate { [weak self] realm in
guard let self else { return }

records.forEach { record in
guard let asset = SessionAsset(record: record) else { return }
guard let session = realm.object(ofType: Session.self, forPrimaryKey: asset.sessionId) else { return }
guard let instance = session.instances.first else { return }

/// Allow record to override state from the backend API only if the record's `overrideState` is set to `1`,
/// otherwise existing local data from Apple's backend always wins.
let canOverrideExistingState = record["overrideState"] as? Int == 1

if let existingAsset = realm.object(ofType: SessionAsset.self, forPrimaryKey: asset.identifier) {
// update existing asset hls URL if appropriate
existingAsset.remoteURL = asset.remoteURL
/// Update existing asset hls URL if appropriate
if canOverrideExistingState {
existingAsset.remoteURL = asset.remoteURL
} else {
self.log.info("Ignoring remoteURL override from record for \(asset.sessionId, privacy: .public) because overrideState is not 1")
}
} else {
// add new live asset to corresponding session
session.assets.append(asset)
}

instance.isForcedLive = (record["isLive"] as? Int == 1)
instance.isCurrentlyLive = instance.isForcedLive

/// Allow record to override live state from not live to live, but not the other way around.
if !instance.isCurrentlyLive {
instance.isCurrentlyLive = instance.isForcedLive
} else {
/// Allow record to override live state however it wants if record's `overrideState` is `1`.
if canOverrideExistingState {
instance.isCurrentlyLive = instance.isForcedLive
} else {
self.log.info("Ignoring live state override from record for \(asset.sessionId, privacy: .public) because overrideState is not 1")
}
}
}
}
}
Expand Down