Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ extension PokeMainRepository: PokeMainRepositoryInterface {
.map { $0.toDomain() }
.eraseToAnyPublisher()
}

public func getIsNewUser() -> AnyPublisher<Bool, any Error> {
pokeService.isNewUser()
.map { $0.isNew }
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import Combine
public protocol PokeMainRepositoryInterface: PokeRepositoryInterface {
func getWhoPokeToMe() -> AnyPublisher<PokeUserModel?, Error>
func getFriend() -> AnyPublisher<[PokeUserModel], Error>
func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher<PokeFriendRandomUserModel, Error>
func getFriendRandomUser(randomType: String, size: Int) -> AnyPublisher<PokeFriendRandomUserModel, Error>
func getIsNewUser() -> AnyPublisher<Bool, any Error>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 Error 타입도 any로 맞추면 좋을 것 같습니다! 추후 Swif6로 마이그레이션 할 때 같이 붙여보아요 . .

}
25 changes: 24 additions & 1 deletion SOPT-iOS/Projects/Domain/Sources/UseCase/PokeMainUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public protocol PokeMainUseCase {
var pokedResponse: PassthroughSubject<PokeUserModel, Never> { get }
var madeNewFriend: PassthroughSubject<PokeUserModel, Never> { get }
var errorMessage: PassthroughSubject<String?, Never> { get }
var isNewUser: PassthroughSubject<Bool, Never> { get }

func getWhoPokedToMe()
func getFriend()
func getFriendRandomUser(randomType: PokeRandomUserType, size: Int)
func poke(userId: Int, message: PokeMessageModel, isAnonymous: Bool, willBeNewFriend: Bool)
func poke(userId: Int, message: PokeMessageModel, isAnonymous: Bool, willBeNewFriend: Bool)
func checkPokeOnboardingNeeded()
}

public class DefaultPokeMainUseCase {
Expand All @@ -34,6 +36,7 @@ public class DefaultPokeMainUseCase {
public let pokedResponse = PassthroughSubject<PokeUserModel, Never>()
public let madeNewFriend = PassthroughSubject<PokeUserModel, Never>()
public let errorMessage = PassthroughSubject<String?, Never>()
public let isNewUser = PassthroughSubject<Bool, Never>()

public init(repository: PokeMainRepositoryInterface) {
self.repository = repository
Expand Down Expand Up @@ -89,4 +92,24 @@ extension DefaultPokeMainUseCase: PokeMainUseCase {
}
}.store(in: self.cancelBag)
}

public func checkPokeOnboardingNeeded() {
#warning("TODO: 온보딩 노출조건 변경으로 기존 유저들을 위해서 임시로 추가 추후 getIsNewUser 체크 로직 제거 필요")
Just(UserDefaultKeyList.User.isVisitedPokeMainView ?? false)
.withUnretained(self)
.flatMap { [weak self] owner, isVisited in
if isVisited {
return Just(false)
.eraseToAnyPublisher()
} else {
return owner.repository.getIsNewUser()
.replaceError(with: false)
.eraseToAnyPublisher()
}
}
Comment on lines +98 to +109
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Just(UserDefaultKeyList.User.isVisitedPokeMainView ?? false)
.flatMap { [weak self] isVisited in
guard let self = self else { return Just(false).eraseToAnyPublisher() }
if isVisited {
return Just(false)
.eraseToAnyPublisher()
} else {
return repository.getIsNewUser()
.replaceError(with: false)
.eraseToAnyPublisher()
}
}
Just(UserDefaultKeyList.User.isVisitedPokeMainView ?? false)
.withUnretained(self)
.flatMap { owner, isVisited in
if isVisited {
return Just(false)
.eraseToAnyPublisher()
} else {
return repository.getIsNewUser()
.replaceError(with: false)
.eraseToAnyPublisher()
}

withUnretained를 쓰면 프로젝트 컨벤션에도 맞고 코드도 훨씬 간결해질 것 같습니다!

.withUnretained(self)
.sink { [weak self] owner, isNewUser in
owner.isNewUser.send(isNewUser)
}.store(in: self.cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,9 @@ extension PokeMainViewModel {
self?.useCase.getFriendRandomUser(randomType: .all, size: 2)
}.store(in: cancelBag)

input.viewDidLoad
.map { _ in UserDefaultKeyList.User.isVisitedPokeMainView ?? false }
.withUnretained(self)
.sink { owner, isVisitedPokeMainView in
owner.onPokeOnboardingNeeded?(!isVisitedPokeMainView)
}
.store(in: cancelBag)

input.viewDidLoad
.sink { [weak self] _ in
self?.useCase.checkPokeOnboardingNeeded()
self?.eventTracker.trackViewEvent(with: .viewPokeMain)
}.store(in: cancelBag)

Expand Down Expand Up @@ -168,6 +161,10 @@ extension PokeMainViewModel {

private func bindOutput(output: Output, cancelBag: CancelBag) {

useCase.isNewUser
.sink { [weak self] isNewUser in self?.onPokeOnboardingNeeded?(isNewUser) }
.store(in: cancelBag)

useCase.pokedToMeUser
.compactMap { $0 }
.sink { output.pokedToMeUser.send($0) }
Expand Down