@ -9,7 +9,7 @@ import SessionMessagingKit
import SessionUtilitiesKit
import SignalUtilitiesKit
final class ConversationVC : BaseVC , ConversationSearchControllerDelegate, UITableViewDataSource , UITableViewDelegate {
final class ConversationVC : BaseVC , SessionUtilRespondingViewController, ConversationSearchControllerDelegate, UITableViewDataSource , UITableViewDelegate {
private static let loadingHeaderHeight : CGFloat = 40
internal let viewModel : ConversationViewModel
@ -211,8 +211,14 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
private lazy var emptyStateLabel : UILabel = {
let text : String = String (
format : " CONVERSATION_EMPTY_STATE " . localized ( ) ,
self . viewModel . threadData . displayName
format : {
switch ( viewModel . threadData . threadIsNoteToSelf , viewModel . threadData . canWrite ) {
case ( true , _ ) : return " CONVERSATION_EMPTY_STATE_NOTE_TO_SELF " . localized ( )
case ( _ , false ) : return " CONVERSATION_EMPTY_STATE_READ_ONLY " . localized ( )
default : return " CONVERSATION_EMPTY_STATE " . localized ( )
}
} ( ) ,
viewModel . threadData . displayName
)
let result : UILabel = UILabel ( )
@ -385,8 +391,16 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
// n a v w i l l b e o f f s e t i n c o r r e c t l y d u r i n g t h e p u s h a n i m a t i o n ( u n f o r t u n a t e l y t h e p r o f i l e i c o n s t i l l
// d o e s n ' t a p p e a r u n t i l a f t e r t h e a n i m a t i o n , I a s s u m e i t ' s t a k i n g a s n a p s h o t o r s o m e t h i n g , b u t
// t h e r e i s n ' t m u c h w e c a n d o a b o u t t h a t u n f o r t u n a t e l y )
updateNavBarButtons ( threadData : nil , initialVariant : self . viewModel . initialThreadVariant )
titleView . initialSetup ( with : self . viewModel . initialThreadVariant )
updateNavBarButtons (
threadData : nil ,
initialVariant : self . viewModel . initialThreadVariant ,
initialIsNoteToSelf : self . viewModel . threadData . threadIsNoteToSelf ,
initialIsBlocked : ( self . viewModel . threadData . threadIsBlocked = = true )
)
titleView . initialSetup (
with : self . viewModel . initialThreadVariant ,
isNoteToSelf : self . viewModel . threadData . threadIsNoteToSelf
)
// C o n s t r a i n t s
view . addSubview ( tableView )
@ -533,6 +547,7 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
let threadId : String = viewModel . threadData . threadId
if
viewModel . threadData . threadIsNoteToSelf = = false &&
viewModel . threadData . threadShouldBeVisible = = false &&
! SessionUtil . conversationExistsInConfig (
threadId : threadId ,
@ -674,9 +689,16 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
// U p d a t e t h e e m p t y s t a t e
let text : String = String (
format : " CONVERSATION_EMPTY_STATE " . localized ( ) ,
format : {
switch ( updatedThreadData . threadIsNoteToSelf , updatedThreadData . canWrite ) {
case ( true , _ ) : return " CONVERSATION_EMPTY_STATE_NOTE_TO_SELF " . localized ( )
case ( _ , false ) : return " CONVERSATION_EMPTY_STATE_READ_ONLY " . localized ( )
default : return " CONVERSATION_EMPTY_STATE " . localized ( )
}
} ( ) ,
updatedThreadData . displayName
)
emptyStateLabel . attributedText = NSAttributedString ( string : text )
. adding (
attributes : [ . font : UIFont . boldSystemFont ( ofSize : Values . verySmallFontSize ) ] ,
@ -689,11 +711,17 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
if
initialLoad ||
viewModel . threadData . threadVariant != updatedThreadData . threadVariant ||
viewModel . threadData . threadIsBlocked != updatedThreadData . threadIsBlocked ||
viewModel . threadData . threadRequiresApproval != updatedThreadData . threadRequiresApproval ||
viewModel . threadData . threadIsMessageRequest != updatedThreadData . threadIsMessageRequest ||
viewModel . threadData . profile != updatedThreadData . profile
{
updateNavBarButtons ( threadData : updatedThreadData , initialVariant : viewModel . initialThreadVariant )
updateNavBarButtons (
threadData : updatedThreadData ,
initialVariant : viewModel . initialThreadVariant ,
initialIsNoteToSelf : viewModel . threadData . threadIsNoteToSelf ,
initialIsBlocked : ( viewModel . threadData . threadIsBlocked = = true )
)
let messageRequestsViewWasVisible : Bool = (
messageRequestStackView . isHidden = = false
@ -1139,7 +1167,12 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
}
}
func updateNavBarButtons ( threadData : SessionThreadViewModel ? , initialVariant : SessionThread . Variant ) {
func updateNavBarButtons (
threadData : SessionThreadViewModel ? ,
initialVariant : SessionThread . Variant ,
initialIsNoteToSelf : Bool ,
initialIsBlocked : Bool
) {
navigationItem . hidesBackButton = isShowingSearchUI
if isShowingSearchUI {
@ -1147,6 +1180,13 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
navigationItem . rightBarButtonItems = [ ]
}
else {
let shouldHaveCallButton : Bool = (
SessionCall . isEnabled &&
( threadData ? . threadVariant ? ? initialVariant ) = = . contact &&
( threadData ? . threadIsNoteToSelf ? ? initialIsNoteToSelf ) = = false &&
( threadData ? . threadIsBlocked ? ? initialIsBlocked ) = = false
)
guard
let threadData : SessionThreadViewModel = threadData ,
(
@ -1169,7 +1209,7 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
)
)
) ,
( initialVariant = = . contact ?
( shouldHaveCallButton ?
UIBarButtonItem ( customView : UIView ( frame : CGRect ( x : 0 , y : 0 , width : 44 , height : 44 ) ) ) :
nil
)
@ -1199,7 +1239,7 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
settingsButtonItem . accessibilityLabel = " More options "
settingsButtonItem . isAccessibilityElement = true
if SessionCall. isEnabled && ! threadData . threadIsNoteToSelf {
if shouldHaveCallButton {
let callButton = UIBarButtonItem (
image : UIImage ( named : " Phone " ) ,
style : . plain ,
@ -1207,11 +1247,12 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
action : #selector ( startCall )
)
callButton . accessibilityLabel = " Call button "
callButton . isAccessibilityElement = true
navigationItem . rightBarButtonItems = [ settingsButtonItem , callButton ]
}
else {
navigationItem . rightBarButtonItem = settingsButtonItem
navigationItem . rightBarButtonItem s = [ settingsButtonItem ]
}
default :
@ -1640,7 +1681,12 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
}
// N a v b a r b u t t o n s
updateNavBarButtons ( threadData : self . viewModel . threadData , initialVariant : viewModel . initialThreadVariant )
updateNavBarButtons (
threadData : viewModel . threadData ,
initialVariant : viewModel . initialThreadVariant ,
initialIsNoteToSelf : viewModel . threadData . threadIsNoteToSelf ,
initialIsBlocked : ( viewModel . threadData . threadIsBlocked = = true )
)
// H a c k s o t h a t t h e R e s u l t s B a r s t a y s o n t h e s c r e e n w h e n d i s m i s s i n g t h e s e a r c h f i e l d
// k e y b o a r d .
@ -1675,7 +1721,12 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
@objc func hideSearchUI ( ) {
isShowingSearchUI = false
navigationItem . titleView = titleView
updateNavBarButtons ( threadData : self . viewModel . threadData , initialVariant : viewModel . initialThreadVariant )
updateNavBarButtons (
threadData : viewModel . threadData ,
initialVariant : viewModel . initialThreadVariant ,
initialIsNoteToSelf : viewModel . threadData . threadIsNoteToSelf ,
initialIsBlocked : ( viewModel . threadData . threadIsBlocked = = true )
)
searchController . uiSearchController . stubbableSearchBar . stubbedNextResponder = nil
becomeFirstResponder ( )
@ -1800,4 +1851,10 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
. highlight ( )
}
}
// MARK: - S e s s i o n U t i l R e s p o n d i n g V i e w C o n t r o l l e r
func isConversation ( in threadIds : [ String ] ) -> Bool {
return threadIds . contains ( self . viewModel . threadData . threadId )
}
}