Compare commits
No commits in common. "cce6413e2beb93dfb1f00dfb5fcc03c399ad1305" and "abe2bbdfd43327b2d67ba782eff913e1e9262dc2" have entirely different histories.
cce6413e2b
...
abe2bbdfd4
|
@ -16,8 +16,6 @@ class GalleryPlayerViewController: UIViewController {
|
||||||
|
|
||||||
var attachment: Attachment!
|
var attachment: Attachment!
|
||||||
|
|
||||||
private var isFirstAppearance = true
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
@ -46,13 +44,6 @@ class GalleryPlayerViewController: UIViewController {
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
AudioSessionHelper.enable()
|
AudioSessionHelper.enable()
|
||||||
AudioSessionHelper.setVideoPlayback()
|
AudioSessionHelper.setVideoPlayback()
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
if self.isFirstAppearance {
|
|
||||||
self.isFirstAppearance = false
|
|
||||||
self.playerVC.player?.play()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -334,31 +334,25 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
loadViewIfNeeded()
|
loadViewIfNeeded()
|
||||||
var loaded = false
|
|
||||||
await controller.restoreInitial {
|
await controller.restoreInitial {
|
||||||
let hasStatusesToRestore = await loadStatusesToRestore(position: position)
|
await loadStatusesToRestore(position: position)
|
||||||
if hasStatusesToRestore {
|
applyItemsToRestore(position: position)
|
||||||
applyItemsToRestore(position: position)
|
|
||||||
loaded = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return loaded
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
private func loadStatusesToRestore(position: TimelinePosition) async -> Bool {
|
private func loadStatusesToRestore(position: TimelinePosition) async {
|
||||||
let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil })
|
let unloaded = position.statusIDs.filter({ mastodonController.persistentContainer.status(for: $0) == nil })
|
||||||
guard !unloaded.isEmpty else {
|
guard !unloaded.isEmpty else {
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
let statuses = await withTaskGroup(of: Status?.self) { group -> [Status] in
|
let statuses = await withTaskGroup(of: Status?.self) { group -> [Status] in
|
||||||
for id in unloaded {
|
for id in unloaded {
|
||||||
group.addTask {
|
group.addTask { @MainActor in
|
||||||
do {
|
if let (status, _) = try? await self.mastodonController.run(Client.getStatus(id: id)) {
|
||||||
let (status, _) = try await self.mastodonController.run(Client.getStatus(id: id))
|
|
||||||
return status
|
return status
|
||||||
} catch {
|
} else {
|
||||||
print(error)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,20 +364,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await mastodonController.persistentContainer.addAll(statuses: statuses, in: mastodonController.persistentContainer.viewContext)
|
await mastodonController.persistentContainer.addAll(statuses: statuses, in: mastodonController.persistentContainer.viewContext)
|
||||||
|
|
||||||
// update the timeline position in case some statuses couldn't be loaded
|
|
||||||
if let center = position.centerStatusID {
|
|
||||||
let nearestLoadedStatusToCenter = position.statusIDs[position.statusIDs.firstIndex(of: center)!...].first(where: { id in
|
|
||||||
// was already loaded or was just now loaded
|
|
||||||
!unloaded.contains(id) || statuses.contains(where: { $0.id == id })
|
|
||||||
})
|
|
||||||
position.centerStatusID = nearestLoadedStatusToCenter
|
|
||||||
}
|
|
||||||
position.statusIDs = position.statusIDs.filter { id in
|
|
||||||
!unloaded.contains(id) || statuses.contains(where: { $0.id == id })
|
|
||||||
}
|
|
||||||
|
|
||||||
return !position.statusIDs.isEmpty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func applyItemsToRestore(position: TimelinePosition) {
|
private func applyItemsToRestore(position: TimelinePosition) {
|
||||||
|
|
Loading…
Reference in New Issue