@ -273,24 +273,28 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
// S e p a r a t e o u t t h e c h a n g e s f o r n e w m e s s a g e r e q u e s t s a n d t h e i n b o x ( s o w e c a n a v o i d u p d a t i n g f o r
// n e w m e s s a g e s w i t h i n a n e x i s t i n g m e s s a g e r e q u e s t )
let messageRequest Insert s = rowChanges
let messageRequest Change s = rowChanges
. compactMap { $0 as ? YapDatabaseViewRowChange }
. filter { $0 . finalGroup = = TSMessageRequestGroup && $0 . type = = . insert }
. filter { $0 . originalGroup = = TSMessageRequestGroup || $0 . finalGroup = = TSMessageRequestGroup }
let inboxRowChanges = rowChanges
. filter { ( $0 as ? YapDatabaseViewRowChange ) ? . finalGroup != TSMessageRequestGroup }
. compactMap { $0 as ? YapDatabaseViewRowChange }
. filter { $0 . originalGroup = = TSInboxGroup || $0 . finalGroup = = TSInboxGroup }
guard sectionChanges . count > 0 || inboxRowChanges . count > 0 || messageRequest Insert s. count > 0 else { return }
guard sectionChanges . count > 0 || inboxRowChanges . count > 0 || messageRequest Change s. count > 0 else { return }
tableView . beginUpdates ( )
// 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 ! messageRequestInserts . isEmpty && ( CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] || tableView . numberOfRows ( inSection : 0 ) = = 0 ) {
CurrentAppContext ( ) . appUserDefaults ( ) [ . hasHiddenMessageRequests ] = false
tableView . insertRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
if ! messageRequestChanges . isEmpty {
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 )
}
}
inboxRowChanges . forEach { rowChange in
let rowChange = rowChange as ! YapDatabaseViewRowChange
let key = rowChange . collectionKey . key
threadViewModelCache [ key ] = nil
@ -310,12 +314,9 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
// a n i n s e r t a s t h e c h a n g e w o n ' t b e d e f i n e d c o r r e c t l y )
if rowChange . originalGroup = = TSMessageRequestGroup && rowChange . finalGroup = = TSInboxGroup {
tableView . insertRows ( at : [ rowChange . newIndexPath ! ] , with : . automatic )
// I f t h a t w a s t h e l a s t m e s s a g e r e q u e s t t h e n w e n e e d t o a l s o r e m o v e t h e m e s s a g e r e q u e s t
// r o w t o p r e v e n t a c r a s h
if messageRequestCount = = 0 {
tableView . deleteRows ( at : [ IndexPath ( row : 0 , section : 0 ) ] , with : . automatic )
}
}
else if rowChange . originalGroup = = TSInboxGroup && rowChange . finalGroup = = TSMessageRequestGroup {
tableView . deleteRows ( at : [ rowChange . indexPath ! ] , with : . automatic )
}
default : break
@ -336,7 +337,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
case . move :
// S i n c e w e a r e c u s t o m h a n d l i n g t h i s s p e c i f i c m o v e m e n t i n t h e a b o v e ' u p d a t e s ' c a l l w e n e e d
// t o a v o i d t r y i n g t o h a n d l e i t h e r e
if rowChange . originalGroup = = TSMessageRequestGroup && rowChange . finalGroup = = TSInbox Group {
if rowChange . originalGroup = = TSMessageRequestGroup || rowChange . finalGroup = = TSMessageRequest Group {
return
}