From 9fff4dce200bd54a74ed793a08004586f2da3c6c Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Mon, 18 Jul 2022 09:54:23 +1000 Subject: [PATCH] Fixed a number of bugs found during QA Fixed a bug where the "Block user" toggle wasn't correctly reflecting the current users state Fixed a bug where the "Blocked banner" wasn't showing the "unblock this user" alert. Fixed a bug where the "Blocked banner" wouldn't re-appear if you re-block a user after unblocking them. Fixed a bug where the conversation screen unblocking logic wasn't actually unblocking the user. Fixed a bug where some settings options were disabled in open groups because the code thought the user had left the group. Fixed a bug where the settings button wouldn't appear after accepting a message request. --- .../ConversationVC+Interaction.swift | 22 ++---------- Session/Conversations/ConversationVC.swift | 35 ++++++++++--------- .../OWSConversationSettingsViewController.m | 2 +- .../Views & Modals/BlockedModal.swift | 2 +- .../Database/Models/Contact.swift | 23 +----------- .../Database/Models/SessionThread.swift | 2 +- 6 files changed, 24 insertions(+), 62 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index aaad028c0..5b7d4dbc3 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -82,29 +82,11 @@ extension ConversationVC: // MARK: - Blocking @objc func unblock() { - guard self.viewModel.threadData.threadVariant == .contact else { return } - - let publicKey: String = self.viewModel.threadData.threadId - - UIView.animate( - withDuration: 0.25, - animations: { - self.blockedBanner.alpha = 0 - }, - completion: { _ in - Storage.shared.write { db in - try Contact - .filter(id: publicKey) - .updateAll(db, Contact.Columns.isBlocked.set(to: true)) - - try MessageSender.syncConfiguration(db, forceSyncNow: true).retainUntilComplete() - } - } - ) + self.showBlockedModalIfNeeded() } func showBlockedModalIfNeeded() -> Bool { - guard viewModel.threadData.threadIsBlocked == true else { return false } + guard self.viewModel.threadData.threadIsBlocked == true else { return false } let blockedModal = BlockedModal(publicKey: viewModel.threadData.threadId) blockedModal.modalPresentationStyle = .overFullScreen diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 3b5e8241e..0ee0ddb1c 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -551,29 +551,21 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers if initialLoad || viewModel.threadData.threadRequiresApproval != updatedThreadData.threadRequiresApproval || + viewModel.threadData.threadIsMessageRequest != updatedThreadData.threadIsMessageRequest || viewModel.threadData.profile != updatedThreadData.profile { updateNavBarButtons(threadData: updatedThreadData, initialVariant: viewModel.initialThreadVariant) - } - - if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked { - addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true)) - } - - if initialLoad || viewModel.threadData.threadIsMessageRequest != updatedThreadData.threadIsMessageRequest { - scrollButtonMessageRequestsBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == true) - scrollButtonBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == false) - } - - if - initialLoad || - viewModel.threadData.threadRequiresApproval != updatedThreadData.threadRequiresApproval || - viewModel.threadData.threadIsMessageRequest != updatedThreadData.threadIsMessageRequest - { + messageRequestView.isHidden = ( updatedThreadData.threadIsMessageRequest == false || updatedThreadData.threadRequiresApproval == true ) + scrollButtonMessageRequestsBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == true) + scrollButtonBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == false) + } + + if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked { + addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true)) } if initialLoad || viewModel.threadData.threadUnreadCount != updatedThreadData.threadUnreadCount { @@ -1056,7 +1048,16 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers func addOrRemoveBlockedBanner(threadIsBlocked: Bool) { guard threadIsBlocked else { - self.blockedBanner.removeFromSuperview() + UIView.animate( + withDuration: 0.25, + animations: { [weak self] in + self?.blockedBanner.alpha = 0 + }, + completion: { [weak self] _ in + self?.blockedBanner.alpha = 1 + self?.blockedBanner.removeFromSuperview() + } + ) return } diff --git a/Session/Conversations/Settings/OWSConversationSettingsViewController.m b/Session/Conversations/Settings/OWSConversationSettingsViewController.m index 8eadd24dd..8af9dc453 100644 --- a/Session/Conversations/Settings/OWSConversationSettingsViewController.m +++ b/Session/Conversations/Settings/OWSConversationSettingsViewController.m @@ -718,7 +718,7 @@ CGFloat kIconViewLength = 24; - (BOOL)hasLeftGroup { - if (self.isClosedGroup || self.isOpenGroup) { + if (self.isClosedGroup) { return ![SMKGroupMember isCurrentUserMemberOf:self.threadId]; } diff --git a/Session/Conversations/Views & Modals/BlockedModal.swift b/Session/Conversations/Views & Modals/BlockedModal.swift index 15b3f8f18..ba24745bb 100644 --- a/Session/Conversations/Views & Modals/BlockedModal.swift +++ b/Session/Conversations/Views & Modals/BlockedModal.swift @@ -81,7 +81,7 @@ final class BlockedModal: Modal { Storage.shared.writeAsync { db in try Contact .filter(id: publicKey) - .updateAll(db, Contact.Columns.isBlocked.set(to: true)) + .updateAll(db, Contact.Columns.isBlocked.set(to: false)) try MessageSender .syncConfiguration(db, forceSyncNow: true) diff --git a/SessionMessagingKit/Database/Models/Contact.swift b/SessionMessagingKit/Database/Models/Contact.swift index 57e93ae0c..ab85bb808 100644 --- a/SessionMessagingKit/Database/Models/Contact.swift +++ b/SessionMessagingKit/Database/Models/Contact.swift @@ -106,33 +106,12 @@ public extension Contact { // TODO: Remove this when possible @objc(SMKContact) public class SMKContact: NSObject { - @objc let isApproved: Bool - @objc let isBlocked: Bool - @objc let didApproveMe: Bool - - init(isApproved: Bool, isBlocked: Bool, didApproveMe: Bool) { - self.isApproved = isApproved - self.isBlocked = isBlocked - self.didApproveMe = didApproveMe - } - - @objc public static func fetchOrCreate(id: String) -> SMKContact { - let existingContact: Contact? = Storage.shared.read { db in - try Contact.fetchOne(db, id: id) - } - - return SMKContact( - isApproved: existingContact?.isApproved ?? false, - isBlocked: existingContact?.isBlocked ?? false, - didApproveMe: existingContact?.didApproveMe ?? false - ) - } - @objc(isBlockedFor:) public static func isBlocked(id: String) -> Bool { return Storage.shared .read { db in try Contact + .filter(id: id) .select(.isBlocked) .asRequest(of: Bool.self) .fetchOne(db) diff --git a/SessionMessagingKit/Database/Models/SessionThread.swift b/SessionMessagingKit/Database/Models/SessionThread.swift index 1b4e55169..452ab8c49 100644 --- a/SessionMessagingKit/Database/Models/SessionThread.swift +++ b/SessionMessagingKit/Database/Models/SessionThread.swift @@ -381,7 +381,7 @@ public class SMKThread: NSObject { public static func isOnlyNotifyingForMentions(_ threadId: String) -> Bool { return Storage.shared.read { db in return try SessionThread - .select(SessionThread.Columns.onlyNotifyForMentions == true) + .select(SessionThread.Columns.onlyNotifyForMentions) .filter(id: threadId) .asRequest(of: Bool.self) .fetchOne(db)