Skip to content

Commit

Permalink
Bump version and fix release bugs (#78)
Browse files Browse the repository at this point in the history
* Bump version and fix release bugs

* fix navigation when leaving competitions

* some cleanup
  • Loading branch information
EvanCooper9 authored Jan 24, 2023
1 parent 3ee4347 commit 9af7d27
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Friendly Competitions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.8.1;
MARKETING_VERSION = 1.8.2;
OTHER_LDFLAGS = "-Objc";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-expression-type-checking=200";
PRODUCT_BUNDLE_IDENTIFIER = com.evancooper.FriendlyCompetitions.debug;
Expand Down Expand Up @@ -1751,7 +1751,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.8.1;
MARKETING_VERSION = 1.8.2;
OTHER_LDFLAGS = "-Objc";
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-expression-type-checking=200";
PRODUCT_BUNDLE_IDENTIFIER = com.evancooper.FriendlyCompetitions;
Expand Down
1 change: 1 addition & 0 deletions Friendly Competitions/Factory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extension Container {
case .prod:
break
case .debug:
settings.isPersistenceEnabled = false
settings.isSSLEnabled = false
switch environment.emulationType {
case .localhost:
Expand Down
16 changes: 13 additions & 3 deletions Friendly Competitions/Managers/CompetitionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ final class CompetitionsManager: CompetitionsManaging {
functions.httpsCallable("joinCompetition")
.call(["competitionID": competition.id])
.mapToVoid()
.handleEvents(withUnretained: self, receiveOutput: { $0.lastCompetitionStandingsUpdate[competition.id] = nil })
.eraseToAnyPublisher()
}

func leave(_ competition: Competition) -> AnyPublisher<Void, Error> {
functions.httpsCallable("leaveCompetition")
.call(["competitionID": competition.id])
.mapToVoid()
.handleEvents(withUnretained: self, receiveOutput: { $0.lastCompetitionStandingsUpdate[competition.id] = nil })
.eraseToAnyPublisher()
}

Expand Down Expand Up @@ -300,10 +302,18 @@ private extension Dictionary where Key == Competition.ID {
}

extension Query {

/// Attempts to get documents from the cache. If that fails, it will get documents from the server.
/// - Returns: A publisher emitting a QuerySnapshot instance.
func getDocumentsPreferCache() -> AnyPublisher<QuerySnapshot, Error> {
getDocuments(source: .cache)
.catch { [weak self] _ -> AnyPublisher<QuerySnapshot, Error> in
self?.getDocuments(source: .server).eraseToAnyPublisher() ?? .never()
let serverQuery = self // after query is ran, it's gone. Can't use `self` in escaping closures below
return getDocuments(source: .cache)
.catch { [serverQuery] _ -> AnyPublisher<QuerySnapshot, Error> in
serverQuery.getDocuments(source: .server).eraseToAnyPublisher()
}
.flatMapLatest { [serverQuery] snapshot -> AnyPublisher<QuerySnapshot, Error> in
guard snapshot.isEmpty else { return .just(snapshot) }
return serverQuery.getDocuments(source: .server).eraseToAnyPublisher()
}
.eraseToAnyPublisher()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol EnvironmentManaging {
final class EnvironmentManager: EnvironmentManaging {

private enum Constants {
static var environmentKey: String { #file + #function }
static var environmentKey: String { #function }
}

// MARK: - Public Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import HealthKit

// sourcery: AutoMockable
protocol HealthKitManaging {
var backgroundDeliveryReceived: AnyPublisher<Void, Never> { get }
var permissionStatus: AnyPublisher<PermissionStatus, Never> { get }
func execute(_ query: HKQuery)
func registerBackgroundDeliveryTask(_ publisher: AnyPublisher<Void, Never>)
Expand All @@ -17,7 +16,6 @@ final class HealthKitManager: HealthKitManaging {

// MARK: - Public Properties

var backgroundDeliveryReceived: AnyPublisher<Void, Never> { backgroundDeliveryReceivedSubject.eraseToAnyPublisher() }
let permissionStatus: AnyPublisher<PermissionStatus, Never>

// MARK: - Private Properties
Expand Down Expand Up @@ -99,10 +97,7 @@ final class HealthKitManager: HealthKitManaging {
Publishers
.ZipMany(strongSelf.backgroundDeliveryPublishers)
.mapToVoid()
.sink(receiveValue: {
print("trigger bg delivery finished")
completion()
})
.sink(receiveValue: completion)
.store(in: &strongSelf.cancellables)
}
healthStore.execute(query)
Expand Down
16 changes: 8 additions & 8 deletions Friendly Competitions/Managers/Premium/PremiumManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ final class PremiumManager: PremiumManaging {
.sink()
.store(in: &cancellables)

// customerInfoTask = .init { [weak self] in
// for try await _ in Purchases.shared.customerInfoStream { [weak self] in
// guard let strongSelf = self else { return }
// strongSelf.restorePurchases()
// .sink()
// .store(in: &strongSelf.cancellables)
// }
// }
customerInfoTask = .init { [weak self] in
for try await _ in Purchases.shared.customerInfoStream {
guard let strongSelf = self else { return }
strongSelf.restorePurchases()
.sink()
.store(in: &strongSelf.cancellables)
}
}
}

// MARK: - Public Methods
Expand Down
5 changes: 0 additions & 5 deletions Friendly Competitions/Sourcery/AutoMockable.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,6 @@ class FriendsManagingMock: FriendsManaging {

}
class HealthKitManagingMock: HealthKitManaging {
var backgroundDeliveryReceived: AnyPublisher<Void, Never> {
get { return underlyingBackgroundDeliveryReceived }
set(value) { underlyingBackgroundDeliveryReceived = value }
}
var underlyingBackgroundDeliveryReceived: AnyPublisher<Void, Never>!
var permissionStatus: AnyPublisher<PermissionStatus, Never> {
get { return underlyingPermissionStatus }
set(value) { underlyingPermissionStatus = value }
Expand Down
29 changes: 19 additions & 10 deletions Friendly Competitions/Views/Competitions/CompetitionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,17 @@ final class CompetitionViewModel: ObservableObject {
}
.assign(to: &$actions)

competitionsManager.competitions
.compactMap { $0.first { $0.id == competition.id } }
.receive(on: RunLoop.main)
.assign(to: &$competition)

Publishers
.CombineLatest(
competitionsManager.standings(for: competition.id).catchErrorJustReturn([]),
competitionsManager.participants(for: competition.id).catchErrorJustReturn([])
)
let fetchStandingsAndParticipants = PassthroughSubject<Void, Never>()
fetchStandingsAndParticipants
.prepend(())
.flatMapLatest(withUnretained: self) { strongSelf in
Publishers
.CombineLatest(
strongSelf.competitionsManager.standings(for: competition.id).catchErrorJustReturn([]),
strongSelf.competitionsManager.participants(for: competition.id).catchErrorJustReturn([])
)
.eraseToAnyPublisher()
}
.handleEvents(
withUnretained: self,
receiveSubscription: { strongSelf, _ in strongSelf.loadingStandings = true },
Expand Down Expand Up @@ -132,6 +133,11 @@ final class CompetitionViewModel: ObservableObject {
}
.assign(to: &$standings)

competitionsManager.competitionPublisher(for: competition.id)
.ignoreFailure()
.handleEvents(receiveOutput: { _ in fetchStandingsAndParticipants.send() })
.assign(to: &$competition)

Publishers.CombineLatest($standings, $currentStandingsMaximum)
.map { $0.count >= $1 }
.assign(to: &$showShowMoreButton)
Expand All @@ -150,6 +156,7 @@ final class CompetitionViewModel: ObservableObject {
case .leave:
return strongSelf.competitionsManager
.leave(competition)
.handleEvents(receiveOutput: { fetchStandingsAndParticipants.send() })
.isLoading { strongSelf.loading = $0 }
.eraseToAnyPublisher()
default:
Expand Down Expand Up @@ -177,6 +184,7 @@ final class CompetitionViewModel: ObservableObject {
case .acceptInvite:
return strongSelf.competitionsManager
.accept(competition)
.handleEvents(receiveOutput: { fetchStandingsAndParticipants.send() })
.isLoading { strongSelf.loading = $0 }
.eraseToAnyPublisher()
case .declineInvite:
Expand All @@ -196,6 +204,7 @@ final class CompetitionViewModel: ObservableObject {
case .join:
return strongSelf.competitionsManager
.join(competition)
.handleEvents(receiveOutput: { fetchStandingsAndParticipants.send() })
.isLoading { strongSelf.loading = $0 }
.eraseToAnyPublisher()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ final class CompetitionResultsViewModel: ObservableObject {
init(competition: Competition) {
self.competition = competition

let results = competitionsManager.results(for: competition.id).catchErrorJustReturn([])
let results = competitionsManager
.results(for: competition.id)
.catchErrorJustReturn([])

Publishers
.CombineLatest3(
Expand Down
16 changes: 10 additions & 6 deletions Friendly Competitions/Views/Home/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,31 @@ final class HomeViewModel: ObservableObject {

Publishers
.CombineLatest4($competitions, $invitedCompetitions, $friendRows, appState.deepLink)
.sink(withUnretained: self) { strongSelf, result in
let (competitions, invitedCompetitions, friendRows, deepLink) = result
.map { [weak self] competitions, invitedCompetitions, friendRows, deepLink -> [NavigationDestination] in
guard let strongSelf = self else { return [] }
let homeScreenCompetitionIDs = Set(competitions.map(\.id) + invitedCompetitions.map(\.id))
let homeScreenFriendIDs = Set(friendRows.map(\.user.id))

// remove stale navigation destinations (ex: leaving a competition, declining a friend invite)
strongSelf.navigationDestinations = strongSelf.navigationDestinations.filter { navigationDestination in
return strongSelf.navigationDestinations.filter { navigationDestination in
// accont for deep link to ensure that if comp/friend lists updates, then the deep link isn't dismissed
switch (navigationDestination, deepLink) {
case (.competition(let competition), .competition(id: let deepLinkedCompeititonID)):
return homeScreenCompetitionIDs.contains(competition.id) || deepLinkedCompeititonID == competition.id
case (.competition(let competition), nil):
return homeScreenCompetitionIDs.contains(competition.id)
case (.competitionResults(let competition), .competitionResults(id: let deepLinkedCompeititonID)):
return homeScreenCompetitionIDs.contains(competition.id) || deepLinkedCompeititonID == competition.id
case (.competitionResults(let competition), nil):
return homeScreenCompetitionIDs.contains(competition.id)
case (.user(let user), .user(id: let deepLinkedUserID)):
return homeScreenFriendIDs.contains(user.id) || deepLinkedUserID == user.id
case (.user(let user), nil):
return homeScreenFriendIDs.contains(user.id)
default:
return true
}
}
}
.store(in: &cancellables)
.assign(to: &$navigationDestinations)

Publishers
.CombineLatest(friendsManager.friends, friendsManager.friendRequests)
Expand Down

0 comments on commit 9af7d27

Please sign in to comment.