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.
This commit is contained in:
Morgan Pretty 2022-07-18 09:54:23 +10:00
parent 3c07a2d044
commit 9fff4dce20
6 changed files with 24 additions and 62 deletions

View file

@ -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

View file

@ -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
}

View file

@ -718,7 +718,7 @@ CGFloat kIconViewLength = 24;
- (BOOL)hasLeftGroup
{
if (self.isClosedGroup || self.isOpenGroup) {
if (self.isClosedGroup) {
return ![SMKGroupMember isCurrentUserMemberOf:self.threadId];
}

View file

@ -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)

View file

@ -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)

View file

@ -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)