Browse Source

chatViewModel now sets title and subtitle correctly

nayooti 5 years ago
parent
commit
98152e3ddc

+ 1 - 39
deltachat-ios/Controller/ChatListController.swift

@@ -275,45 +275,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
     }
 
     private func update(avatarCell cell: ContactCell, cellViewModel: AvatarCellViewModel) {
-        switch cellViewModel.type {
-        case .CHAT(let chatData):
-            let chatId = chatData.chatId
-            let summary = chatData.summary
-            let unreadMessages = chatData.unreadMessages
-            let chat = DcChat(id: chatId)
-            cell.nameLabel.attributedText = (unreadMessages > 0) ?
-                NSAttributedString(string: chat.name, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ]) :
-                NSAttributedString(string: chat.name, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .medium) ])
-            if let img = chat.profileImage {
-                cell.resetBackupImage()
-                cell.setImage(img)
-            } else {
-                cell.setBackupImage(name: chat.name, color: chat.color)
-            }
-
-            cell.setVerified(isVerified: chat.isVerified)
-
-            let result1 = summary.text1 ?? ""
-            let result2 = summary.text2 ?? ""
-            let result: String
-            if !result1.isEmpty, !result2.isEmpty {
-                result = "\(result1): \(result2)"
-            } else {
-                result = "\(result1)\(result2)"
-            }
-
-            cell.emailLabel.text = result
-            cell.setTimeLabel(summary.timestamp)
-            cell.setUnreadMessageCounter(unreadMessages)
-            cell.setDeliveryStatusIndicator(summary.state)
-        case .CONTACT(let contactData):
-            let contactId = contactData.contactId
-            cell.updateCell(cellViewModel: cellViewModel)
-        }
-    }
-
-    private func showStartChatConfirmationAlert(chatId: Int) {
-
+        cell.updateCell(cellViewModel: cellViewModel)
     }
 
     private func showDeleteChatConfirmationAlert(chatId: Int) {

+ 22 - 4
deltachat-ios/View/ContactCell.swift

@@ -195,16 +195,34 @@ class ContactCell: UITableViewCell {
 
     func updateCell(cellViewModel: AvatarCellViewModel) {
 
-        // title
-        nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
         // subtitle
         emailLabel.attributedText = cellViewModel.subtitle.boldAt(indexes: cellViewModel.subtitleHighlightIndexes, fontSize: emailLabel.font.pointSize)
 
         switch cellViewModel.type {
         case .CHAT(let chatData):
-            break
+            let chat = DcChat(id: chatData.chatId)
+
+            // text bold if chat contains unread messages - otherwise hightlight search results if needed
+            if chatData.unreadMessages > 0 {
+                nameLabel.attributedText = NSAttributedString(string: cellViewModel.title, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ])
+            } else {
+                nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
+            }
+
+            if let img = chat.profileImage {
+                resetBackupImage()
+                setImage(img)
+            } else {
+              setBackupImage(name: chat.name, color: chat.color)
+            }
+            setVerified(isVerified: chat.isVerified)
+            setTimeLabel(chatData.summary.timestamp)
+            setUnreadMessageCounter(chatData.unreadMessages)
+            setDeliveryStatusIndicator(chatData.summary.state)
+
         case .CONTACT(let contactData):
-            break
+            nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
+
         }
     }
 

+ 12 - 2
deltachat-ios/ViewModel/ChatListViewModel.swift

@@ -73,14 +73,23 @@ class ContactCellViewModel: AvatarCellViewModel {
 
 class ChatCellViewModel: AvatarCellViewModel{
 
+    private let chat: DcChat
     private let summary: DcLot
 
     var type: CellModel
     var title: String {
-        return summary.text1 ?? ""
+        return chat.name
     }
     var subtitle: String {
-        return summary.text2 ?? ""
+        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 avartarTitle: String {
@@ -95,6 +104,7 @@ class ChatCellViewModel: AvatarCellViewModel{
         self.titleHighlightIndexes = titleHighlightIndexes
         self.subtitleHighlightIndexes = subtitleHighlightIndexes
         self.summary = chatData.summary
+        self.chat = DcChat(id: chatData.chatId)
     }
 }