Skip to content

Commit

Permalink
MyPlanetModel savePublic is now async
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Aug 15, 2023
1 parent 663023a commit 303453f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Planet/Entities/DraftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class DraftModel: Identifiable, Equatable, Hashable, Codable, ObservableObject {
try planet.save()

Task {
try planet.savePublic()
try await planet.savePublic()
try await planet.publish()
}

Expand Down
6 changes: 3 additions & 3 deletions Planet/Entities/MyPlanetModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl

Task {
do {
try planet.savePublic()
try await planet.savePublic()
}
catch {
Self.logger.error("Error creating planet public info \(planet.id): \(error)")
Expand Down Expand Up @@ -1264,7 +1264,7 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl
}
}

func savePublic() throws {
func savePublic() async throws {
guard let template = template else {
throw PlanetError.MissingTemplateError
}
Expand Down Expand Up @@ -1687,7 +1687,7 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl
debugPrint("failed to save ops to file: \(error)")
}
}
try self.savePublic()
try await self.savePublic()
NotificationCenter.default.post(name: .loadArticle, object: nil)
Task { @MainActor in
NotificationCenter.default.post(name: .publishMyPlanet, object: self)
Expand Down
4 changes: 2 additions & 2 deletions Planet/Entities/PlanetStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ enum PlanetDetailViewType: Hashable, Equatable {
try toPlanet.save()

debugPrint("target planet save public")
try toPlanet.savePublic()
try await toPlanet.savePublic()

debugPrint("update from planet update date")
fromPlanet.updated = Date()
Expand All @@ -470,7 +470,7 @@ enum PlanetDetailViewType: Hashable, Equatable {
try fromPlanet.save()

debugPrint("from planet save public")
try fromPlanet.savePublic()
try await fromPlanet.savePublic()

debugPrint("refresh planet store")
let refreshedFromPlanet = try MyPlanetModel.load(from: fromPlanet.basePath)
Expand Down
8 changes: 5 additions & 3 deletions Planet/PlanetAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ extension PlanetAPI {
try planet.uploadAvatar(image: planetAvatarImage)
}
try planet.save()
try planet.savePublic()
try await planet.savePublic()
PlanetStore.shared.myPlanets.insert(planet, at: 0)
PlanetStore.shared.selectedView = .myPlanet(planet)
} catch {
Expand Down Expand Up @@ -283,7 +283,7 @@ extension PlanetAPI {
try planet.save()
try planet.copyTemplateAssets()
try planet.articles.forEach { try $0.savePublic() }
try planet.savePublic()
try await planet.savePublic()
NotificationCenter.default.post(name: .loadArticle, object: nil)
try await planet.publish()
} catch {
Expand Down Expand Up @@ -497,7 +497,9 @@ extension PlanetAPI {
planet.updated = Date()
do {
try planet.save()
try planet.savePublic()
Task {
try await planet.savePublic()
}
if PlanetStore.shared.selectedArticle == article {
PlanetStore.shared.selectedArticle = nil
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/Views/Create & Follow Planet/CreatePlanetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct CreatePlanetView: View {
}
planetStore.selectedView = .myPlanet(planet)
try planet.save()
try planet.savePublic()
try await planet.savePublic()
} catch {
PlanetStore.shared.alert(title: "Failed to create planet")
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/Views/My/MyArticleItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct MyArticleItemView: View {
planet.updated = Date()
Task {
try planet.save()
try planet.savePublic()
try await planet.savePublic()
}
if PlanetStore.shared.selectedArticle == article {
PlanetStore.shared.selectedArticle = nil
Expand Down
4 changes: 2 additions & 2 deletions Planet/Views/My/MyArticleSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ struct MyArticleSettingsView: View {
try planet.copyTemplateAssets()
planet.updated = Date()
try planet.save()
try planet.savePublic()
Task {
Task(priority: .background) {
try await planet.savePublic()
try await planet.publish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/Views/My/MyPlanetCustomCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct MyPlanetCustomCodeView: View {
try planet.save()
try planet.copyTemplateAssets()
try planet.articles.forEach { try $0.savePublic() }
try planet.savePublic()
try await planet.savePublic()
NotificationCenter.default.post(name: .loadArticle, object: nil)
try await planet.publish()
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/Views/My/MyPlanetPodcastSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct MyPlanetPodcastSettingsView: View {
try planet.save()
try planet.copyTemplateAssets()
try planet.articles.forEach { try $0.savePublic() }
try planet.savePublic()
try await planet.savePublic()
NotificationCenter.default.post(name: .loadArticle, object: nil)
try await planet.publish()
}
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 1551
CURRENT_PROJECT_VERSION = 1556

0 comments on commit 303453f

Please sign in to comment.