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"
),
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 ?

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

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

Loading…
Cancel
Save