@ -367,8 +367,47 @@ 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
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 )
// D e l a y t h e c h a n g e t o g i v e t h e c e l l " u n s w i p e " a n i m a t i o n s o m e t i m e t o c o m p l e t e
@ -379,7 +418,11 @@ public extension UIContextualAction {
switch threadViewModel . threadVariant {
case . contact :
try Contact
. fetchOrCreate ( db , id : threadViewModel . threadId , using : dependencies )
. fetchOrCreate (
db ,
id : threadViewModel . threadId ,
using : dependencies
)
. upsert ( db )
try Contact
. filter ( id : threadViewModel . threadId )
@ -391,7 +434,11 @@ public extension UIContextualAction {
case . group :
try Contact
. fetchOrCreate ( db , id : profileInfo . id , using : dependencies )
. fetchOrCreate (
db ,
id : profileInfo . id ,
using : dependencies
)
. upsert ( db )
try Contact
. filter ( id : profileInfo . id )
@ -418,40 +465,6 @@ public extension UIContextualAction {
. 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
}
} ( )
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 ) }
)
@ -459,7 +472,6 @@ public extension UIContextualAction {
viewController ? . present ( confirmationModal , animated : true , completion : nil )
}
}
// MARK: - - l e a v e