Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 request notify after add friends #764

Merged
merged 1 commit into from
Oct 15, 2023
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: 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