mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fixed an issue where read receipts could be sent for already read messages Fixed an issue where the read state change might not update the UI
36 lines
1.3 KiB
Swift
36 lines
1.3 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
|
|
extension MessageReceiver {
|
|
internal static func handleReadReceipt(
|
|
_ db: Database,
|
|
message: ReadReceipt,
|
|
serverExpirationTimestamp: TimeInterval?
|
|
) throws {
|
|
guard let sender: String = message.sender else { return }
|
|
guard let timestampMsValues: [Int64] = message.timestamps?.map({ Int64($0) }) else { return }
|
|
guard let readTimestampMs: Int64 = message.receivedTimestamp.map({ Int64($0) }) else { return }
|
|
|
|
let pendingTimestampMs: Set<Int64> = try Interaction.markAsRead(
|
|
db,
|
|
recipientId: sender,
|
|
timestampMsValues: timestampMsValues,
|
|
readTimestampMs: readTimestampMs
|
|
)
|
|
|
|
guard !pendingTimestampMs.isEmpty else { return }
|
|
|
|
// We have some pending read receipts so store them in the database
|
|
try pendingTimestampMs.forEach { timestampMs in
|
|
try PendingReadReceipt(
|
|
threadId: sender,
|
|
interactionTimestampMs: timestampMs,
|
|
readTimestampMs: readTimestampMs,
|
|
serverExpirationTimestamp: (serverExpirationTimestamp ?? 0)
|
|
).save(db)
|
|
}
|
|
}
|
|
}
|