@ -6,6 +6,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
private var threads : YapDatabaseViewMappings !
private var threadViewModelCache : [ String : ThreadViewModel ] = [ : ] // T h r e a d I D t o T h r e a d V i e w M o d e l
private var tableViewTopConstraint : NSLayoutConstraint !
private var unreadMessageRequestCount : UInt = 0
private var messageRequestCount : UInt {
threads . numberOfItems ( inGroup : TSMessageRequestGroup )
@ -196,7 +197,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
switch indexPath . section {
case 0 :
let cell = tableView . dequeueReusableCell ( withIdentifier : MessageRequestsCell . reuseIdentifier ) as ! MessageRequestsCell
cell . update ( with : Int ( m essageRequestCount) )
cell . update ( with : Int ( unreadM essageRequestCount) )
return cell
default :
@ -263,6 +264,14 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
}
}
// U p d a t e t h e n u m b e r o f u n r e a d m e s s a g e r e q u e s t s
unreadMessageRequestCount = OWSMessageUtils . sharedManager ( ) . unreadMessageRequestCount ( )
// I f t h e r e a r e n o u n r e a d m e s s a g e r e q u e s t s t h e n h i d e t h e m e s s a g e r e q u e s t b a n n e r
if unreadMessageRequestCount = = 0 {
CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] = true
}
return reload ( )
}
}
@ -286,11 +295,21 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
// I f w e n e e d t o u n h i d e t h e m e s s a g e r e q u e s t r o w a n d t h e n r e - i n s e r t i t
if ! messageRequestChanges . isEmpty {
if tableView . numberOfRows ( inSection : 0 ) = = 1 && Int ( messageRequestCount ) <= 0 {
// U p d a t e t h e n u m b e r o f u n r e a d m e s s a g e r e q u e s t s
unreadMessageRequestCount = OWSMessageUtils . sharedManager ( ) . unreadMessageRequestCount ( )
// I f t h e r e a r e n o u n r e a d m e s s a g e r e q u e s t s t h e n h i d e t h e m e s s a g e r e q u e s t b a n n e r
if unreadMessageRequestCount = = 0 && tableView . numberOfRows ( inSection : 0 ) = = 1 {
CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] = true
tableView . deleteRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
}
else if tableView . numberOfRows ( inSection : 0 ) = = 0 && Int ( messageRequestCount ) > 0 && ! CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] {
tableView . insertRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
else {
if tableView . numberOfRows ( inSection : 0 ) = = 1 && Int ( messageRequestCount ) <= 0 {
tableView . deleteRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
}
else if tableView . numberOfRows ( inSection : 0 ) = = 0 && Int ( messageRequestCount ) > 0 && ! CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] {
tableView . insertRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
}
}
}