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

New profile fixes #760

Merged
merged 10 commits into from
Aug 5, 2020
Prev Previous commit
Fix social profiles shows error state on empty cache
  • Loading branch information
ivan-magda committed Aug 5, 2020
commit 31d4846b5bbc10ae344f871920ee1414bad2f585
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ final class NewProfileSocialProfilesInteractor: NewProfileSocialProfilesInteract
}.ensure {
if !strongSelf.didLoadFromCache {
strongSelf.didLoadFromCache = true
strongSelf.isOnline = true
strongSelf.doSocialProfilesLoad(request: .init())
}
strongSelf.fetchSemaphore.signal()
@@ -96,21 +97,16 @@ final class NewProfileSocialProfilesInteractor: NewProfileSocialProfilesInteract

self.currentSocialProfilesIDs = Set(socialProfiles.map(\.id))

// There are no social profiles in cache.
// There are no social profiles in cache, ignore and wait for network response.
if self.currentSocialProfilesIDs.isEmpty && !shouldFetchRemote {
// Wait for network response.
if self.isOnline {
seal.fulfill(.init(result: .failure(Error.emptyCache)))
} else {
seal.reject(Error.fetchFailed)
}
seal.fulfill(.init(result: .failure(Error.emptyCache)))
} else {
seal.fulfill(.init(result: .success(socialProfiles)))
}
}.catch { error in
if case NewProfileSocialProfilesProvider.Error.networkFetchFailed = error,
self.didLoadFromCache,
!self.currentSocialProfilesIDs.isEmpty {
self.didLoadFromCache,
!self.currentSocialProfilesIDs.isEmpty {
// Offline mode: we already presented cached social profiles, but network request failed
// so let's ignore it and show only cached
seal.fulfill(.init(result: .failure(Error.networkFetchFailed)))
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ final class NewProfileSocialProfilesViewController: UIViewController, Controller

switch newState {
case .result(let viewModel):
self.isPlaceholderShown = false
self.socialProfilesView?.configure(viewModel: viewModel)
case .error:
self.showPlaceholder(for: .connectionError)