Clean
This commit is contained in:
parent
2b8e74348a
commit
ce33d472eb
|
@ -454,7 +454,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
|
||||
for (NSString *server in servers) {
|
||||
[[LKPublicChatAPI setDisplayName:localProfileName on:server] retainUntilComplete];
|
||||
[[LKPublicChatAPI setAvatar:avatarURL profileKey:self.localProfileKey.keyData on:server] retainUntilComplete];
|
||||
[[LKPublicChatAPI setProfilePictureURL:avatarURL usingProfileKey:self.localProfileKey.keyData on:server] retainUntilComplete];
|
||||
}
|
||||
|
||||
successBlock();
|
||||
|
|
|
@ -101,8 +101,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
}
|
||||
var avatar: LokiPublicChatMessage.Avatar? = nil
|
||||
let displayName = user["name"] as? String ?? NSLocalizedString("Anonymous", comment: "")
|
||||
if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnoration = userAnnotations.first(where: { $0["type"] as? String == avatarType }),
|
||||
let avatarValue = avatarAnnoration["value"] as? JSON, let profileKeyString = avatarValue["profileKey"] as? String, let profileKey = Data(base64Encoded: profileKeyString), let url = avatarValue["url"] as? String {
|
||||
if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnotation = userAnnotations.first(where: { $0["type"] as? String == avatarType }),
|
||||
let avatarValue = avatarAnnotation["value"] as? JSON, let profileKeyString = avatarValue["profileKey"] as? String, let profileKey = Data(base64Encoded: profileKeyString), let url = avatarValue["url"] as? String {
|
||||
avatar = LokiPublicChatMessage.Avatar(profileKey: profileKey, url: url)
|
||||
}
|
||||
let lastMessageServerID = getLastMessageServerID(for: channel, on: server)
|
||||
|
@ -292,19 +292,19 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
}.retryingIfNeeded(maxRetryCount: 3)
|
||||
}
|
||||
|
||||
public static func setAvatar(with url: String?, profileKey: Data, on server: String) -> Promise<Void> {
|
||||
print("[Loki] Updating avatar on server: \(server).")
|
||||
public static func setProfilePictureURL(to url: String?, using profileKey: Data, on server: String) -> Promise<Void> {
|
||||
print("[Loki] Updating profile picture on server: \(server).")
|
||||
return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise<Void> in
|
||||
var annotation: JSON = ["type" : avatarType]
|
||||
var annotation: JSON = [ "type" : avatarType ]
|
||||
if let url = url {
|
||||
annotation["value"] = ["profileKey": profileKey.base64EncodedString(), "url" : url]
|
||||
annotation["value"] = [ "profileKey" : profileKey.base64EncodedString(), "url" : url ]
|
||||
}
|
||||
let parameters: JSON = [ "annotations" : [annotation] ]
|
||||
let parameters: JSON = [ "annotations" : [ annotation ] ]
|
||||
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().perform(request, withCompletionQueue: DispatchQueue.global()).map { _ in }.recover(on: DispatchQueue.global()) { error in
|
||||
print("Couldn't update avatar due to error: \(error).")
|
||||
print("[Loki] Couldn't update profile picture due to error: \(error).")
|
||||
throw error
|
||||
}
|
||||
}.retryingIfNeeded(maxRetryCount: 3)
|
||||
|
@ -353,8 +353,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
return AnyPromise.from(setDisplayName(to: newDisplayName, on: server))
|
||||
}
|
||||
|
||||
@objc(setAvatar:profileKey:on:)
|
||||
public static func objc_setAvatar(with url: String?, profileKey: Data, on server: String) -> AnyPromise {
|
||||
return AnyPromise.from(setAvatar(with: url, profileKey: profileKey, on: server))
|
||||
@objc(setProfilePictureURL:usingProfileKey:on:)
|
||||
public static func objc_setProfilePicture(to url: String?, using profileKey: Data, on server: String) -> AnyPromise {
|
||||
return AnyPromise.from(setProfilePictureURL(to: url, using: profileKey, on: server))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,8 +163,7 @@ public final class LokiPublicChatPoller : NSObject {
|
|||
transaction.setObject(senderDisplayName, forKey: senderHexEncodedPublicKey, inCollection: publicChat.id)
|
||||
let messageServerID = message.serverID
|
||||
SSKEnvironment.shared.messageManager.throws_processEnvelope(try! envelope.build(), plaintextData: try! content.build().serializedData(), wasReceivedByUD: false, transaction: transaction, serverID: messageServerID ?? 0)
|
||||
|
||||
// If we got a message from our primary device then we should use its avatar
|
||||
// If we got a message from our master device then we should use its profile picture
|
||||
if let avatar = message.avatar, masterHexEncodedPublicKey == message.hexEncodedPublicKey {
|
||||
if (message.displayName.count > 0) {
|
||||
SSKEnvironment.shared.profileManager.updateProfileForContact(withID: masterHexEncodedPublicKey!, displayName: message.displayName, with: transaction)
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
- (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient {
|
||||
SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder;
|
||||
NSError *error;
|
||||
// Build the pre key bundle message
|
||||
if (self.kind == LKDeviceLinkMessageKindRequest) {
|
||||
// Build the pre key bundle message
|
||||
PreKeyBundle *preKeyBundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId];
|
||||
SSKProtoPrekeyBundleMessageBuilder *preKeyBundleMessageBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:preKeyBundle];
|
||||
SSKProtoPrekeyBundleMessage *preKeyBundleMessage = [preKeyBundleMessageBuilder buildAndReturnError:&error];
|
||||
|
@ -49,7 +49,7 @@
|
|||
[contentBuilder setPrekeyBundleMessage:preKeyBundleMessage];
|
||||
}
|
||||
} else {
|
||||
// Loki: Set display name & profile picture
|
||||
// Set display name & profile picture
|
||||
id<ProfileManagerProtocol> profileManager = SSKEnvironment.shared.profileManager;
|
||||
NSString *displayName = profileManager.localProfileName;
|
||||
NSString *profilePictureURL = profileManager.profilePictureURL;
|
||||
|
|
|
@ -465,8 +465,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (masterSignature != nil) { // Authorization
|
||||
OWSLogInfo(@"[Loki] Received a device linking authorization from: %@", envelope.source); // Not masterHexEncodedPublicKey
|
||||
[LKDeviceLinkingSession.current processLinkingAuthorizationFrom:masterHexEncodedPublicKey for:slaveHexEncodedPublicKey masterSignature:masterSignature slaveSignature:slaveSignature];
|
||||
|
||||
// Set any profile information
|
||||
// Set any profile info
|
||||
if (contentProto.dataMessage) {
|
||||
SSKProtoDataMessage *dataMessage = contentProto.dataMessage;
|
||||
[self handleProfileNameUpdateIfNeeded:dataMessage recipientId:masterHexEncodedPublicKey transaction:transaction];
|
||||
|
|
Loading…
Reference in New Issue