Skip to content

Commit

Permalink
feat: 🎸 request notify after add friends
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun committed Oct 15, 2023
1 parent dfc8e8a commit 7ee8f39
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Packages/GodPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ let package = Package(
.product(name: "RoundedCorner", package: "UIComponentPackage"),
.product(name: "AnalyticsClient", package: "DependencyPackage"),
.product(name: "UserDefaultsClient", package: "CupertinoPackage"),
.product(name: "UIApplicationClient", package: "CupertinoPackage"),
.product(name: "FirebaseAuthClient", package: "DependencyPackage"),
.product(name: "UserNotificationClient", package: "CupertinoPackage"),
.product(name: "FirebaseStorageClient", package: "DependencyPackage"),
.product(name: "PhoneNumberDependencies", package: "DependencyPackage"),
.product(name: "CachedAsyncImage", package: "swiftui-cached-async-image"),
Expand Down
5 changes: 0 additions & 5 deletions Packages/GodPackage/Sources/AppFeature/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public struct AppDelegateLogic: Reducer {
firebaseCore.configure()
return .run { @MainActor send in
await withThrowingTaskGroup(of: Void.self) { group in
group.addTask {
guard try await userNotifications.requestAuthorization([.alert, .sound, .badge])
else { return }
await registerForRemoteNotifications()
}
group.addTask {
for await event in userNotifications.delegate() {
await send(.userNotifications(event))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct HowItWorksLogic: Reducer {

public enum Delegate: Equatable {
case start
case notifyRequest
}
}

Expand All @@ -35,6 +36,7 @@ public struct HowItWorksLogic: Reducer {
switch action {
case .onTask:
return .run { send in
await send(.delegate(.notifyRequest))
for try await data in godClient.currentUser() {
await send(.currentUserResponse(.success(data)))
}
Expand Down
12 changes: 12 additions & 0 deletions Packages/GodPackage/Sources/OnboardFeature/OnboardPathLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ContactsClient
import God
import GodClient
import UserDefaultsClient
import UserNotificationClient
import UIApplicationClient

public struct OnboardPathLogic: Reducer {
@Dependency(\.analytics) var analytics
Expand All @@ -31,6 +33,9 @@ public struct OnboardPathLogic: Reducer {
await send(.contactResponse(.failure(error)))
}
}

@Dependency(\.userNotifications.requestAuthorization) var requestAuthorization
@Dependency(\.application.registerForRemoteNotifications) var registerForRemoteNotifications

public func reduce(
into state: inout OnboardLogic.State,
Expand Down Expand Up @@ -136,6 +141,13 @@ public struct OnboardPathLogic: Reducer {
case .addFriends(.delegate(.nextScreen)):
state.path.append(.howItWorks())
return .none

case .howItWorks(.delegate(.notifyRequest)):
return .run { send in
guard try await requestAuthorization([.alert, .sound, .badge])
else { return }
await registerForRemoteNotifications()
}

case .howItWorks(.delegate(.start)):
// オンボーディングすべて終わり
Expand Down

0 comments on commit 7ee8f39

Please sign in to comment.