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

pull/1061/head
Morgan Pretty 2 months 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,11 +160,16 @@ 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) ///
/// **Notes:**
/// - We only want to add the control message if the sender hadn't already approved the current user (this is to prevent spam
/// if the sender deletes and re-accepts message requests from the current user)
/// - This will always appear in the un-blinded thread
if !senderHadAlreadyApprovedMe {
_ = try Interaction( _ = try Interaction(
serverHash: message.serverHash, serverHash: message.serverHash,
threadId: unblindedThread.id, threadId: unblindedThread.id,
@ -172,6 +183,7 @@ extension MessageReceiver {
using: dependencies using: dependencies
).inserted(db) ).inserted(db)
} }
}
internal static func updateContactApprovalStatusIfNeeded( internal static func updateContactApprovalStatusIfNeeded(
_ db: Database, _ db: Database,

Loading…
Cancel
Save