|
|
|
@ -292,10 +292,10 @@ public extension Message {
|
|
|
|
|
dependencies: SMKDependencies = SMKDependencies()
|
|
|
|
|
) throws -> ProcessedMessage? {
|
|
|
|
|
// Need a sender in order to process the message
|
|
|
|
|
guard let sender: String = message.sender else { return nil }
|
|
|
|
|
guard let sender: String = message.sender, let timestamp = message.posted else { return nil }
|
|
|
|
|
|
|
|
|
|
// Note: The `posted` value is in seconds but all messages in the database use milliseconds for timestamps
|
|
|
|
|
let envelopeBuilder = SNProtoEnvelope.builder(type: .sessionMessage, timestamp: UInt64(floor(message.posted * 1000)))
|
|
|
|
|
let envelopeBuilder = SNProtoEnvelope.builder(type: .sessionMessage, timestamp: UInt64(floor(timestamp * 1000)))
|
|
|
|
|
envelopeBuilder.setContent(data)
|
|
|
|
|
envelopeBuilder.setSource(sender)
|
|
|
|
|
|
|
|
|
@ -367,34 +367,55 @@ public extension Message {
|
|
|
|
|
rawReaction.count > 0,
|
|
|
|
|
let reactors = rawReaction.reactors
|
|
|
|
|
{
|
|
|
|
|
var count = rawReaction.count
|
|
|
|
|
let sortId: Int64 = rawReaction.index
|
|
|
|
|
for reactor in reactors {
|
|
|
|
|
if reactor == blindedUserPublicKey { continue } // Will add a reaction for this case outside of the loop
|
|
|
|
|
let reaction = Reaction(
|
|
|
|
|
let timestampMs: Int64 = Int64(floor((Date().timeIntervalSince1970 * 1000)))
|
|
|
|
|
let desiredReactorIds: [String] = reactors
|
|
|
|
|
.filter { $0 != blindedUserPublicKey }
|
|
|
|
|
|
|
|
|
|
results = results
|
|
|
|
|
.appending( // Add the first reaction (with the count)
|
|
|
|
|
desiredReactorIds.first
|
|
|
|
|
.map { reactor in
|
|
|
|
|
Reaction(
|
|
|
|
|
interactionId: message.id,
|
|
|
|
|
serverHash: nil,
|
|
|
|
|
timestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000))),
|
|
|
|
|
timestampMs: timestampMs,
|
|
|
|
|
authorId: reactor,
|
|
|
|
|
emoji: emoji,
|
|
|
|
|
count: count,
|
|
|
|
|
sortId: sortId
|
|
|
|
|
count: rawReaction.count,
|
|
|
|
|
sortId: rawReaction.index
|
|
|
|
|
)
|
|
|
|
|
count = 0 // Only insert the first reaction with the total count of this emoji
|
|
|
|
|
results.append(reaction)
|
|
|
|
|
}
|
|
|
|
|
if rawReaction.you && !reactors.contains(userPublicKey) {
|
|
|
|
|
let reaction = Reaction(
|
|
|
|
|
)
|
|
|
|
|
.appending( // Add all other reactions
|
|
|
|
|
contentsOf: desiredReactorIds.count <= 1 ?
|
|
|
|
|
[] :
|
|
|
|
|
desiredReactorIds
|
|
|
|
|
.suffix(from: 1)
|
|
|
|
|
.map { reactor in
|
|
|
|
|
Reaction(
|
|
|
|
|
interactionId: message.id,
|
|
|
|
|
serverHash: nil,
|
|
|
|
|
timestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000))),
|
|
|
|
|
authorId: userPublicKey,
|
|
|
|
|
timestampMs: timestampMs,
|
|
|
|
|
authorId: reactor,
|
|
|
|
|
emoji: emoji,
|
|
|
|
|
count: count,
|
|
|
|
|
sortId: sortId
|
|
|
|
|
count: 0, // Only want this on the first reaction
|
|
|
|
|
sortId: rawReaction.index
|
|
|
|
|
)
|
|
|
|
|
results.append(reaction)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.appending( // Add the current user reaction (if applicable and not already included)
|
|
|
|
|
!rawReaction.you || reactors.contains(userPublicKey) ?
|
|
|
|
|
nil :
|
|
|
|
|
Reaction(
|
|
|
|
|
interactionId: message.id,
|
|
|
|
|
serverHash: nil,
|
|
|
|
|
timestampMs: timestampMs,
|
|
|
|
|
authorId: userPublicKey,
|
|
|
|
|
emoji: emoji,
|
|
|
|
|
count: (desiredReactorIds.isEmpty ? rawReaction.count : 0),
|
|
|
|
|
sortId: rawReaction.index
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results
|
|
|
|
|