diff --git a/Session/Conversations/Settings/ThreadSettingsViewModel.swift b/Session/Conversations/Settings/ThreadSettingsViewModel.swift index 7d611f2ac..9c3eb18e3 100644 --- a/Session/Conversations/Settings/ThreadSettingsViewModel.swift +++ b/Session/Conversations/Settings/ThreadSettingsViewModel.swift @@ -669,29 +669,20 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigatableStateHolder, Ob label: "Block" ), confirmationInfo: ConfirmationModal.Info( - title: { - guard threadViewModel.threadIsBlocked == true else { - return String( - format: "block".localized(), - threadViewModel.displayName - ) - } - - return String( - format: "blockUnblock".localized(), - threadViewModel.displayName - ) - }(), + title: (threadViewModel.threadIsBlocked == true ? + "blockUnblock".localized() : + "block".localized() + ), body: (threadViewModel.threadIsBlocked == true ? .attributedText( "blockUnblockName" .put(key: "name", value: threadViewModel.displayName) - .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) + .localizedFormatted(baseFont: ConfirmationModal.explanationFont) ) : .attributedText( "blockDescription" .put(key: "name", value: threadViewModel.displayName) - .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) + .localizedFormatted(baseFont: ConfirmationModal.explanationFont) ) ), confirmTitle: (threadViewModel.threadIsBlocked == true ? diff --git a/Session/Utilities/UIContextualAction+Utilities.swift b/Session/Utilities/UIContextualAction+Utilities.swift index ac3797c65..e094e5c89 100644 --- a/Session/Utilities/UIContextualAction+Utilities.swift +++ b/Session/Utilities/UIContextualAction+Utilities.swift @@ -367,98 +367,110 @@ public extension UIContextualAction { (!threadIsContactMessageRequest ? nil : Contact.Columns.didApproveMe.set(to: true)), (!threadIsContactMessageRequest ? nil : Contact.Columns.isApproved.set(to: false)) ].compactMap { $0 } + let nameToUse: String = { + switch threadViewModel.threadVariant { + case .group: + return Profile.displayName( + for: .contact, + id: profileInfo.id, + name: profileInfo.profile?.name, + nickname: profileInfo.profile?.nickname, + suppressId: false + ) + + default: return threadViewModel.displayName + } + }() - let performBlock: (UIViewController?) -> () = { viewController in - completionHandler(true) - - // Delay the change to give the cell "unswipe" animation some time to complete - DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + unswipeAnimationDelay) { - dependencies[singleton: .storage] - .writePublisher { db in - // Create the contact if it doesn't exist - switch threadViewModel.threadVariant { - case .contact: - try Contact - .fetchOrCreate(db, id: threadViewModel.threadId, using: dependencies) - .upsert(db) - try Contact - .filter(id: threadViewModel.threadId) - .updateAllAndConfig( - db, - contactChanges, - using: dependencies - ) + let confirmationModal: ConfirmationModal = ConfirmationModal( + info: ConfirmationModal.Info( + title: (threadIsBlocked ? + "blockUnblock".localized() : + "block".localized() + ), + body: (threadIsBlocked ? + .attributedText( + "blockUnblockName" + .put(key: "name", value: nameToUse) + .localizedFormatted(baseFont: ConfirmationModal.explanationFont) + ) : + .attributedText( + "blockDescription" + .put(key: "name", value: nameToUse) + .localizedFormatted(baseFont: ConfirmationModal.explanationFont) + ) + ), + confirmTitle: (threadIsBlocked ? + "blockUnblock".localized() : + "block".localized() + ), + confirmStyle: .danger, + cancelStyle: .alert_text, + dismissOnConfirm: true, + onConfirm: { _ in + completionHandler(true) + + // Delay the change to give the cell "unswipe" animation some time to complete + DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + unswipeAnimationDelay) { + dependencies[singleton: .storage] + .writePublisher { db in + // Create the contact if it doesn't exist + switch threadViewModel.threadVariant { + case .contact: + try Contact + .fetchOrCreate( + db, + id: threadViewModel.threadId, + using: dependencies + ) + .upsert(db) + try Contact + .filter(id: threadViewModel.threadId) + .updateAllAndConfig( + db, + contactChanges, + using: dependencies + ) + + case .group: + try Contact + .fetchOrCreate( + db, + id: profileInfo.id, + using: dependencies + ) + .upsert(db) + try Contact + .filter(id: profileInfo.id) + .updateAllAndConfig( + db, + contactChanges, + using: dependencies + ) + + default: break + } - case .group: - try Contact - .fetchOrCreate(db, id: profileInfo.id, using: dependencies) - .upsert(db) - try Contact - .filter(id: profileInfo.id) - .updateAllAndConfig( + // Blocked message requests should be deleted + if threadViewModel.threadIsMessageRequest == true { + try SessionThread.deleteOrLeave( db, - contactChanges, + type: .deleteContactConversationAndMarkHidden, + threadId: threadViewModel.threadId, + threadVariant: threadViewModel.threadVariant, using: dependencies ) - - default: break - } - - // Blocked message requests should be deleted - if threadViewModel.threadIsMessageRequest == true { - try SessionThread.deleteOrLeave( - db, - type: .deleteContactConversationAndMarkHidden, - threadId: threadViewModel.threadId, - threadVariant: threadViewModel.threadVariant, - using: dependencies - ) - } - } - .subscribe(on: DispatchQueue.global(qos: .userInitiated)) - .sinkUntilComplete() - } - } - - switch threadViewModel.threadIsMessageRequest == true { - case false: performBlock(nil) - case true: - let nameToUse: String = { - switch threadViewModel.threadVariant { - case .group: - return Profile.displayName( - for: .contact, - id: profileInfo.id, - name: profileInfo.profile?.name, - nickname: profileInfo.profile?.nickname, - suppressId: false - ) - - default: return threadViewModel.displayName + } + } + .subscribe(on: DispatchQueue.global(qos: .userInitiated)) + .sinkUntilComplete() } - }() - - let confirmationModal: ConfirmationModal = ConfirmationModal( - info: ConfirmationModal.Info( - title: "block".localized(), - body: .attributedText( - "blockDescription" - .put(key: "name", value: nameToUse) - .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) - ), - confirmTitle: "block".localized(), - confirmStyle: .danger, - cancelStyle: .alert_text, - dismissOnConfirm: true, - onConfirm: { _ in - performBlock(viewController) - }, - afterClosed: { completionHandler(false) } - ) - ) - - viewController?.present(confirmationModal, animated: true, completion: nil) - } + }, + afterClosed: { completionHandler(false) } + ) + ) + + viewController?.present(confirmationModal, animated: true, completion: nil) } // MARK: -- leave diff --git a/SessionMessagingKit/Database/Models/SessionThread.swift b/SessionMessagingKit/Database/Models/SessionThread.swift index 097a7bc4c..9e0e19ebf 100644 --- a/SessionMessagingKit/Database/Models/SessionThread.swift +++ b/SessionMessagingKit/Database/Models/SessionThread.swift @@ -534,9 +534,14 @@ public extension SessionThread { try LibSession.hide(db, contactIds: Array(remainingThreadIds), using: dependencies) case .deleteContactConversationAndContact: - // Remove the contact from the config + // Remove the contact from the config (also need to clear the nickname since that's + // custom data for this contact) try LibSession.remove(db, contactIds: Array(remainingThreadIds), using: dependencies) + _ = try Profile + .filter(ids: remainingThreadIds) + .updateAll(db, Profile.Columns.nickname.set(to: nil)) + _ = try Contact .filter(ids: remainingThreadIds) .deleteAll(db)