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