clean up
This commit is contained in:
parent
ba578fcb3c
commit
4cb2d81670
|
@ -244,4 +244,4 @@ SPEC CHECKSUMS:
|
|||
|
||||
PODFILE CHECKSUM: f0857369c4831b2e5c1946345e76e493f3286805
|
||||
|
||||
COCOAPODS: 1.11.2
|
||||
COCOAPODS: 1.11.3
|
||||
|
|
|
@ -10,6 +10,5 @@ enum QueryParam: String {
|
|||
case limit // For messages - number between 1 and 256 (default is 100)
|
||||
case platform // For file server session version check
|
||||
|
||||
case reactions = "t"
|
||||
case reactors = "reactors"
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
interactionId: message.id,
|
||||
serverHash: nil,
|
||||
timestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000))),
|
||||
authorId: reactor,
|
||||
emoji: emoji,
|
||||
count: count,
|
||||
sortId: sortId
|
||||
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: timestampMs,
|
||||
authorId: reactor,
|
||||
emoji: emoji,
|
||||
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(
|
||||
interactionId: message.id,
|
||||
serverHash: nil,
|
||||
timestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000))),
|
||||
authorId: userPublicKey,
|
||||
emoji: emoji,
|
||||
count: count,
|
||||
sortId: sortId
|
||||
.appending( // Add all other reactions
|
||||
contentsOf: desiredReactorIds.count <= 1 ?
|
||||
[] :
|
||||
desiredReactorIds
|
||||
.suffix(from: 1)
|
||||
.map { reactor in
|
||||
Reaction(
|
||||
interactionId: message.id,
|
||||
serverHash: nil,
|
||||
timestampMs: timestampMs,
|
||||
authorId: reactor,
|
||||
emoji: emoji,
|
||||
count: 0, // Only want this on the first reaction
|
||||
sortId: rawReaction.index
|
||||
)
|
||||
}
|
||||
)
|
||||
.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
|
||||
)
|
||||
)
|
||||
results.append(reaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
|
|
|
@ -24,7 +24,7 @@ extension OpenGroupAPI {
|
|||
|
||||
public let id: Int64
|
||||
public let sender: String?
|
||||
public let posted: TimeInterval
|
||||
public let posted: TimeInterval?
|
||||
public let edited: TimeInterval?
|
||||
public let deleted: Bool?
|
||||
public let seqNo: Int64
|
||||
|
@ -98,7 +98,7 @@ extension OpenGroupAPI.Message {
|
|||
self = OpenGroupAPI.Message(
|
||||
id: try container.decode(Int64.self, forKey: .id),
|
||||
sender: try? container.decode(String.self, forKey: .sender),
|
||||
posted: ((try? container.decode(TimeInterval.self, forKey: .posted)) ?? Date().timeIntervalSince1970), // Reaction updates don't include posted
|
||||
posted: try? container.decode(TimeInterval.self, forKey: .posted),
|
||||
edited: try? container.decode(TimeInterval.self, forKey: .edited),
|
||||
deleted: try? container.decode(Bool.self, forKey: .deleted),
|
||||
seqNo: try container.decode(Int64.self, forKey: .seqNo),
|
||||
|
|
|
@ -97,8 +97,7 @@ public enum OpenGroupAPI {
|
|||
.roomMessagesRecent(openGroup.roomToken) :
|
||||
.roomMessagesSince(openGroup.roomToken, seqNo: openGroup.sequenceNumber)
|
||||
),
|
||||
queryParameters: [.reactions: "r",
|
||||
.reactors: "20"]
|
||||
queryParameters: [.reactors: "20"]
|
||||
),
|
||||
responseType: [Failable<Message>].self
|
||||
)
|
||||
|
@ -621,7 +620,7 @@ public enum OpenGroupAPI {
|
|||
request: Request<NoBody, Endpoint>(
|
||||
server: server,
|
||||
endpoint: .roomMessagesSince(roomToken, seqNo: seqNo),
|
||||
queryParameters: [.reactions : "r"]
|
||||
queryParameters: [.reactors: "20"]
|
||||
),
|
||||
using: dependencies
|
||||
)
|
||||
|
|
|
@ -564,13 +564,11 @@ public final class OpenGroupManager: NSObject {
|
|||
dependencies: dependencies
|
||||
)
|
||||
|
||||
if !reactions.isEmpty {
|
||||
try MessageReceiver.handleOpenGroupReactions(
|
||||
db,
|
||||
openGroupMessageServerId: message.id,
|
||||
openGroupReactions: reactions
|
||||
)
|
||||
}
|
||||
try MessageReceiver.handleOpenGroupReactions(
|
||||
db,
|
||||
openGroupMessageServerId: message.id,
|
||||
openGroupReactions: reactions
|
||||
)
|
||||
}
|
||||
catch {
|
||||
SNLog("Couldn't handle open group reactions due to error: \(error).")
|
||||
|
|
|
@ -433,7 +433,8 @@ public final class MessageSender {
|
|||
)
|
||||
.done(on: DispatchQueue.global(qos: .default)) { responseInfo, data in
|
||||
message.openGroupServerMessageId = UInt64(data.id)
|
||||
|
||||
let serverTimestampMs: UInt64? = (data.posted == nil) ? nil : UInt64(floor(data.posted! * 1000))
|
||||
|
||||
dependencies.storage.write { db in
|
||||
// The `posted` value is in seconds but we sent it in ms so need that for de-duping
|
||||
try MessageSender.handleSuccessfulMessageSend(
|
||||
|
@ -441,7 +442,7 @@ public final class MessageSender {
|
|||
message: message,
|
||||
to: destination,
|
||||
interactionId: interactionId,
|
||||
serverTimestampMs: UInt64(floor(data.posted * 1000))
|
||||
serverTimestampMs: serverTimestampMs
|
||||
)
|
||||
seal.fulfill(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue