|
@@ -1,31 +1,7 @@
|
|
|
import UIKit
|
|
|
|
|
|
-protocol AvatarCellViewModel {
|
|
|
- var type: CellModel { get }
|
|
|
- var title: String { get }
|
|
|
- var titleHighlightIndexes: [Int] { get }
|
|
|
- var subtitle: String { get }
|
|
|
- var subtitleHighlightIndexes: [Int] { get }
|
|
|
-}
|
|
|
-
|
|
|
-enum CellModel {
|
|
|
- case CONTACT(ContactCellData)
|
|
|
- case CHAT(ChatCellData)
|
|
|
-}
|
|
|
-
|
|
|
-struct ContactCellData {
|
|
|
- let contactId: Int
|
|
|
-}
|
|
|
-
|
|
|
-struct ChatCellData {
|
|
|
- let chatId: Int
|
|
|
- let summary: DcLot
|
|
|
- let unreadMessages: Int
|
|
|
-}
|
|
|
-
|
|
|
protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
|
|
|
var numberOfSections: Int { get }
|
|
|
-
|
|
|
var onChatListUpdate: VoidFunction? { get set }
|
|
|
var showArchive: Bool { get }
|
|
|
var archivedChatsCount: Int { get }
|
|
@@ -36,71 +12,10 @@ protocol ChatListViewModelProtocol: class, UISearchResultsUpdating {
|
|
|
func getCellViewModelFor(indexPath: IndexPath) -> AvatarCellViewModel
|
|
|
func beginFiltering()
|
|
|
func endFiltering()
|
|
|
-
|
|
|
func archieveChat(chatId: Int)
|
|
|
func deleteChat(chatId: Int)
|
|
|
}
|
|
|
|
|
|
-class ContactCellViewModel: AvatarCellViewModel {
|
|
|
-
|
|
|
- private let contact: DcContact
|
|
|
-
|
|
|
- var type: CellModel
|
|
|
- var title: String {
|
|
|
- return contact.displayName
|
|
|
- }
|
|
|
- var subtitle: String {
|
|
|
- return contact.email
|
|
|
- }
|
|
|
-
|
|
|
- var avartarTitle: String {
|
|
|
- return Utils.getInitials(inputName: title)
|
|
|
- }
|
|
|
-
|
|
|
- var titleHighlightIndexes: [Int]
|
|
|
- var subtitleHighlightIndexes: [Int]
|
|
|
-
|
|
|
- init(contactData: ContactCellData, titleHighlightIndexes: [Int] = [], subtitleHighlightIndexes: [Int] = []) {
|
|
|
- type = CellModel.CONTACT(contactData)
|
|
|
- self.titleHighlightIndexes = titleHighlightIndexes
|
|
|
- self.subtitleHighlightIndexes = subtitleHighlightIndexes
|
|
|
- self.contact = DcContact(id: contactData.contactId)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class ChatCellViewModel: AvatarCellViewModel{
|
|
|
-
|
|
|
- private let chat: DcChat
|
|
|
- private let summary: DcLot
|
|
|
-
|
|
|
- var type: CellModel
|
|
|
- var title: String {
|
|
|
- return chat.name
|
|
|
- }
|
|
|
- var subtitle: String {
|
|
|
- let result1 = summary.text1 ?? ""
|
|
|
- let result2 = summary.text2 ?? ""
|
|
|
- let result: String
|
|
|
- if !result1.isEmpty, !result2.isEmpty {
|
|
|
- result = "\(result1): \(result2)"
|
|
|
- } else {
|
|
|
- result = "\(result1)\(result2)"
|
|
|
- }
|
|
|
- return result
|
|
|
- }
|
|
|
-
|
|
|
- var titleHighlightIndexes: [Int]
|
|
|
- var subtitleHighlightIndexes: [Int]
|
|
|
-
|
|
|
- init(chatData: ChatCellData, titleHighlightIndexes: [Int] = [], subtitleHighlightIndexes: [Int] = []) {
|
|
|
- self.type = CellModel.CHAT(chatData)
|
|
|
- self.titleHighlightIndexes = titleHighlightIndexes
|
|
|
- self.subtitleHighlightIndexes = subtitleHighlightIndexes
|
|
|
- self.summary = chatData.summary
|
|
|
- self.chat = DcChat(id: chatData.chatId)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
class ChatListViewModel: NSObject, ChatListViewModelProtocol {
|
|
|
func titleForHeaderIn(section: Int) -> String? {
|
|
|
if searchActive {
|