diff --git a/Signal/src/Loki/Onboarding/DisplayNameVC.swift b/Signal/src/Loki/Onboarding/DisplayNameVC.swift index 6efbf3721..7c96c2581 100644 --- a/Signal/src/Loki/Onboarding/DisplayNameVC.swift +++ b/Signal/src/Loki/Onboarding/DisplayNameVC.swift @@ -63,10 +63,12 @@ final class DisplayNameVC : OnboardingBaseViewController { guard !OWSProfileManager.shared().isProfileNameTooLong(normalizedName) else { return OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long")) } - OWSProfileManager.shared().updateLocalProfileName(normalizedUserName, avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result } TSAccountManager.sharedInstance().didRegister() UserDefaults.standard.set(true, forKey: "didUpdateForMainnet") onboardingController.verificationDidComplete(fromView: self) + if let normalizedName = normalizedUserName { + OWSProfileManager.shared().updateLocalProfileName(normalizedName, avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result + } } } diff --git a/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m b/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m index 498191187..2d06fb1cb 100644 --- a/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m +++ b/Signal/src/ViewControllers/AppSettings/OWSQRCodeScanningViewController.m @@ -59,20 +59,20 @@ NS_ASSUME_NONNULL_BEGIN [maskingView setConfigureShapeLayerBlock:^(CAShapeLayer *layer, CGRect bounds) { // Add a circular mask UIBezierPath *path = [UIBezierPath bezierPathWithRect:bounds]; - CGFloat margin = ScaleFromIPhone5To7Plus(8.f, 16.f); + CGFloat margin = ScaleFromIPhone5To7Plus(24.f, 48.f); CGFloat radius = MIN(bounds.size.width, bounds.size.height) * 0.5f - margin; // Center the circle's bounding rectangle CGRect circleRect = CGRectMake( bounds.size.width * 0.5f - radius, bounds.size.height * 0.5f - radius, radius * 2.f, radius * 2.f); - UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:circleRect cornerRadius:radius]; + UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:circleRect cornerRadius:16.f]; [path appendPath:circlePath]; [path setUsesEvenOddFillRule:YES]; layer.path = path.CGPath; layer.fillRule = kCAFillRuleEvenOdd; - layer.fillColor = [UIColor grayColor].CGColor; - layer.opacity = 0.5f; + layer.fillColor = UIColor.lokiDarkestGray.CGColor; + layer.opacity = 0.32f; }]; [self.view addSubview:maskingView]; [maskingView ows_autoPinToSuperviewEdges]; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 06cc09b1e..e983cc1c1 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -534,25 +534,14 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); failure:(ProfileManagerFailureBlock)failureBlock { OWSAssertDebug(successBlock); OWSAssertDebug(failureBlock); - - // Loki: We don't need to make any server calls so succeed automatically - successBlock(); - - /* ============ Original code ============ - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSData *_Nullable encryptedPaddedName = [self encryptProfileNameWithUnpaddedName:localProfileName]; - TSRequest *request = [OWSRequestBuilder profileNameSetRequestWithEncryptedPaddedName:encryptedPaddedName]; - [self.networkManager makeRequest:request - success:^(NSURLSessionDataTask *task, id responseObject) { - successBlock(); - } - failure:^(NSURLSessionDataTask *task, NSError *error) { - OWSLogError(@"Failed to update profile with error: %@", error); - failureBlock(error); - }]; - }); - */ + [[LKGroupChatAPI setDisplayName:localProfileName on:LKGroupChatAPI.publicChatServer] + .thenOn(dispatch_get_main_queue(), ^() { + successBlock(); + }) + .catchOn(dispatch_get_main_queue(), ^(NSError *error) { + failureBlock(error); + }) retainUntilComplete]; } - (void)fetchLocalUsersProfile diff --git a/SignalServiceKit/src/Loki/API/Group Chat/LokiGroupChatAPI.swift b/SignalServiceKit/src/Loki/API/Group Chat/LokiGroupChatAPI.swift index dd7d5313e..9eeadcfd7 100644 --- a/SignalServiceKit/src/Loki/API/Group Chat/LokiGroupChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/Group Chat/LokiGroupChatAPI.swift @@ -202,6 +202,20 @@ public final class LokiGroupChatAPI : LokiDotNetAPI { return moderators[server]?[group]?.contains(hexEncodedPublicString) ?? false } + public static func setDisplayName(to newDisplayName: String?, on server: String) -> Promise { + print("[Loki] Updating display name on server: \(server).") + return getAuthToken(for: server).then { token -> Promise in + let parameters: JSON = [ "name" : newDisplayName ] + let url = URL(string: "\(server)/users/me")! + let request = TSRequest(url: url, method: "PATCH", parameters: parameters) + request.allHTTPHeaderFields = [ "Content-Type" : "application/json", "Authorization" : "Bearer \(token)" ] + return TSNetworkManager.shared().makePromise(request: request).map { _ in }.recover { error in + print("Couldn't update display name due to error: \(error).") + throw error + } + } + } + // MARK: Public API (Obj-C) @objc(getMessagesForGroup:onServer:) public static func objc_getMessages(for group: UInt64, on server: String) -> AnyPromise { @@ -213,8 +227,13 @@ public final class LokiGroupChatAPI : LokiDotNetAPI { return AnyPromise.from(sendMessage(message, to: group, on: server)) } - @objc (deleteMessageWithID:forGroup:onServer:isSentByUser:) + @objc(deleteMessageWithID:forGroup:onServer:isSentByUser:) public static func objc_deleteMessage(with messageID: UInt, for group: UInt64, on server: String, isSentByUser: Bool) -> AnyPromise { return AnyPromise.from(deleteMessage(with: messageID, for: group, on: server, isSentByUser: isSentByUser)) } + + @objc(setDisplayName:on:) + public static func objc_setDisplayName(to newDisplayName: String?, on server: String) -> AnyPromise { + return AnyPromise.from(setDisplayName(to: newDisplayName, on: server)) + } } diff --git a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift index 5b6ffc105..08a9c4065 100644 --- a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift @@ -123,6 +123,5 @@ public final class LokiStorageAPI : LokiDotNetAPI { throw error } } - } }