Minor refactoring

pull/254/head
nielsandriesse 5 years ago
parent 57d8d9bc69
commit 833b8aa18a

@ -131,7 +131,7 @@ public final class PublicChatAPI : DotNetAPI {
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
} }
let servertTimestamp = UInt64(date.timeIntervalSince1970) * 1000 let serverTimestamp = UInt64(date.timeIntervalSince1970) * 1000
var profilePicture: PublicChatMessage.ProfilePicture? = nil var profilePicture: PublicChatMessage.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 profilePictureAnnotation = 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 }),
@ -171,7 +171,7 @@ public final class PublicChatAPI : DotNetAPI {
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 = PublicChatMessage(serverID: serverID, senderPublicKey: hexEncodedPublicKey, displayName: displayName, profilePicture: profilePicture, let result = PublicChatMessage(serverID: serverID, senderPublicKey: hexEncodedPublicKey, displayName: displayName, profilePicture: profilePicture,
body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature, serverTimestamp: servertTimestamp) body: body, type: publicChatMessageType, timestamp: timestamp, quote: quote, attachments: attachments, signature: signature, serverTimestamp: serverTimestamp)
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.")
return nil return nil

@ -13,8 +13,7 @@ public final class PublicChatMessage : NSObject {
public let quote: Quote? public let quote: Quote?
public var attachments: [Attachment] = [] public var attachments: [Attachment] = []
public let signature: Signature? public let signature: Signature?
/// - Note: Used for sorting.
// MARK: Server Timestamp (use for sorting)
public let serverTimestamp: UInt64 public let serverTimestamp: UInt64
@objc(serverID) @objc(serverID)

@ -189,14 +189,13 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value)
{ {
OWSAssertDebug(other); OWSAssertDebug(other);
// Loki: Sort the messages by the sender's timestamp (Signal uses sortId) // Sort the messages by the sender's timestamp (Signal uses sortId)
uint64_t sortId1 = self.timestamp; uint64_t sortId1 = self.timestamp;
uint64_t sortId2 = other.timestamp; uint64_t sortId2 = other.timestamp;
// Loki: In open groups, we use the server time to sort the messages // In open groups messages should be sorted by their server timestamp. `sortId` represents the order in which messages
// SortId represents the order that a message is processed // were processed. Since in the open group poller we sort messages by their server timestamp, sorting by `sortId` is
// Since we have sorted the messages in the poller using server time // effectively the same as sorting by server timestamp.
// SortId can represent the order by server time.
if (self.thread.isGroupThread) { if (self.thread.isGroupThread) {
TSGroupThread *thread = (TSGroupThread *)self.thread; TSGroupThread *thread = (TSGroupThread *)self.thread;
if (thread.isPublicChat) { if (thread.isPublicChat) {

Loading…
Cancel
Save