Fixed a couple of QA issues

• Fixed a bug where the nickname of a deleted contact would remain after deletion
• Fixed a bug where the block swipe action wouldn't show the confirmation modal
pull/1061/head
Morgan Pretty 3 weeks ago
parent afd0e8ee50
commit ed212e69a8

@ -669,29 +669,20 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigatableStateHolder, Ob
label: "Block" label: "Block"
), ),
confirmationInfo: ConfirmationModal.Info( confirmationInfo: ConfirmationModal.Info(
title: { title: (threadViewModel.threadIsBlocked == true ?
guard threadViewModel.threadIsBlocked == true else { "blockUnblock".localized() :
return String( "block".localized()
format: "block".localized(), ),
threadViewModel.displayName
)
}
return String(
format: "blockUnblock".localized(),
threadViewModel.displayName
)
}(),
body: (threadViewModel.threadIsBlocked == true ? body: (threadViewModel.threadIsBlocked == true ?
.attributedText( .attributedText(
"blockUnblockName" "blockUnblockName"
.put(key: "name", value: threadViewModel.displayName) .put(key: "name", value: threadViewModel.displayName)
.localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) .localizedFormatted(baseFont: ConfirmationModal.explanationFont)
) : ) :
.attributedText( .attributedText(
"blockDescription" "blockDescription"
.put(key: "name", value: threadViewModel.displayName) .put(key: "name", value: threadViewModel.displayName)
.localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize)) .localizedFormatted(baseFont: ConfirmationModal.explanationFont)
) )
), ),
confirmTitle: (threadViewModel.threadIsBlocked == true ? confirmTitle: (threadViewModel.threadIsBlocked == true ?

@ -367,98 +367,110 @@ public extension UIContextualAction {
(!threadIsContactMessageRequest ? nil : Contact.Columns.didApproveMe.set(to: true)), (!threadIsContactMessageRequest ? nil : Contact.Columns.didApproveMe.set(to: true)),
(!threadIsContactMessageRequest ? nil : Contact.Columns.isApproved.set(to: false)) (!threadIsContactMessageRequest ? nil : Contact.Columns.isApproved.set(to: false))
].compactMap { $0 } ].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 let confirmationModal: ConfirmationModal = ConfirmationModal(
completionHandler(true) info: ConfirmationModal.Info(
title: (threadIsBlocked ?
// Delay the change to give the cell "unswipe" animation some time to complete "blockUnblock".localized() :
DispatchQueue.global(qos: .default).asyncAfter(deadline: .now() + unswipeAnimationDelay) { "block".localized()
dependencies[singleton: .storage] ),
.writePublisher { db in body: (threadIsBlocked ?
// Create the contact if it doesn't exist .attributedText(
switch threadViewModel.threadVariant { "blockUnblockName"
case .contact: .put(key: "name", value: nameToUse)
try Contact .localizedFormatted(baseFont: ConfirmationModal.explanationFont)
.fetchOrCreate(db, id: threadViewModel.threadId, using: dependencies) ) :
.upsert(db) .attributedText(
try Contact "blockDescription"
.filter(id: threadViewModel.threadId) .put(key: "name", value: nameToUse)
.updateAllAndConfig( .localizedFormatted(baseFont: ConfirmationModal.explanationFont)
db, )
contactChanges, ),
using: dependencies 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: // Blocked message requests should be deleted
try Contact if threadViewModel.threadIsMessageRequest == true {
.fetchOrCreate(db, id: profileInfo.id, using: dependencies) try SessionThread.deleteOrLeave(
.upsert(db)
try Contact
.filter(id: profileInfo.id)
.updateAllAndConfig(
db, db,
contactChanges, type: .deleteContactConversationAndMarkHidden,
threadId: threadViewModel.threadId,
threadVariant: threadViewModel.threadVariant,
using: dependencies using: dependencies
) )
}
default: break }
} .subscribe(on: DispatchQueue.global(qos: .userInitiated))
.sinkUntilComplete()
// 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
} }
}() },
afterClosed: { completionHandler(false) }
let confirmationModal: ConfirmationModal = ConfirmationModal( )
info: ConfirmationModal.Info( )
title: "block".localized(),
body: .attributedText( viewController?.present(confirmationModal, animated: true, completion: nil)
"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)
}
} }
// MARK: -- leave // MARK: -- leave

@ -534,9 +534,14 @@ public extension SessionThread {
try LibSession.hide(db, contactIds: Array(remainingThreadIds), using: dependencies) try LibSession.hide(db, contactIds: Array(remainingThreadIds), using: dependencies)
case .deleteContactConversationAndContact: 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 LibSession.remove(db, contactIds: Array(remainingThreadIds), using: dependencies)
_ = try Profile
.filter(ids: remainingThreadIds)
.updateAll(db, Profile.Columns.nickname.set(to: nil))
_ = try Contact _ = try Contact
.filter(ids: remainingThreadIds) .filter(ids: remainingThreadIds)
.deleteAll(db) .deleteAll(db)

Loading…
Cancel
Save