Browse Source

add 'start chat' when there is no chat

B. Petersen 5 năm trước cách đây
mục cha
commit
cb1bea1a33

+ 6 - 6
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -146,6 +146,8 @@ class ContactDetailViewController: UITableViewController {
                 return ephemeralMessagesCell
             case .muteChat:
                 return muteChatCell
+            case .startChat:
+                return startChatCell
             }
         case .chatActions:
             switch viewModel.chatActionFor(row: row) {
@@ -156,8 +158,6 @@ class ContactDetailViewController: UITableViewController {
             case .deleteChat:
                 return deleteChatCell
             }
-        case .startChat:
-            return startChatCell
         case .sharedChats:
             if let cell = tableView.dequeueReusableCell(withIdentifier: ContactCell.reuseIdentifier, for: indexPath) as? ContactCell {
                 viewModel.update(sharedChatCell: cell, row: row)
@@ -174,9 +174,6 @@ class ContactDetailViewController: UITableViewController {
             handleAttachmentAction(for: indexPath.row)
         case .chatActions:
             handleCellAction(for: indexPath.row)
-        case .startChat:
-            let contactId = viewModel.contactId
-            chatWith(contactId: contactId)
         case .sharedChats:
             let chatId = viewModel.getSharedChatIdAt(indexPath: indexPath)
             showChat(chatId: chatId)
@@ -186,7 +183,7 @@ class ContactDetailViewController: UITableViewController {
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
         let type = viewModel.typeFor(section: indexPath.section)
         switch type {
-        case .chatActions, .startChat, .chatOptions:
+        case .chatActions, .chatOptions:
             return Constants.defaultCellHeight
         case .sharedChats:
             return ContactCell.cellHeight
@@ -241,6 +238,9 @@ class ContactDetailViewController: UITableViewController {
             } else {
                 showMuteAlert()
             }
+        case .startChat:
+            let contactId = viewModel.contactId
+            chatWith(contactId: contactId)
         }
     }
 

+ 3 - 5
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -6,7 +6,6 @@ class ContactDetailViewModel {
     let context: DcContext
 
     enum ProfileSections {
-        case startChat
         case chatOptions
         case sharedChats
         case chatActions
@@ -17,6 +16,7 @@ class ContactDetailViewModel {
         case documents
         case ephemeralMessages
         case muteChat
+        case startChat
     }
 
     enum ChatAction {
@@ -44,20 +44,19 @@ class ContactDetailViewModel {
         self.sharedChats = context.getChatlist(flags: 0, queryString: nil, queryId: contactId)
 
         sections.append(.chatOptions)
-        sections.append(.startChat)
         if sharedChats.length > 0 {
             sections.append(.sharedChats)
         }
         sections.append(.chatActions)
 
         if chatId != 0 {
-            chatOptions = [.gallery, .documents, .muteChat]
+            chatOptions = [.gallery, .documents, .muteChat, .startChat]
             chatActions = [.archiveChat, .blockContact, .deleteChat]
             if UserDefaults.standard.bool(forKey: "ephemeral_messages") || dcContext.getChatEphemeralTimer(chatId: chatId) > 0 {
                 chatOptions.insert(.ephemeralMessages, at: 2)
             }
         } else {
-            chatOptions = [.gallery, .documents]
+            chatOptions = [.gallery, .documents, .startChat]
             chatActions = [.blockContact]
         }
     }
@@ -90,7 +89,6 @@ class ContactDetailViewModel {
         switch sections[section] {
         case .chatOptions: return chatOptions.count
         case .sharedChats: return sharedChats.length
-        case .startChat: return 1
         case .chatActions: return chatActions.count
         }
     }