Pass 'userProfileWriter' in to the ProfileFetcher job.
This commit is contained in:
parent
15efc04b51
commit
b1ddffc05c
@ -205,7 +205,7 @@ public class BackupArchiveAvatarFetcher {
|
||||
} else {
|
||||
_ = try await profileFetcher.fetchProfileImpl(
|
||||
for: serviceId,
|
||||
context: .init(isOpportunistic: true),
|
||||
context: .init(isOpportunistic: true, userProfileWriter: .backupRestore),
|
||||
authedAccount: .implicit(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -16,10 +16,20 @@ public struct ProfileFetchContext {
|
||||
/// If true, the fetch must try to fetch a new credential.
|
||||
public var mustFetchNewCredential: Bool
|
||||
|
||||
public init(groupId: GroupIdentifier? = nil, isOpportunistic: Bool = false, mustFetchNewCredential: Bool = false) {
|
||||
/// The nature of the user profile fetch. This determines side-effect behavior
|
||||
/// such as if storage service is updated after the write.
|
||||
public var userProfileWriter: UserProfileWriter
|
||||
|
||||
public init(
|
||||
groupId: GroupIdentifier? = nil,
|
||||
isOpportunistic: Bool = false,
|
||||
mustFetchNewCredential: Bool = false,
|
||||
userProfileWriter: UserProfileWriter = .profileFetch,
|
||||
) {
|
||||
self.groupId = groupId
|
||||
self.isOpportunistic = isOpportunistic
|
||||
self.mustFetchNewCredential = mustFetchNewCredential
|
||||
self.userProfileWriter = userProfileWriter
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +63,13 @@ public enum ProfileFetcherError: Error {
|
||||
}
|
||||
|
||||
public actor ProfileFetcherImpl: ProfileFetcher {
|
||||
private let jobCreator: (ServiceId, GroupIdentifier?, _ mustFetchNewCredential: Bool, AuthedAccount) -> ProfileFetcherJob
|
||||
private let jobCreator: (
|
||||
ServiceId,
|
||||
GroupIdentifier?,
|
||||
_ mustFetchNewCredential: Bool,
|
||||
AuthedAccount,
|
||||
UserProfileWriter,
|
||||
) -> ProfileFetcherJob
|
||||
private let reachabilityManager: any SSKReachabilityManager
|
||||
private let tsAccountManager: any TSAccountManager
|
||||
|
||||
@ -101,7 +117,7 @@ public actor ProfileFetcherImpl: ProfileFetcher {
|
||||
) {
|
||||
self.reachabilityManager = reachabilityManager
|
||||
self.tsAccountManager = tsAccountManager
|
||||
self.jobCreator = { serviceId, groupIdContext, mustFetchNewCredential, authedAccount in
|
||||
self.jobCreator = { serviceId, groupIdContext, mustFetchNewCredential, authedAccount, userProfileWriter in
|
||||
return ProfileFetcherJob(
|
||||
serviceId: serviceId,
|
||||
groupIdContext: groupIdContext,
|
||||
@ -118,6 +134,7 @@ public actor ProfileFetcherImpl: ProfileFetcher {
|
||||
tsAccountManager: tsAccountManager,
|
||||
udManager: udManager,
|
||||
versionedProfiles: versionedProfiles,
|
||||
userProfileWriter: userProfileWriter,
|
||||
)
|
||||
}
|
||||
SwiftSingletons.register(self)
|
||||
@ -248,7 +265,13 @@ public actor ProfileFetcherImpl: ProfileFetcher {
|
||||
context: ProfileFetchContext,
|
||||
authedAccount: AuthedAccount,
|
||||
) async throws -> FetchedProfile {
|
||||
let result = await Result { try await jobCreator(serviceId, context.groupId, context.mustFetchNewCredential, authedAccount).run() }
|
||||
let result = await Result { try await jobCreator(
|
||||
serviceId,
|
||||
context.groupId,
|
||||
context.mustFetchNewCredential,
|
||||
authedAccount,
|
||||
context.userProfileWriter,
|
||||
).run() }
|
||||
let outcome: FetchResult.Outcome
|
||||
do {
|
||||
_ = try result.get()
|
||||
|
||||
@ -32,6 +32,7 @@ public class ProfileFetcherJob {
|
||||
private let tsAccountManager: any TSAccountManager
|
||||
private let udManager: any OWSUDManager
|
||||
private let versionedProfiles: any VersionedProfiles
|
||||
private let userProfileWriter: UserProfileWriter
|
||||
|
||||
init(
|
||||
serviceId: ServiceId,
|
||||
@ -49,6 +50,7 @@ public class ProfileFetcherJob {
|
||||
tsAccountManager: any TSAccountManager,
|
||||
udManager: any OWSUDManager,
|
||||
versionedProfiles: any VersionedProfiles,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
) {
|
||||
self.serviceId = serviceId
|
||||
self.groupIdContext = groupIdContext
|
||||
@ -65,6 +67,7 @@ public class ProfileFetcherJob {
|
||||
self.tsAccountManager = tsAccountManager
|
||||
self.udManager = udManager
|
||||
self.versionedProfiles = versionedProfiles
|
||||
self.userProfileWriter = userProfileWriter
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
@ -78,7 +81,11 @@ public class ProfileFetcherJob {
|
||||
let localIdentifiers = try tsAccountManager.localIdentifiersWithMaybeSneakyTransaction(authedAccount: authedAccount)
|
||||
do {
|
||||
let fetchedProfile = try await requestProfile(localIdentifiers: localIdentifiers)
|
||||
try await updateProfile(fetchedProfile: fetchedProfile, localIdentifiers: localIdentifiers)
|
||||
try await updateProfile(
|
||||
fetchedProfile: fetchedProfile,
|
||||
localIdentifiers: localIdentifiers,
|
||||
userProfileWriter: userProfileWriter,
|
||||
)
|
||||
return fetchedProfile
|
||||
} catch ProfileRequestError.notFound {
|
||||
let isRegistered = db.read { tx in
|
||||
@ -319,6 +326,7 @@ public class ProfileFetcherJob {
|
||||
private func updateProfile(
|
||||
fetchedProfile: FetchedProfile,
|
||||
localIdentifiers: LocalIdentifiers,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
) async throws {
|
||||
await updateProfile(
|
||||
fetchedProfile: fetchedProfile,
|
||||
@ -327,6 +335,7 @@ public class ProfileFetcherJob {
|
||||
localIdentifiers: localIdentifiers,
|
||||
),
|
||||
localIdentifiers: localIdentifiers,
|
||||
userProfileWriter: userProfileWriter,
|
||||
)
|
||||
}
|
||||
|
||||
@ -406,6 +415,7 @@ public class ProfileFetcherJob {
|
||||
fetchedProfile: FetchedProfile,
|
||||
avatarDownloadResult: AvatarDownloadResult,
|
||||
localIdentifiers: LocalIdentifiers,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
) async {
|
||||
let profile = fetchedProfile.profile
|
||||
let serviceId = profile.serviceId
|
||||
@ -457,7 +467,7 @@ public class ProfileFetcherJob {
|
||||
avatarFileName: avatarFilename,
|
||||
profileBadges: profileBadgeMetadata,
|
||||
lastFetchDate: Date(),
|
||||
userProfileWriter: .profileFetch,
|
||||
userProfileWriter: userProfileWriter,
|
||||
tx: transaction,
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user