@ -40,6 +40,20 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
return result
} ( )
private lazy var emptyStateLabel : UILabel = {
let result : UILabel = UILabel ( )
result . translatesAutoresizingMaskIntoConstraints = false
result . isUserInteractionEnabled = false
result . font = UIFont . systemFont ( ofSize : Values . smallFontSize )
result . text = NSLocalizedString ( " MESSAGE_REQUESTS_EMPTY_TEXT " , comment : " " )
result . textColor = Colors . text
result . textAlignment = . center
result . numberOfLines = 0
result . isHidden = true
return result
} ( )
private lazy var fadeView : UIView = {
let result : UIView = UIView ( )
result . translatesAutoresizingMaskIntoConstraints = false
@ -62,6 +76,7 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
. toImage ( isDarkMode : isDarkMode ) ,
for : . highlighted
)
result . isHidden = true
result . layer . cornerRadius = ( NewConversationButtonSet . collapsedButtonSize / 2 )
result . layer . borderColor = Colors . destructive . cgColor
result . layer . borderWidth = 1.5
@ -84,6 +99,7 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
// A d d t h e U I ( M U S T b e d o n e a f t e r t h e t h r e a d f r e e z e s o t h e ' t a b l e V i e w ' c r e a t i o n a n d s e t t i n g
// t h e d a t a S o u r c e h a s t h e c o r r e c t d a t a )
view . addSubview ( tableView )
view . addSubview ( emptyStateLabel )
view . addSubview ( fadeView )
view . addSubview ( clearAllButton )
@ -135,6 +151,11 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
tableView . rightAnchor . constraint ( equalTo : view . rightAnchor ) ,
tableView . bottomAnchor . constraint ( equalTo : view . bottomAnchor ) ,
emptyStateLabel . topAnchor . constraint ( equalTo : view . topAnchor , constant : Values . massiveSpacing ) ,
emptyStateLabel . leftAnchor . constraint ( equalTo : view . leftAnchor , constant : Values . mediumSpacing ) ,
emptyStateLabel . rightAnchor . constraint ( equalTo : view . rightAnchor , constant : - Values . mediumSpacing ) ,
emptyStateLabel . centerXAnchor . constraint ( equalTo : view . centerXAnchor ) ,
fadeView . topAnchor . constraint ( equalTo : view . topAnchor , constant : ( 0.15 * view . bounds . height ) ) ,
fadeView . leftAnchor . constraint ( equalTo : view . leftAnchor ) ,
fadeView . rightAnchor . constraint ( equalTo : view . rightAnchor ) ,
@ -173,6 +194,8 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
threadViewModelCache . removeAll ( )
tableView . reloadData ( )
clearAllButton . isHidden = ( messageRequestCount = = 0 )
emptyStateLabel . isHidden = ( messageRequestCount != 0 )
emptyStateLabel . isHidden = ( messageRequestCount != 0 )
}
@objc private func handleYapDatabaseModifiedNotification ( _ yapDatabase : YapDatabase ) {
@ -245,6 +268,7 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
tableView . endUpdates ( )
clearAllButton . isHidden = ( messageRequestCount = = 0 )
emptyStateLabel . isHidden = ( messageRequestCount != 0 )
}
@objc private func handleProfileDidChangeNotification ( _ notification : Notification ) {
@ -282,17 +306,7 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
guard let thread = self . thread ( at : indexPath . row ) else { return [ ] }
let delete = UITableViewRowAction ( style : . destructive , title : NSLocalizedString ( " TXT_DELETE_TITLE " , comment : " " ) ) { [ weak self ] _ , _ in
var message = NSLocalizedString ( " CONVERSATION_DELETE_CONFIRMATION_ALERT_MESSAGE " , comment : " " )
if let thread = thread as ? TSGroupThread , thread . isClosedGroup , thread . groupModel . groupAdminIds . contains ( getUserHexEncodedPublicKey ( ) ) {
message = NSLocalizedString ( " admin_group_leave_warning " , comment : " " )
}
let alert = UIAlertController ( title : NSLocalizedString ( " CONVERSATION_DELETE_CONFIRMATION_ALERT_TITLE " , comment : " " ) , message : message , preferredStyle : . alert )
alert . addAction ( UIAlertAction ( title : NSLocalizedString ( " TXT_DELETE_TITLE " , comment : " " ) , style : . destructive ) { [ weak self ] _ in
self ? . delete ( thread )
} )
alert . addAction ( UIAlertAction ( title : NSLocalizedString ( " TXT_CANCEL_TITLE " , comment : " " ) , style : . default ) { _ in } )
guard let self = self else { return }
self . present ( alert , animated : true , completion : nil )
}
delete . backgroundColor = Colors . destructive
@ -332,6 +346,9 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
let threads : [ TSThread ] = ( 0. . < threadCount ) . compactMap { self . thread ( at : $0 ) }
var needsSync : Bool = false
let alertVC : UIAlertController = UIAlertController ( title : NSLocalizedString ( " MESSAGE_REQUESTS_CLEAR_ALL_CONFIRMATION_TITLE " , comment : " " ) , message : nil , preferredStyle : . actionSheet )
alertVC . addAction ( UIAlertAction ( title : NSLocalizedString ( " MESSAGE_REQUESTS_CLEAR_ALL_CONFIRMATION_ACTON " , comment : " " ) , style : . destructive ) { _ in
// C l e a r t h e r e q u e s t s
Storage . write (
with : { [ weak self ] transaction in
threads . forEach { thread in
@ -357,18 +374,23 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
// F o r c e a c o n f i g s y n c ( m u s t r u n o n t h e m a i n t h r e a d )
if needsSync {
DispatchQueue . main . async {
( UIApplication . shared . delegate as ? AppDelegate ) ?
. forceSyncConfigurationNowIfNeeded ( )
.retainUntilComplete ( )
if let appDelegate = UIApplication . shared . delegate as ? AppDelegate {
appDelegate . forceSyncConfigurationNowIfNeeded ( ) . retainUntilComplete ( )
}
}
}
}
)
} )
alertVC . addAction ( UIAlertAction ( title : NSLocalizedString ( " TXT_CANCEL_TITLE " , comment : " " ) , style : . cancel , handler : nil ) )
self . present ( alertVC , animated : true , completion : nil )
}
private func delete ( _ thread : TSThread ) {
guard let uniqueId : String = thread . uniqueId else { return }
let alertVC : UIAlertController = UIAlertController ( title : NSLocalizedString ( " MESSAGE_REQUESTS_DELETE_CONFIRMATION_ACTON " , comment : " " ) , message : nil , preferredStyle : . actionSheet )
alertVC . addAction ( UIAlertAction ( title : NSLocalizedString ( " TXT_DELETE_TITLE " , comment : " " ) , style : . destructive ) { _ in
Storage . write (
with : { [ weak self ] transaction in
Storage . shared . cancelPendingMessageSendJobs ( for : uniqueId , using : transaction )
@ -388,6 +410,9 @@ class MessageRequestsViewController: BaseVC, UITableViewDelegate, UITableViewDat
}
}
)
} )
alertVC . addAction ( UIAlertAction ( title : NSLocalizedString ( " TXT_CANCEL_TITLE " , comment : " " ) , style : . cancel , handler : nil ) )
self . present ( alertVC , animated : true , completion : nil )
}
// MARK: - C o n v e n i e n c e