pull/352/head
Niels Andriesse 4 years ago
parent 646910d115
commit f6ced55003

@ -134,14 +134,29 @@ final class LinkDeviceVC : BaseVC, UIPageViewControllerDataSource, UIPageViewCon
}
}
@objc private func handleConfigurationMessageReceived() {
@objc private func handleConfigurationMessageReceived(_ notification: Notification) {
guard let profile = notification.object as? [String:Any?], let displayName = profile["displayName"] as? String else { return }
let profilePictureURL = profile["profilePictureURL"] as? String
let profileKeyAsData = profile["profileKey"] as? NSData
let profileKey = given(profileKeyAsData) { OWSAES256Key(data: $0 as Data)! }
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
DispatchQueue.main.async {
self.navigationController!.dismiss(animated: true) {
let pnModeVC = PNModeVC()
self.navigationController!.setViewControllers([ pnModeVC ], animated: true)
let profileManager = OWSProfileManager.shared()
var userProfile: OWSUserProfile!
Storage.write(with: { transaction in
userProfile = profileManager.getLocalUserProfile(with: transaction)
userProfile.profileName = displayName
userProfile.avatarUrlPath = profilePictureURL
userProfile.profileKey = profileKey
userProfile.save(with: transaction)
}, completion: {
profileManager.downloadAvatar(for: userProfile)
DispatchQueue.main.async {
self.navigationController!.dismiss(animated: true) {
let pnModeVC = PNModeVC()
self.navigationController!.setViewControllers([ pnModeVC ], animated: true)
}
}
}
})
}
}

@ -145,22 +145,10 @@ extension MessageReceiver {
private static func handleConfigurationMessage(_ message: ConfigurationMessage, using transaction: Any) {
guard message.sender == getUserHexEncodedPublicKey(), !UserDefaults.standard[.hasSyncedConfiguration] else { return }
let storage = SNMessagingKitConfiguration.shared.storage
let profileManager = SSKEnvironment.shared.profileManager
// Profile
let sessionID = getUserHexEncodedPublicKey()
let contact = Storage.shared.getContact(with: sessionID) ?? Contact(sessionID: sessionID)
if let displayName = message.displayName {
profileManager.updateProfileForContact(withID: sessionID, displayName: displayName, with: transaction as! YapDatabaseReadWriteTransaction)
contact.displayName = displayName
}
if let profileKey = message.profileKey, let profilePictureURL = message.profilePictureURL, profileKey.count == kAES256_KeyByteLength {
profileManager.setProfileKeyData(profileKey, forRecipientId: sessionID, avatarURL: profilePictureURL)
contact.profilePictureURL = profilePictureURL
contact.profilePictureEncryptionKey = OWSAES256Key(data: profileKey)
}
// Notification
UserDefaults.standard[.hasSyncedConfiguration] = true
NotificationCenter.default.post(name: .configurationMessageReceived, object: nil)
let profile: [String:Any?] = [ "displayName" : message.displayName, "profilePictureURL" : message.profilePictureURL, "profileKey" : message.profileKey ]
NotificationCenter.default.post(name: .configurationMessageReceived, object: profile)
// Closed groups
let allClosedGroupPublicKeys = storage.getUserClosedGroupPublicKeys()
for closedGroup in message.closedGroups {

@ -26,9 +26,9 @@ extern NSString *const kLocalProfileUniqueId;
@interface OWSUserProfile : TSYapDatabaseObject
@property (atomic, readonly) NSString *recipientId;
@property (atomic, readonly, nullable) OWSAES256Key *profileKey;
@property (atomic, readonly, nullable) NSString *profileName;
@property (atomic, readonly, nullable) NSString *avatarUrlPath;
@property (atomic, nullable) OWSAES256Key *profileKey;
@property (atomic, nullable) NSString *profileName;
@property (atomic, nullable) NSString *avatarUrlPath;
// This filename is relative to OWSProfileManager.profileAvatarsDirPath.
@property (atomic, readonly, nullable) NSString *avatarFileName;

@ -29,9 +29,6 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
@interface OWSUserProfile ()
@property (atomic, nullable) OWSAES256Key *profileKey;
@property (atomic, nullable) NSString *profileName;
@property (atomic, nullable) NSString *avatarUrlPath;
@property (atomic, nullable) NSString *avatarFileName;
@end

@ -4,7 +4,7 @@ extension ConfigurationMessage {
public static func getCurrent() -> ConfigurationMessage {
let storage = Storage.shared
let displayName = storage.getUserDisplayName()!
let profilePictureURL = storage.getUserProfilePictureURL()
let profilePictureURL = SSKEnvironment.shared.profileManager.profilePictureURL()
let profileKey = storage.getUserProfileKey()
var closedGroups: Set<ClosedGroup> = []
var openGroups: Set<String> = []

@ -93,6 +93,10 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
fromViewController:(UIViewController *)fromViewController
success:(void (^)(void))successHandler;
#pragma mark - Other
- (void)downloadAvatarForUserProfile:(OWSUserProfile *)userProfile;
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save