|
|
|
@ -117,7 +117,7 @@ extension MessageReceiver {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the `didApproveMe` state of the sender
|
|
|
|
|
try updateContactApprovalStatusIfNeeded(
|
|
|
|
|
let shouldInsertControlMessage: Bool = try updateContactApprovalStatusIfNeeded(
|
|
|
|
|
db,
|
|
|
|
|
senderSessionId: senderId,
|
|
|
|
|
threadId: nil
|
|
|
|
@ -138,6 +138,7 @@ extension MessageReceiver {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard shouldInsertControlMessage else { return }
|
|
|
|
|
// Notify the user of their approval (Note: This will always appear in the un-blinded thread)
|
|
|
|
|
//
|
|
|
|
|
// Note: We want to do this last as it'll mean the un-blinded thread gets updated and the
|
|
|
|
@ -156,11 +157,11 @@ extension MessageReceiver {
|
|
|
|
|
).inserted(db)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static func updateContactApprovalStatusIfNeeded(
|
|
|
|
|
@discardableResult internal static func updateContactApprovalStatusIfNeeded(
|
|
|
|
|
_ db: Database,
|
|
|
|
|
senderSessionId: String,
|
|
|
|
|
threadId: String?
|
|
|
|
|
) throws {
|
|
|
|
|
) throws -> Bool {
|
|
|
|
|
let userPublicKey: String = getUserHexEncodedPublicKey(db)
|
|
|
|
|
|
|
|
|
|
// If the sender of the message was the current user
|
|
|
|
@ -171,13 +172,13 @@ extension MessageReceiver {
|
|
|
|
|
let threadId: String = threadId,
|
|
|
|
|
let thread: SessionThread = try? SessionThread.fetchOne(db, id: threadId),
|
|
|
|
|
!thread.isNoteToSelf(db)
|
|
|
|
|
else { return }
|
|
|
|
|
else { return true }
|
|
|
|
|
|
|
|
|
|
// Sending a message to someone flags them as approved so create the contact record if
|
|
|
|
|
// it doesn't exist
|
|
|
|
|
let contact: Contact = Contact.fetchOrCreate(db, id: threadId)
|
|
|
|
|
|
|
|
|
|
guard !contact.isApproved else { return }
|
|
|
|
|
guard !contact.isApproved else { return false }
|
|
|
|
|
|
|
|
|
|
try? contact.save(db)
|
|
|
|
|
_ = try? Contact
|
|
|
|
@ -189,12 +190,14 @@ extension MessageReceiver {
|
|
|
|
|
// someone without approving them)
|
|
|
|
|
let contact: Contact = Contact.fetchOrCreate(db, id: senderSessionId)
|
|
|
|
|
|
|
|
|
|
guard !contact.didApproveMe else { return }
|
|
|
|
|
guard !contact.didApproveMe else { return false }
|
|
|
|
|
|
|
|
|
|
try? contact.save(db)
|
|
|
|
|
_ = try? Contact
|
|
|
|
|
.filter(id: senderSessionId)
|
|
|
|
|
.updateAllAndConfig(db, Contact.Columns.didApproveMe.set(to: true))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|