pull/101/head
Niels Andriesse 5 years ago
parent 067a31bb79
commit f3a77222ab

@ -5,15 +5,11 @@
<key>BuildDetails</key>
<dict>
<key>CarthageVersion</key>
<string>0.33.0</string>
<key>DateTime</key>
<string>Tue Feb 11 02:41:14 UTC 2020</string>
<string>0.34.0</string>
<key>OSXVersion</key>
<string>10.15.3</string>
<key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
<key>XCodeVersion</key>
<string>1100.1130</string>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>

@ -137,6 +137,8 @@ internal extension Promise {
LokiAPI.randomSnodePool.remove(target) // Remove it from the random snode pool
LokiAPI.failureCount[target] = 0
}
case 406:
break // TODO: Handle clock out of sync
case 421:
// The snode isn't associated with the given public key anymore
print("[Loki] Invalidating swarm for: \(hexEncodedPublicKey).")

@ -97,11 +97,11 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
print("[Loki] Couldn't parse message for public chat channel with ID: \(channel) on server: \(server) from: \(message).")
return nil
}
var avatar: LokiPublicChatMessage.Avatar? = nil
var profilePicture: LokiPublicChatMessage.ProfilePicture? = nil
let displayName = user["name"] as? String ?? NSLocalizedString("Anonymous", comment: "")
if let userAnnotations = user["annotations"] as? [JSON], let avatarAnnotation = userAnnotations.first(where: { $0["type"] as? String == profilePictureType }),
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)
if let userAnnotations = user["annotations"] as? [JSON], let profilePictureAnnotation = userAnnotations.first(where: { $0["type"] as? String == profilePictureType }),
let profilePictureValue = profilePictureAnnotation["value"] as? JSON, let profileKeyString = profilePictureValue["profileKey"] as? String, let profileKey = Data(base64Encoded: profileKeyString), let url = profilePictureValue["url"] as? String {
profilePicture = LokiPublicChatMessage.ProfilePicture(profileKey: profileKey, url: url)
}
let lastMessageServerID = getLastMessageServerID(for: channel, on: server)
if serverID > (lastMessageServerID ?? 0) { setLastMessageServerID(for: channel, on: server, to: serverID) }
@ -135,7 +135,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
return LokiPublicChatMessage.Attachment(kind: kind, server: server, serverID: serverID, contentType: contentType, size: size, fileName: fileName, flags: flags,
width: width, height: height, caption: caption, url: url, linkPreviewURL: linkPreviewURL, linkPreviewTitle: linkPreviewTitle)
}
let result = LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, avatar: avatar,
let result = LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, profilePicture: profilePicture,
body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature)
guard result.hasValidSignature() else {
print("[Loki] Ignoring public chat message with invalid signature.")
@ -173,7 +173,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
throw Error.parsingFailed
}
let timestamp = UInt64(date.timeIntervalSince1970) * 1000
return LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: userHexEncodedPublicKey, displayName: displayName, avatar: signedMessage.avatar, body: body, type: publicChatMessageType, timestamp: timestamp, quote: signedMessage.quote, attachments: signedMessage.attachments, signature: signedMessage.signature)
return LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: userHexEncodedPublicKey, displayName: displayName, profilePicture: signedMessage.profilePicture, body: body, type: publicChatMessageType, timestamp: timestamp, quote: signedMessage.quote, attachments: signedMessage.attachments, signature: signedMessage.signature)
}
}.recover(on: DispatchQueue.global()) { error -> Promise<LokiPublicChatMessage> in
if let error = error as? NetworkManagerError, error.statusCode == 401 {

@ -5,7 +5,7 @@ public final class LokiPublicChatMessage : NSObject {
public let serverID: UInt64?
public let hexEncodedPublicKey: String
public let displayName: String
public let avatar: Avatar?
public let profilePicture: ProfilePicture?
public let body: String
/// - Note: Expressed as milliseconds since 00:00:00 UTC on 1 January 1970.
public let timestamp: UInt64
@ -22,7 +22,7 @@ public final class LokiPublicChatMessage : NSObject {
private let attachmentType = "net.app.core.oembed"
// MARK: Types
public struct Avatar {
public struct ProfilePicture {
public let profileKey: Data
public let url: String
}
@ -72,11 +72,11 @@ public final class LokiPublicChatMessage : NSObject {
}
// MARK: Initialization
public init(serverID: UInt64?, hexEncodedPublicKey: String, displayName: String, avatar: Avatar?, body: String, type: String, timestamp: UInt64, quote: Quote?, attachments: [Attachment], signature: Signature?) {
public init(serverID: UInt64?, hexEncodedPublicKey: String, displayName: String, profilePicture: ProfilePicture?, body: String, type: String, timestamp: UInt64, quote: Quote?, attachments: [Attachment], signature: Signature?) {
self.serverID = serverID
self.hexEncodedPublicKey = hexEncodedPublicKey
self.displayName = displayName
self.avatar = avatar
self.profilePicture = profilePicture
self.body = body
self.type = type
self.timestamp = timestamp
@ -100,7 +100,7 @@ public final class LokiPublicChatMessage : NSObject {
} else {
signature = nil
}
self.init(serverID: nil, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, avatar: nil, body: body, type: type, timestamp: timestamp, quote: quote, attachments: [], signature: signature)
self.init(serverID: nil, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, profilePicture: nil, body: body, type: type, timestamp: timestamp, quote: quote, attachments: [], signature: signature)
}
// MARK: Crypto
@ -115,7 +115,7 @@ public final class LokiPublicChatMessage : NSObject {
return nil
}
let signature = Signature(data: signatureData, version: signatureVersion)
return LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, avatar: avatar, body: body, type: type, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature)
return LokiPublicChatMessage(serverID: serverID, hexEncodedPublicKey: hexEncodedPublicKey, displayName: displayName, profilePicture: profilePicture, body: body, type: type, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature)
}
internal func hasValidSignature() -> Bool {
@ -135,8 +135,8 @@ public final class LokiPublicChatMessage : NSObject {
value["sig"] = signature.data.toHexString()
value["sigver"] = signature.version
}
if let avatar = avatar {
value["avatar"] = avatar;
if let profilePicture = profilePicture {
value["avatar"] = profilePicture;
}
let annotation: JSON = [ "type" : type, "value" : value ]
let attachmentAnnotations: [JSON] = attachments.map { attachment in

@ -1,7 +1,5 @@
import PromiseKit
// TODO: Move away from polling
@objc(LKPublicChatPoller)
public final class LokiPublicChatPoller : NSObject {
private let publicChat: LokiPublicChat
@ -129,9 +127,9 @@ public final class LokiPublicChatPoller : NSObject {
}
let profile = SSKProtoDataMessageLokiProfile.builder()
profile.setDisplayName(message.displayName)
if let avatar = message.avatar {
profile.setProfilePicture(avatar.url)
dataMessage.setProfileKey(avatar.profileKey)
if let profilePicture = message.profilePicture {
profile.setProfilePicture(profilePicture.url)
dataMessage.setProfileKey(profilePicture.profileKey)
}
dataMessage.setProfile(try! profile.build())
dataMessage.setTimestamp(message.timestamp)
@ -170,12 +168,12 @@ public final class LokiPublicChatPoller : NSObject {
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 master device then we should use its profile picture
if let avatar = message.avatar, masterHexEncodedPublicKey == message.hexEncodedPublicKey {
if let profilePicture = message.profilePicture, masterHexEncodedPublicKey == message.hexEncodedPublicKey {
if (message.displayName.count > 0) {
SSKEnvironment.shared.profileManager.updateProfileForContact(withID: masterHexEncodedPublicKey!, displayName: message.displayName, with: transaction)
}
SSKEnvironment.shared.profileManager.updateService(withProfileName: message.displayName, avatarUrl: avatar.url)
SSKEnvironment.shared.profileManager.setProfileKeyData(avatar.profileKey, forRecipientId: masterHexEncodedPublicKey!, avatarURL: avatar.url)
SSKEnvironment.shared.profileManager.updateService(withProfileName: message.displayName, avatarUrl: profilePicture.url)
SSKEnvironment.shared.profileManager.setProfileKeyData(profilePicture.profileKey, forRecipientId: masterHexEncodedPublicKey!, avatarURL: profilePicture.url)
}
}
}

@ -10,9 +10,7 @@
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
}
- (BOOL)shouldBeSaved {
return NO;
}
- (BOOL)shouldBeSaved { return NO; }
#pragma mark Building
- (nullable SSKProtoDataMessageBuilder *)dataMessageBuilder

Loading…
Cancel
Save