Fixed an issue where the message request acceptance control message could incorrectly appear

pull/1061/head
Morgan Pretty 4 weeks ago
parent c5f70fc92b
commit 72d01758ef

@ -131,6 +131,12 @@ extension MessageReceiver {
} }
// Update the `didApproveMe` state of the sender // Update the `didApproveMe` state of the sender
let senderHadAlreadyApprovedMe: Bool = (try? Contact
.select(.didApproveMe)
.filter(id: senderId)
.asRequest(of: Bool.self)
.fetchOne(db))
.defaulting(to: false)
try updateContactApprovalStatusIfNeeded( try updateContactApprovalStatusIfNeeded(
db, db,
senderSessionId: senderId, senderSessionId: senderId,
@ -154,23 +160,29 @@ extension MessageReceiver {
) )
} }
// Notify the user of their approval (Note: This will always appear in the un-blinded thread) /// Notify the user of their approval
// ///
// Note: We want to do this last as it'll mean the un-blinded thread gets updated and the /// We want to do this last as it'll mean the un-blinded thread gets updated and the contact approval status will have been
// contact approval status will have been updated at this point (which will mean the /// updated at this point (which will mean the `isMessageRequest` will return correctly after this is saved)
// `isMessageRequest` will return correctly after this is saved) ///
_ = try Interaction( /// **Notes:**
serverHash: message.serverHash, /// - We only want to add the control message if the sender hadn't already approved the current user (this is to prevent spam
threadId: unblindedThread.id, /// if the sender deletes and re-accepts message requests from the current user)
threadVariant: unblindedThread.variant, /// - This will always appear in the un-blinded thread
authorId: senderId, if !senderHadAlreadyApprovedMe {
variant: .infoMessageRequestAccepted, _ = try Interaction(
timestampMs: ( serverHash: message.serverHash,
message.sentTimestampMs.map { Int64($0) } ?? threadId: unblindedThread.id,
dependencies[cache: .snodeAPI].currentOffsetTimestampMs() threadVariant: unblindedThread.variant,
), authorId: senderId,
using: dependencies variant: .infoMessageRequestAccepted,
).inserted(db) timestampMs: (
message.sentTimestampMs.map { Int64($0) } ??
dependencies[cache: .snodeAPI].currentOffsetTimestampMs()
),
using: dependencies
).inserted(db)
}
} }
internal static func updateContactApprovalStatusIfNeeded( internal static func updateContactApprovalStatusIfNeeded(

Loading…
Cancel
Save