|
@@ -7,6 +7,7 @@ protocol ContactDetailViewModelProtocol {
|
|
var chatIsArchived: Bool { get }
|
|
var chatIsArchived: Bool { get }
|
|
func numberOfRowsInSection(_ : Int) -> Int
|
|
func numberOfRowsInSection(_ : Int) -> Int
|
|
func typeFor(section: Int) -> ContactDetailViewModel.ProfileSections
|
|
func typeFor(section: Int) -> ContactDetailViewModel.ProfileSections
|
|
|
|
+ func actionFor(row: Int) -> ContactDetailViewModel.ChatAction
|
|
func update(sharedChatCell: ContactCell, row index: Int)
|
|
func update(sharedChatCell: ContactCell, row index: Int)
|
|
func getSharedChatIdAt(indexPath: IndexPath) -> Int
|
|
func getSharedChatIdAt(indexPath: IndexPath) -> Int
|
|
func titleFor(section: Int) -> String?
|
|
func titleFor(section: Int) -> String?
|
|
@@ -22,6 +23,12 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
|
|
case chatActions // archive chat, block chat, delete chats
|
|
case chatActions // archive chat, block chat, delete chats
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ enum ChatAction {
|
|
|
|
+ case archiveChat
|
|
|
|
+ case blockChat
|
|
|
|
+ case deleteChat
|
|
|
|
+ }
|
|
|
|
+
|
|
var contactId: Int
|
|
var contactId: Int
|
|
|
|
|
|
var contact: DcContact
|
|
var contact: DcContact
|
|
@@ -29,6 +36,7 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
|
|
private let sharedChats: DcChatlist
|
|
private let sharedChats: DcChatlist
|
|
private let startChatOption: Bool
|
|
private let startChatOption: Bool
|
|
private var sections: [ProfileSections] = []
|
|
private var sections: [ProfileSections] = []
|
|
|
|
+ private var actions: [ChatAction] = [] // chatDetail: archive, block, delete - else: block
|
|
|
|
|
|
/// if chatId is nil this is a contact detail with 'start chat'-option
|
|
/// if chatId is nil this is a contact detail with 'start chat'-option
|
|
init(contactId: Int, chatId: Int?, context: DcContext) {
|
|
init(contactId: Int, chatId: Int?, context: DcContext) {
|
|
@@ -46,15 +54,26 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
|
|
sections.append(.sharedChats)
|
|
sections.append(.sharedChats)
|
|
}
|
|
}
|
|
sections.append(.chatActions)
|
|
sections.append(.chatActions)
|
|
|
|
+
|
|
|
|
+ if chatId != nil {
|
|
|
|
+ actions = [.archiveChat, .blockChat, .deleteChat]
|
|
|
|
+ } else {
|
|
|
|
+ actions = [.blockChat]
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
func typeFor(section: Int) -> ContactDetailViewModel.ProfileSections {
|
|
func typeFor(section: Int) -> ContactDetailViewModel.ProfileSections {
|
|
return sections[section]
|
|
return sections[section]
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func actionFor(row: Int) -> ContactDetailViewModel.ChatAction {
|
|
|
|
+ return actions[row]
|
|
|
|
+ }
|
|
|
|
+
|
|
var chatIsArchived: Bool {
|
|
var chatIsArchived: Bool {
|
|
guard let chatId = chatId else {
|
|
guard let chatId = chatId else {
|
|
- safe_fatalError("This is a ContactDetail view with no chat id")
|
|
|
|
|
|
+ // safe_fatalError("This is a ContactDetail view with no chat id")
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
return DcChat(id: chatId).isArchived
|
|
return DcChat(id: chatId).isArchived
|
|
@@ -68,7 +87,7 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
|
|
switch sections[section] {
|
|
switch sections[section] {
|
|
case .sharedChats: return sharedChats.length
|
|
case .sharedChats: return sharedChats.length
|
|
case .startChat: return 1
|
|
case .startChat: return 1
|
|
- case .chatActions: return 3
|
|
|
|
|
|
+ case .chatActions: return actions.count
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|