mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Update for new username API
This commit is contained in:
parent
8253871047
commit
b7d3c1da04
5 changed files with 34 additions and 25 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -535,24 +535,13 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
OWSAssertDebug(successBlock);
|
||||
OWSAssertDebug(failureBlock);
|
||||
|
||||
// Loki: We don't need to make any server calls so succeed automatically
|
||||
[[LKGroupChatAPI setDisplayName:localProfileName on:LKGroupChatAPI.publicChatServer]
|
||||
.thenOn(dispatch_get_main_queue(), ^() {
|
||||
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);
|
||||
})
|
||||
.catchOn(dispatch_get_main_queue(), ^(NSError *error) {
|
||||
failureBlock(error);
|
||||
}];
|
||||
});
|
||||
*/
|
||||
}) retainUntilComplete];
|
||||
}
|
||||
|
||||
- (void)fetchLocalUsersProfile
|
||||
|
|
|
@ -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<Void> {
|
||||
print("[Loki] Updating display name on server: \(server).")
|
||||
return getAuthToken(for: server).then { token -> Promise<Void> 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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,5 @@ public final class LokiStorageAPI : LokiDotNetAPI {
|
|||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue