Skip to content

Commit

Permalink
Remove last remnants of OWSUserProfile caching
Browse files Browse the repository at this point in the history
  • Loading branch information
max-signal authored Jan 9, 2025
1 parent 78a6c30 commit b7dedf2
Show file tree
Hide file tree
Showing 81 changed files with 702 additions and 1,069 deletions.
8 changes: 4 additions & 4 deletions Signal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@
50C97C252C3C7F7000A9F384 /* CallEventConversation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C97C242C3C7F7000A9F384 /* CallEventConversation.swift */; };
50C98A412B69D9340065BD2E /* PhoneNumberVisibilityFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C98A402B69D9340065BD2E /* PhoneNumberVisibilityFetcher.swift */; };
50CF28F02829C94800752AB3 /* CVComponentGiftBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50CF28EF2829C94800752AB3 /* CVComponentGiftBadge.swift */; };
50D146CD2D1F4E5800D628DE /* ProfileKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D146CC2D1F4E5800D628DE /* ProfileKey.swift */; };
50D2FC7D2AEB134C002E4589 /* AuthorMergeHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D2FC7C2AEB134C002E4589 /* AuthorMergeHelper.swift */; };
50D3136F2BFFE9370023EDCC /* CallEventInserter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D3136E2BFFE9370023EDCC /* CallEventInserter.swift */; };
50D5E2412980AD6F00899660 /* LinkValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D5E2402980AD6F00899660 /* LinkValidator.swift */; };
Expand Down Expand Up @@ -1305,7 +1306,6 @@
72C9058D2B9AC81B00E586B8 /* OWSPaymentsLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 501D64FA28C027BA008D5993 /* OWSPaymentsLock.swift */; };
72C9058E2B9AC8E600E586B8 /* CallMessageRelay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D7BA9D266809F50088D1C2 /* CallMessageRelay.swift */; };
72C905912B9ACA3D00E586B8 /* ScreenLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34641E172088D7E900E2EDE5 /* ScreenLock.swift */; };
72D12EB72C802833001DAD29 /* OWSProfileSnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72D12EB62C802833001DAD29 /* OWSProfileSnapshot.swift */; };
72DB95AE2C8C7C7B00FD2266 /* String+OWS.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72DB95AD2C8C7C7B00FD2266 /* String+OWS.swift */; };
76057C4B29D268A800C9EDBD /* VideoPlaybackControls.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76057C4A29D268A800C9EDBD /* VideoPlaybackControls.swift */; };
760981882936DE90008F8300 /* BezierPathView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 760981872936DE90008F8300 /* BezierPathView.swift */; };
Expand Down Expand Up @@ -4438,6 +4438,7 @@
50C97C242C3C7F7000A9F384 /* CallEventConversation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallEventConversation.swift; sourceTree = "<group>"; };
50C98A402B69D9340065BD2E /* PhoneNumberVisibilityFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberVisibilityFetcher.swift; sourceTree = "<group>"; };
50CF28EF2829C94800752AB3 /* CVComponentGiftBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CVComponentGiftBadge.swift; sourceTree = "<group>"; };
50D146CC2D1F4E5800D628DE /* ProfileKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileKey.swift; sourceTree = "<group>"; };
50D2FC7C2AEB134C002E4589 /* AuthorMergeHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorMergeHelper.swift; sourceTree = "<group>"; };
50D3136E2BFFE9370023EDCC /* CallEventInserter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallEventInserter.swift; sourceTree = "<group>"; };
50D5E2402980AD6F00899660 /* LinkValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkValidator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4977,7 +4978,6 @@
72B0C2412C9EED0800B57DAD /* SignedPreKeyRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignedPreKeyRecord.swift; sourceTree = "<group>"; };
72B4819C2BD60FDF008B8BA1 /* OWSMath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OWSMath.swift; sourceTree = "<group>"; };
72B994DA2BE950DB000CBBFD /* TestAppContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAppContext.swift; sourceTree = "<group>"; };
72D12EB62C802833001DAD29 /* OWSProfileSnapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OWSProfileSnapshot.swift; sourceTree = "<group>"; };
72DB95AD2C8C7C7B00FD2266 /* String+OWS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+OWS.swift"; sourceTree = "<group>"; };
741B66EF7DCE5EF90200211D /* Pods-SignalShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalShareExtension.debug.xcconfig"; path = "Target Support Files/Pods-SignalShareExtension/Pods-SignalShareExtension.debug.xcconfig"; sourceTree = "<group>"; };
76057C4A29D268A800C9EDBD /* VideoPlaybackControls.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoPlaybackControls.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9986,7 +9986,6 @@
F9C5CB66289453B200548EEE /* BadgeStore.swift */,
50159CDC2B4EF75600D344D4 /* LocalProfileChecker.swift */,
3470249D2385B6360078D72C /* OWSProfileManager.swift */,
72D12EB62C802833001DAD29 /* OWSProfileSnapshot.swift */,
F9C5CB68289453B200548EEE /* ProfileFetcher.swift */,
F9C5CB67289453B200548EEE /* ProfileFetcherJob.swift */,
F9C5CB6A289453B200548EEE /* VersionedProfiles.swift */,
Expand Down Expand Up @@ -13316,6 +13315,7 @@
C18E3C712A9FF65D003D1CF1 /* PniDistributionSyncMessage.swift */,
D9CAF7482A09CCE50049193A /* PniHelloWorldManager.swift */,
D9F399AC2A95798A001599EC /* PniIdentityKeyChecker.swift */,
50D146CC2D1F4E5800D628DE /* ProfileKey.swift */,
507CD5E429660D5100E47DAC /* ServiceId.swift */,
);
path = Account;
Expand Down Expand Up @@ -17420,7 +17420,6 @@
72C9058D2B9AC81B00E586B8 /* OWSPaymentsLock.swift in Sources */,
F9C5CC32289453B300548EEE /* OWSProfileKeyMessage.m in Sources */,
724D47B82B97C301001BE973 /* OWSProfileManager.swift in Sources */,
72D12EB72C802833001DAD29 /* OWSProfileSnapshot.swift in Sources */,
66A830442CEBFCC700A7656D /* OWSProgress.swift in Sources */,
F9C5CCF1289453B300548EEE /* OWSProvisioningCipher.swift in Sources */,
F9C5CC3A289453B300548EEE /* OWSReaction.swift in Sources */,
Expand Down Expand Up @@ -17522,6 +17521,7 @@
D995546F2AF5668E0001E15C /* ProfileBadgesSnapshot.swift in Sources */,
F9C5CE39289453B400548EEE /* ProfileFetcher.swift in Sources */,
F9C5CE38289453B400548EEE /* ProfileFetcherJob.swift in Sources */,
50D146CD2D1F4E5800D628DE /* ProfileKey.swift in Sources */,
503BD2892B44D666009624FC /* ProfileManager.swift in Sources */,
72901D2D2C9B129B000406DC /* ProfileManagerProtocol.swift in Sources */,
B93296692BBB3FF200B8BD39 /* ProfileName.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Signal/AppLaunch/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class AppEnvironment: NSObject {
}

Task {
DonationSubscriptionManager.performMigrationToStorageServiceIfNecessary()
await DonationSubscriptionManager.performMigrationToStorageServiceIfNecessary()
do {
try await DonationSubscriptionManager.redeemSubscriptionIfNecessary()
} catch {
Expand Down
34 changes: 12 additions & 22 deletions Signal/Calls/UserInterface/CallMemberCameraOffView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,41 +281,31 @@ class BlurredAvatarBackgroundView: UIView {
type: CallMemberView.MemberType,
remoteGroupMemberDeviceState: RemoteDeviceState?
) {
let backgroundAvatarImage: UIImage?
var backgroundColor: UIColor?
let address: SignalServiceAddress
switch type {
case .local:
SSKEnvironment.shared.databaseStorageRef.read { tx in
guard let localAddress = DependenciesBridge.shared.tsAccountManager.localIdentifiers(tx: tx.asV2Read)?.aciAddress else {
owsFailDebug("missing local address")
return
}
backgroundColor = AvatarTheme.forAddress(localAddress).backgroundColor
let tsAccountManager = DependenciesBridge.shared.tsAccountManager
guard let localAddress = tsAccountManager.localIdentifiersWithMaybeSneakyTransaction?.aciAddress else {
owsFailDebug("missing local address")
return
}
backgroundAvatarImage = SSKEnvironment.shared.profileManagerRef.localProfileAvatarImage
address = localAddress
case .remoteInGroup:
guard let remoteGroupMemberDeviceState else { return }
let (image, color) = avatarImageAndBackgroundColorWithSneakyTransaction(for: remoteGroupMemberDeviceState.address)
backgroundAvatarImage = image
backgroundColor = color
address = remoteGroupMemberDeviceState.address
case .remoteInIndividual(let individualCall):
let (image, color) = avatarImageAndBackgroundColorWithSneakyTransaction(for: individualCall.remoteAddress)
backgroundAvatarImage = image
backgroundColor = color
address = individualCall.remoteAddress
}
backgroundAvatarView.image = backgroundAvatarImage
self.backgroundColor = backgroundColor
let (image, color) = self.avatarImageAndBackgroundColorWithSneakyTransaction(for: address)
backgroundAvatarView.image = image
self.backgroundColor = color
}

private func avatarImageAndBackgroundColorWithSneakyTransaction(
for address: SignalServiceAddress
) -> (UIImage?, UIColor?) {
let profileImage = SSKEnvironment.shared.databaseStorageRef.read { tx in
return SSKEnvironment.shared.contactManagerImplRef.avatarImage(
forAddress: address,
shouldValidate: true,
transaction: tx
)
return SSKEnvironment.shared.contactManagerImplRef.avatarImage(forAddress: address, transaction: tx)
}
return (
profileImage,
Expand Down
14 changes: 5 additions & 9 deletions Signal/Calls/UserInterface/GroupCallNotificationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,11 @@ private class BannerView: UIView {
avatarView.autoVCenterInSuperview()
avatarView.autoMatch(.height, to: .width, of: avatarView)

if address.isLocalAddress,
let avatarImage = SSKEnvironment.shared.profileManagerRef.localProfileAvatarImage {
avatarView.image = avatarImage
} else {
let avatar = SSKEnvironment.shared.avatarBuilderRef.avatarImageWithSneakyTransaction(forAddress: address,
diameterPoints: 40,
localUserDisplayMode: .asUser)
avatarView.image = avatar
}
avatarView.image = SSKEnvironment.shared.avatarBuilderRef.avatarImageWithSneakyTransaction(
forAddress: address,
diameterPoints: 40,
localUserDisplayMode: .asUser
)
}

let label = UILabel()
Expand Down
8 changes: 4 additions & 4 deletions Signal/Calls/UserInterface/IndividualCallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ class IndividualCallViewController: OWSViewController, IndividualCallObserver {

@objc
private func updateAvatarImage() {
SSKEnvironment.shared.databaseStorageRef.read { transaction in
backgroundAvatarView.image = SSKEnvironment.shared.contactManagerImplRef.avatarImage(forAddress: thread.contactAddress,
shouldValidate: true,
transaction: transaction)
let contactManager = SSKEnvironment.shared.contactManagerImplRef
let databaseStorage = SSKEnvironment.shared.databaseStorageRef
backgroundAvatarView.image = databaseStorage.read { tx in
return contactManager.avatarImage(forAddress: thread.contactAddress, transaction: tx)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ extension CVComponentSystemMessage {
return nil
}
let newProfileName = OWSFormat.formatNameComponents(profileChangesNewNameComponents)
let currentProfileName = SSKEnvironment.shared.profileManagerRef.fullName(for: profileChangeAddress, transaction: transaction)
let currentProfileName = SSKEnvironment.shared.profileManagerRef.userProfile(for: profileChangeAddress, tx: transaction)?.filteredFullName

// Only show the button if the address book contact's name is different
// than the profile name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ public class CVComponentThreadDetails: CVComponentBase, CVRootComponent {
if contactThread.isNoteToSelf {
return nil
}
return SSKEnvironment.shared.profileManagerImplRef.profileBioForDisplay(for: contactThread.contactAddress,
transaction: transaction)
let profileManager = SSKEnvironment.shared.profileManagerRef
let userProfile = profileManager.userProfile(for: contactThread.contactAddress, tx: transaction)
return userProfile?.bioForDisplay
}()

let detailsText = { () -> String? in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ public extension ConversationViewController {
for address: SignalServiceAddress,
tx: SDSAnyReadTransaction
) -> UIImage? {
if
address.isLocalAddress,
let profileAvatar = SSKEnvironment.shared.profileManagerRef.localProfileAvatarImage
{
return profileAvatar.resizedImage(to: CGSize(square: 24))
}
return SSKEnvironment.shared.avatarBuilderRef.avatarImage(
forAddress: address,
diameterPoints: 24,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ extension ConversationViewController {
if isExpired {
let mode: BadgeIssueSheetState.Mode
if isRedeemed {
let hasCurrentSubscription = DonationSubscriptionManager.probablyHasCurrentSubscription()
let hasCurrentSubscription = SSKEnvironment.shared.databaseStorageRef.read { tx -> Bool in
return DonationSubscriptionManager.probablyHasCurrentSubscription(tx: tx)
}
mode = .giftBadgeExpired(hasCurrentSubscription: hasCurrentSubscription)
} else {
let fullName = SSKEnvironment.shared.databaseStorageRef.read { transaction -> String in
Expand All @@ -106,8 +108,14 @@ extension ConversationViewController {

private func giftRedemptionSheet(incomingMessage: TSIncomingMessage, profileBadge: ProfileBadge) -> UIViewController {
let authorAddress = incomingMessage.authorAddress
let shortName = SSKEnvironment.shared.databaseStorageRef.read { transaction in
SSKEnvironment.shared.contactManagerRef.displayName(for: authorAddress, tx: transaction).resolvedValue(useShortNameIfAvailable: true)
let contactManager = SSKEnvironment.shared.contactManagerRef
let profileManager = SSKEnvironment.shared.profileManagerRef
let databaseStorage = SSKEnvironment.shared.databaseStorageRef
let (shortName, oldBadgesSnapshot) = databaseStorage.read { tx in
return (
contactManager.displayName(for: authorAddress, tx: tx).resolvedValue(useShortNameIfAvailable: true),
ProfileBadgesSnapshot.forLocalProfile(profileManager: profileManager, tx: tx)
)
}
return BadgeThanksSheet(
newBadge: profileBadge,
Expand All @@ -116,7 +124,7 @@ extension ConversationViewController {
notNowAction: { [weak self] in self?.showRedeemBadgeLaterText() },
incomingMessage: incomingMessage
),
oldBadgesSnapshot: .current()
oldBadgesSnapshot: oldBadgesSnapshot
)
}

Expand Down
2 changes: 1 addition & 1 deletion Signal/ConversationView/Loading/CVAvatarBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class CVAvatarBuilder {
let badgeImage: UIImage?
if includingBadge {
// TODO: Badges — Unify with ConversationAvatarDataSource
let userProfile = SSKEnvironment.shared.profileManagerRef.getUserProfile(for: address, transaction: transaction)
let userProfile = SSKEnvironment.shared.profileManagerRef.userProfile(for: address, tx: transaction)
let sizeClass = ConversationAvatarView.Configuration.SizeClass(avatarDiameter: diameterPoints)
let badge = userProfile?.primaryBadge?.fetchBadgeContent(transaction: transaction)
if let badgeAssets = badge?.assets {
Expand Down
6 changes: 3 additions & 3 deletions Signal/Provisioning/ProvisioningCoordinator+Shims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class _ProvisioningCoordinator_MessageFactoryWrapper: _ProvisioningCoordi

public protocol _ProvisioningCoordinator_ProfileManagerShim {

func localProfileKey() -> Aes256Key
func localUserProfile(tx: DBReadTransaction) -> OWSUserProfile?

func setLocalProfileKey(
_ key: Aes256Key,
Expand All @@ -71,8 +71,8 @@ public class _ProvisioningCoordinator_ProfileManagerWrapper: _ProvisioningCoordi
self.profileManager = profileManager
}

public func localProfileKey() -> Aes256Key {
return profileManager.localProfileKey
public func localUserProfile(tx: DBReadTransaction) -> OWSUserProfile? {
return profileManager.localUserProfile(tx: SDSDB.shimOnlyBridge(tx))
}

public func setLocalProfileKey(
Expand Down
8 changes: 1 addition & 7 deletions Signal/Provisioning/ProvisioningCoordinatorImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,7 @@ class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
// TODO: can we change this with atomic device linking?
let isManualMessageFetchEnabled = true

let udAccessKey: String
do {
udAccessKey = try SMKUDAccessKey(profileKey: profileKey.keyData).keyData.base64EncodedString()
} catch {
// Crash app if UD cannot be enabled.
owsFail("Could not determine UD access key: \(error).")
}
let udAccessKey = SMKUDAccessKey(profileKey: profileKey).keyData.base64EncodedString()
let allowUnrestrictedUD = udManager.shouldAllowUnrestrictedAccessLocal(tx: tx)

// Historical note: secondary device registration uses the same AccountAttributes object,
Expand Down
9 changes: 4 additions & 5 deletions Signal/Registration/RegistrationCoodinatorShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@ public class _RegistrationCoordinator_PreKeyManagerWrapper: _RegistrationCoordin

public protocol _RegistrationCoordinator_ProfileManagerShim {

var hasProfileName: Bool { get }
func localUserProfile(tx: DBReadTransaction) -> OWSUserProfile?

// NOTE: non-optional because OWSProfileManager generates a random key
// if one doesn't already exist.
var localProfileKey: Aes256Key { get }

func updateLocalProfile(
givenName: OWSUserProfile.NameComponent,
Expand All @@ -297,9 +296,9 @@ public class _RegistrationCoordinator_ProfileManagerWrapper: _RegistrationCoordi
private let manager: ProfileManager
public init(_ manager: ProfileManager) { self.manager = manager }

public var hasProfileName: Bool { manager.hasProfileName }

public var localProfileKey: Aes256Key { manager.localProfileKey }
public func localUserProfile(tx: DBReadTransaction) -> OWSUserProfile? {
return manager.localUserProfile(tx: SDSDB.shimOnlyBridge(tx))
}

public func updateLocalProfile(
givenName: OWSUserProfile.NameComponent,
Expand Down
Loading

0 comments on commit b7dedf2

Please sign in to comment.