diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index c23af9fc7..5f2270597 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1728,6 +1728,53 @@ extension ConversationVC { self.present(alertVC, animated: true, completion: nil) } + + @objc func block() { + guard self.viewModel.threadData.threadVariant == .contact else { return } + + let threadId: String = self.viewModel.threadData.threadId + let alertVC: UIAlertController = UIAlertController( + title: "MESSAGE_REQUESTS_BLOCK_CONFIRMATION_ACTON".localized(), + message: nil, + preferredStyle: .actionSheet + ) + alertVC.addAction(UIAlertAction(title: "TXT_DELETE_TITLE".localized(), style: .destructive) { _ in + // Delete the request + Storage.shared.writeAsync( + updates: { db in + // Update the contact + _ = try Contact + .fetchOrCreate(db, id: threadId) + .with( + isApproved: false, + isBlocked: true, + + // Note: We set this to true so the current user will be able to send a + // message to the person who originally sent them the message request in + // the future if they unblock them + didApproveMe: true + ) + .saved(db) + + _ = try SessionThread + .filter(id: threadId) + .deleteAll(db) + + try MessageSender + .syncConfiguration(db, forceSyncNow: true) + .retainUntilComplete() + }, + completion: { db, _ in + DispatchQueue.main.async { [weak self] in + self?.navigationController?.popViewController(animated: true) + } + } + ) + }) + alertVC.addAction(UIAlertAction(title: "TXT_CANCEL_TITLE".localized(), style: .cancel, handler: nil)) + + self.present(alertVC, animated: true, completion: nil) + } } // MARK: - MediaPresentationContextProvider diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index c0cf9eca4..e20aec2a3 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -279,6 +279,18 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers return result }() + + private lazy var messageRequestBlockButton: UIButton = { + let result: UIButton = UIButton() + result.translatesAutoresizingMaskIntoConstraints = false + result.clipsToBounds = true + result.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16) + result.setTitle(NSLocalizedString("TXT_BLOCK_USER_TITLE", comment: ""), for: .normal) + result.setTitleColor(Colors.destructive, for: .normal) + result.addTarget(self, action: #selector(block), for: .touchUpInside) + + return result + }() // MARK: - Settings @@ -339,6 +351,7 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers view.addSubview(scrollButton) view.addSubview(messageRequestView) + messageRequestView.addSubview(messageRequestBlockButton) messageRequestView.addSubview(messageRequestDescriptionLabel) messageRequestView.addSubview(messageRequestAcceptButton) messageRequestView.addSubview(messageRequestDeleteButton) @@ -351,7 +364,10 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers self.scrollButtonBottomConstraint?.isActive = false // Note: Need to disable this to avoid a conflict with the other bottom constraint self.scrollButtonMessageRequestsBottomConstraint = scrollButton.pin(.bottom, to: .top, of: messageRequestView, withInset: -16) - messageRequestDescriptionLabel.pin(.top, to: .top, of: messageRequestView, withInset: 10) + messageRequestBlockButton.pin(.top, to: .top, of: messageRequestView, withInset: 10) + messageRequestBlockButton.center(.horizontal, in: messageRequestView) + + messageRequestDescriptionLabel.pin(.top, to: .bottom, of: messageRequestBlockButton, withInset: 20) messageRequestDescriptionLabel.pin(.left, to: .left, of: messageRequestView, withInset: 40) messageRequestDescriptionLabel.pin(.right, to: .right, of: messageRequestView, withInset: -40)