pull/69/head
Niels Andriesse 6 years ago
parent 2b8e74348a
commit ce33d472eb

@ -454,7 +454,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
for (NSString *server in servers) { for (NSString *server in servers) {
[[LKPublicChatAPI setDisplayName:localProfileName on:server] retainUntilComplete]; [[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(); successBlock();

@ -101,8 +101,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
} }
var avatar: LokiPublicChatMessage.Avatar? = nil var avatar: LokiPublicChatMessage.Avatar? = nil
let displayName = user["name"] as? String ?? NSLocalizedString("Anonymous", comment: "") 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 }), if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnotation = 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 { 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) avatar = LokiPublicChatMessage.Avatar(profileKey: profileKey, url: url)
} }
let lastMessageServerID = getLastMessageServerID(for: channel, on: server) let lastMessageServerID = getLastMessageServerID(for: channel, on: server)
@ -292,19 +292,19 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
}.retryingIfNeeded(maxRetryCount: 3) }.retryingIfNeeded(maxRetryCount: 3)
} }
public static func setAvatar(with url: String?, profileKey: Data, on server: String) -> Promise<Void> { public static func setProfilePictureURL(to url: String?, using profileKey: Data, on server: String) -> Promise<Void> {
print("[Loki] Updating avatar on server: \(server).") print("[Loki] Updating profile picture on server: \(server).")
return getAuthToken(for: server).then(on: DispatchQueue.global()) { token -> Promise<Void> in 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 { 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 url = URL(string: "\(server)/users/me")!
let request = TSRequest(url: url, method: "PATCH", parameters: parameters) let request = TSRequest(url: url, method: "PATCH", parameters: parameters)
request.allHTTPHeaderFields = [ "Content-Type" : "application/json", "Authorization" : "Bearer \(token)" ] 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 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 throw error
} }
}.retryingIfNeeded(maxRetryCount: 3) }.retryingIfNeeded(maxRetryCount: 3)
@ -353,8 +353,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
return AnyPromise.from(setDisplayName(to: newDisplayName, on: server)) return AnyPromise.from(setDisplayName(to: newDisplayName, on: server))
} }
@objc(setAvatar:profileKey:on:) @objc(setProfilePictureURL:usingProfileKey:on:)
public static func objc_setAvatar(with url: String?, profileKey: Data, on server: String) -> AnyPromise { public static func objc_setProfilePicture(to url: String?, using profileKey: Data, on server: String) -> AnyPromise {
return AnyPromise.from(setAvatar(with: url, profileKey: profileKey, on: server)) 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) transaction.setObject(senderDisplayName, forKey: senderHexEncodedPublicKey, inCollection: publicChat.id)
let messageServerID = message.serverID let messageServerID = message.serverID
SSKEnvironment.shared.messageManager.throws_processEnvelope(try! envelope.build(), plaintextData: try! content.build().serializedData(), wasReceivedByUD: false, transaction: transaction, serverID: messageServerID ?? 0) 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 master device then we should use its profile picture
// If we got a message from our primary device then we should use its avatar
if let avatar = message.avatar, masterHexEncodedPublicKey == message.hexEncodedPublicKey { if let avatar = message.avatar, masterHexEncodedPublicKey == message.hexEncodedPublicKey {
if (message.displayName.count > 0) { if (message.displayName.count > 0) {
SSKEnvironment.shared.profileManager.updateProfileForContact(withID: masterHexEncodedPublicKey!, displayName: message.displayName, with: transaction) SSKEnvironment.shared.profileManager.updateProfileForContact(withID: masterHexEncodedPublicKey!, displayName: message.displayName, with: transaction)

@ -37,8 +37,8 @@
- (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient { - (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient {
SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder; SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder;
NSError *error; NSError *error;
// Build the pre key bundle message
if (self.kind == LKDeviceLinkMessageKindRequest) { if (self.kind == LKDeviceLinkMessageKindRequest) {
// Build the pre key bundle message
PreKeyBundle *preKeyBundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId]; PreKeyBundle *preKeyBundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId];
SSKProtoPrekeyBundleMessageBuilder *preKeyBundleMessageBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:preKeyBundle]; SSKProtoPrekeyBundleMessageBuilder *preKeyBundleMessageBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:preKeyBundle];
SSKProtoPrekeyBundleMessage *preKeyBundleMessage = [preKeyBundleMessageBuilder buildAndReturnError:&error]; SSKProtoPrekeyBundleMessage *preKeyBundleMessage = [preKeyBundleMessageBuilder buildAndReturnError:&error];
@ -49,7 +49,7 @@
[contentBuilder setPrekeyBundleMessage:preKeyBundleMessage]; [contentBuilder setPrekeyBundleMessage:preKeyBundleMessage];
} }
} else { } else {
// Loki: Set display name & profile picture // Set display name & profile picture
id<ProfileManagerProtocol> profileManager = SSKEnvironment.shared.profileManager; id<ProfileManagerProtocol> profileManager = SSKEnvironment.shared.profileManager;
NSString *displayName = profileManager.localProfileName; NSString *displayName = profileManager.localProfileName;
NSString *profilePictureURL = profileManager.profilePictureURL; NSString *profilePictureURL = profileManager.profilePictureURL;

@ -465,8 +465,7 @@ NS_ASSUME_NONNULL_BEGIN
if (masterSignature != nil) { // Authorization if (masterSignature != nil) { // Authorization
OWSLogInfo(@"[Loki] Received a device linking authorization from: %@", envelope.source); // Not masterHexEncodedPublicKey OWSLogInfo(@"[Loki] Received a device linking authorization from: %@", envelope.source); // Not masterHexEncodedPublicKey
[LKDeviceLinkingSession.current processLinkingAuthorizationFrom:masterHexEncodedPublicKey for:slaveHexEncodedPublicKey masterSignature:masterSignature slaveSignature:slaveSignature]; [LKDeviceLinkingSession.current processLinkingAuthorizationFrom:masterHexEncodedPublicKey for:slaveHexEncodedPublicKey masterSignature:masterSignature slaveSignature:slaveSignature];
// Set any profile info
// Set any profile information
if (contentProto.dataMessage) { if (contentProto.dataMessage) {
SSKProtoDataMessage *dataMessage = contentProto.dataMessage; SSKProtoDataMessage *dataMessage = contentProto.dataMessage;
[self handleProfileNameUpdateIfNeeded:dataMessage recipientId:masterHexEncodedPublicKey transaction:transaction]; [self handleProfileNameUpdateIfNeeded:dataMessage recipientId:masterHexEncodedPublicKey transaction:transaction];

Loading…
Cancel
Save