AppActions.swift (2065B)
1 import Foundation 2 import SwiftUI 3 4 @MainActor 5 final class AppActions { 6 private unowned let services: AppServices 7 8 init(services: AppServices) { 9 self.services = services 10 } 11 12 func resetDatabase() async { 13 do { 14 try await services.cloudService.resetAllData() 15 } catch { 16 services.announcements.post(Announcement( 17 id: "reset-database-error", 18 scope: .global, 19 severity: .error, 20 title: "Resetting Failed", 21 body: error.localizedDescription, 22 dismissal: .manual 23 )) 24 } 25 } 26 27 func inviteFriend(gameID: UUID, friendAuthorID: String) async throws { 28 try await services.invites.inviteFriend(gameID: gameID, friendAuthorID: friendAuthorID) 29 } 30 31 func acceptInvite(shareURL: String, pingRecordName: String) async throws { 32 _ = try await services.invites.acceptInvite( 33 shareURL: shareURL, 34 pingRecordName: pingRecordName 35 ) 36 } 37 38 func declineInvite(gameID: UUID) async throws { 39 try await services.invites.declineInvite(gameID: gameID) 40 } 41 42 func blockFriend(authorID: String) async { 43 await services.invites.blockFriend(authorID: authorID) 44 } 45 46 func unblockFriend(authorID: String) async { 47 await services.invites.unblockFriend(authorID: authorID) 48 } 49 50 func renameFriend(authorID: String, nickname: String) async { 51 do { 52 try await services.friendController.setNickname( 53 friendAuthorID: authorID, 54 nickname: nickname 55 ) 56 } catch { 57 services.announcements.post(Announcement( 58 id: "rename-friend-error-\(authorID)", 59 scope: .global, 60 severity: .error, 61 title: "Renaming Failed", 62 body: error.localizedDescription, 63 dismissal: .manual 64 )) 65 } 66 } 67 68 } 69 70 extension EnvironmentValues { 71 @Entry var appActions: AppActions? = nil 72 }