fix disappear after read not synced properly

pull/941/head
ryanzhao 1 year ago
parent 284bdab9f8
commit 84452750fe

@ -86,8 +86,8 @@ public extension DisappearingMessagesJob {
Interaction.Columns.expiresInSeconds != nil && Interaction.Columns.expiresInSeconds != nil &&
Interaction.Columns.expiresStartedAtMs == nil Interaction.Columns.expiresStartedAtMs == nil
) )
.select(Interaction.Columns.serverHash) .select(Interaction.Columns.serverHash)
.fetchAll(db)) .fetchAll(db))
.defaulting(to: []) .defaulting(to: [])
// If there were no message hashes then none of the messages sent before lastReadTimestampMs are expiring messages // If there were no message hashes then none of the messages sent before lastReadTimestampMs are expiring messages
@ -103,18 +103,16 @@ public extension DisappearingMessagesJob {
let userPublicKey: String = getUserHexEncodedPublicKey(db) let userPublicKey: String = getUserHexEncodedPublicKey(db)
SnodeAPI.getSwarm(for: userPublicKey) SnodeAPI.getSwarm(for: userPublicKey)
.tryFlatMap { swarm -> AnyPublisher<(ResponseInfoType, GetExpiriesResponse), Error> in .tryFlatMap { swarm -> AnyPublisher<Void, Error> in
guard let snode = swarm.randomElement() else { throw SnodeAPIError.generic } guard let snode = swarm.randomElement() else { throw SnodeAPIError.generic }
return SnodeAPI.getExpiries( return SnodeAPI.getExpiries(
from: snode, from: snode,
associatedWith: userPublicKey, associatedWith: userPublicKey,
of: messageHashes of: messageHashes
) )
} .map { (_, response) in
.sinkUntilComplete (
receiveValue: { response in
Storage.shared.writeAsync { db in Storage.shared.writeAsync { db in
try response.1.expiries.forEach { hash, exipreAtMs in try response.expiries.forEach { hash, exipreAtMs in
let expiresInSeconds: TimeInterval = TimeInterval((exipreAtMs - UInt64(lastReadTimestampMs)) / 1000) let expiresInSeconds: TimeInterval = TimeInterval((exipreAtMs - UInt64(lastReadTimestampMs)) / 1000)
_ = try Interaction _ = try Interaction
@ -126,7 +124,9 @@ public extension DisappearingMessagesJob {
} }
} }
} }
) .eraseToAnyPublisher()
}
.sinkUntilComplete ()
return updateNextRunIfNeeded(db) return updateNextRunIfNeeded(db)
} }

Loading…
Cancel
Save