|
|
|
@ -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
|
|
|
|
|