@ -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 )
// 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
DispatchQueue . global ( qos : . default ) . asyncAfter ( deadline : . now ( ) + unswipeAnimationDelay ) {
dependencies [ singleton : . storage ]
. writePublisher { db in
// C r e a t e t h e c o n t a c t i f i t d o e s n ' t e x i s t
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 )
// 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
DispatchQueue . global ( qos : . default ) . asyncAfter ( deadline : . now ( ) + unswipeAnimationDelay ) {
dependencies [ singleton : . storage ]
. writePublisher { db in
// C r e a t e t h e c o n t a c t i f i t d o e s n ' t e x i s t
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 (
// B l o c k e d m e s s a g e r e q u e s t s s h o u l d b e d e l e t e d
if threadViewModel . threadIsMessageRequest = = true {
try SessionThread . deleteOrLeave (
db ,
contactChanges ,
type : . deleteContactConversationAndMarkHidden ,
threadId : threadViewModel . threadId ,
threadVariant : threadViewModel . threadVariant ,
using : dependencies
)
default : break
}
// B l o c k e d m e s s a g e r e q u e s t s s h o u l d b e d e l e t e d
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: - - l e a v e