Parcourir la source

Merge pull request #832 from deltachat/tweak-disappearing

tweak profile
cyBerta il y a 5 ans
Parent
commit
9b5e890095

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

@@ -136,19 +136,21 @@ class ContactDetailViewController: UITableViewController {
         let row = indexPath.row
         let cellType = viewModel.typeFor(section: indexPath.section)
         switch cellType {
-        case .attachments:
-            switch viewModel.attachmentActionFor(row: row) {
+        case .chatOptions:
+            switch viewModel.chatOptionFor(row: row) {
             case .documents:
                 return documentsCell
             case .gallery:
                 return galleryCell
-            }
-        case .chatActions:
-            switch viewModel.chatActionFor(row: row) {
             case .ephemeralMessages:
                 return ephemeralMessagesCell
             case .muteChat:
                 return muteChatCell
+            case .startChat:
+                return startChatCell
+            }
+        case .chatActions:
+            switch viewModel.chatActionFor(row: row) {
             case .archiveChat:
                 return archiveChatCell
             case .blockContact:
@@ -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)
@@ -170,13 +170,10 @@ class ContactDetailViewController: UITableViewController {
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         let type = viewModel.typeFor(section: indexPath.section)
         switch type {
-        case .attachments:
-            handleAttachmentAction(for: indexPath.row)
+        case .chatOptions:
+            handleChatOption(for: indexPath.row)
         case .chatActions:
-            handleCellAction(for: indexPath.row)
-        case .startChat:
-            let contactId = viewModel.contactId
-            chatWith(contactId: contactId)
+            handleChatAction(for: indexPath.row)
         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, .attachments:
+        case .chatActions, .chatOptions:
             return Constants.defaultCellHeight
         case .sharedChats:
             return ContactCell.cellHeight
@@ -213,18 +210,9 @@ class ContactDetailViewController: UITableViewController {
     }
 
     // MARK: - actions
-    private func handleCellAction(for index: Int) {
+    private func handleChatAction(for index: Int) {
         let action = viewModel.chatActionFor(row: index)
         switch action {
-        case .ephemeralMessages:
-            showEphemeralMessagesController()
-        case .muteChat:
-            if viewModel.chatIsMuted {
-                self.viewModel.context.setChatMuteDuration(chatId: self.viewModel.chatId, duration: 0)
-                muteChatCell.actionTitle = String.localized("menu_mute")
-            } else {
-                showMuteAlert()
-            }
         case .archiveChat:
             toggleArchiveChat()
         case .blockContact:
@@ -234,13 +222,25 @@ class ContactDetailViewController: UITableViewController {
         }
     }
 
-    private func handleAttachmentAction(for index: Int) {
-        let action = viewModel.attachmentActionFor(row: index)
+    private func handleChatOption(for index: Int) {
+        let action = viewModel.chatOptionFor(row: index)
         switch action {
         case .documents:
             showDocuments()
         case .gallery:
             showGallery()
+        case .ephemeralMessages:
+            showEphemeralMessagesController()
+        case .muteChat:
+            if viewModel.chatIsMuted {
+                self.viewModel.context.setChatMuteDuration(chatId: self.viewModel.chatId, duration: 0)
+                muteChatCell.actionTitle = String.localized("menu_mute")
+            } else {
+                showMuteAlert()
+            }
+        case .startChat:
+            let contactId = viewModel.contactId
+            chatWith(contactId: contactId)
         }
     }
 

+ 40 - 31
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -4,36 +4,43 @@ import DcCore
 class GroupChatDetailViewController: UIViewController {
 
     enum ProfileSections {
-        case attachments
+        case chatOptions
         case members
         case chatActions
     }
 
-    enum ChatAction {
+    enum ChatOption {
+        case gallery
+        case documents
         case ephemeralMessages
         case muteChat
+    }
+
+    enum ChatAction {
         case archiveChat
         case leaveGroup
         case deleteChat
     }
 
-    private lazy var chatActions: [ChatAction] = {
-        var actions: [ChatAction] = [.muteChat, .archiveChat, .leaveGroup, .deleteChat]
+    private lazy var chatOptions: [ChatOption] = {
+        var options: [ChatOption] = [.gallery, .documents, .muteChat]
         if UserDefaults.standard.bool(forKey: "ephemeral_messages") || dcContext.getChatEphemeralTimer(chatId: chatId) > 0 {
-            actions.insert(.ephemeralMessages, at: 0)
+            options.insert(.ephemeralMessages, at: 2)
         }
-        return actions
+        return options
+    }()
+
+    private lazy var chatActions: [ChatAction] = {
+        return [.archiveChat, .leaveGroup, .deleteChat]
     }()
 
-    private let attachmentsRowGallery = 0
-    private let attachmentsRowDocuments = 1
     private let membersRowAddMembers = 0
     private let membersRowQrInvite = 1
     private let memberManagementRows = 2
 
     private let dcContext: DcContext
 
-    private let sections: [ProfileSections] = [.attachments, .members, .chatActions]
+    private let sections: [ProfileSections] = [.chatOptions, .members, .chatActions]
 
     private var currentUser: DcContact? {
         let myId = groupMemberIds.filter { DcContact(id: $0).email == dcContext.addr }.first
@@ -287,8 +294,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
     func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
         let sectionType = sections[section]
         switch sectionType {
-        case .attachments:
-            return 2
+        case .chatOptions:
+            return chatOptions.count
         case .members:
             return groupMemberIds.count + memberManagementRows
         case .chatActions:
@@ -300,7 +307,7 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let sectionType = sections[indexPath.section]
         let row = indexPath.row
         switch sectionType {
-        case .attachments, .chatActions:
+        case .chatOptions, .chatActions:
             return Constants.defaultCellHeight
         case .members:
             switch row {
@@ -316,11 +323,16 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
         let sectionType = sections[indexPath.section]
         switch sectionType {
-        case .attachments:
-            if row == attachmentsRowGallery {
+        case .chatOptions:
+            switch chatOptions[row] {
+            case .gallery:
                 return galleryCell
-            } else if row == attachmentsRowDocuments {
+            case .documents:
                 return documentsCell
+            case .ephemeralMessages:
+                return ephemeralMessagesCell
+            case .muteChat:
+                return muteChatCell
             }
         case .members:
             if row == membersRowAddMembers || row == membersRowQrInvite {
@@ -352,10 +364,6 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             return contactCell
         case .chatActions:
             switch chatActions[row] {
-            case .ephemeralMessages:
-                return ephemeralMessagesCell
-            case .muteChat:
-                return muteChatCell
             case .archiveChat:
                 return archiveChatCell
             case .leaveGroup:
@@ -373,11 +381,21 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
         let row = indexPath.row
 
         switch sectionType {
-        case .attachments:
-            if row == attachmentsRowGallery {
+        case .chatOptions:
+            switch chatOptions[row] {
+            case .gallery:
                 showGallery()
-            } else if row == attachmentsRowDocuments {
+            case .documents:
                 showDocuments()
+            case .ephemeralMessages:
+                showEphemeralMessagesController()
+            case .muteChat:
+                if chat.isMuted {
+                    dcContext.setChatMuteDuration(chatId: chatId, duration: 0)
+                    muteChatCell.actionTitle = String.localized("menu_mute")
+                } else {
+                    showMuteAlert()
+                }
             }
         case .members:
             if row == membersRowAddMembers {
@@ -390,15 +408,6 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
             }
         case .chatActions:
             switch chatActions[row] {
-            case .ephemeralMessages:
-                showEphemeralMessagesController()
-            case .muteChat:
-                if chat.isMuted {
-                    dcContext.setChatMuteDuration(chatId: chatId, duration: 0)
-                    muteChatCell.actionTitle = String.localized("menu_mute")
-                } else {
-                    showMuteAlert()
-                }
             case .archiveChat:
                 toggleArchiveChat()
             case .leaveGroup:

+ 18 - 18
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -6,25 +6,25 @@ class ContactDetailViewModel {
     let context: DcContext
 
     enum ProfileSections {
-        case startChat
-        case attachments
+        case chatOptions
         case sharedChats
-        case chatActions //  archive chat, block chat, delete chats
+        case chatActions
     }
 
-    enum ChatAction {
+    enum ChatOption {
+        case gallery
+        case documents
         case ephemeralMessages
         case muteChat
+        case startChat
+    }
+
+    enum ChatAction {
         case archiveChat
         case blockContact
         case deleteChat
     }
 
-    enum AttachmentAction {
-        case gallery
-        case documents
-    }
-
     var contactId: Int
 
     var contact: DcContact {
@@ -35,7 +35,7 @@ class ContactDetailViewModel {
     private let sharedChats: DcChatlist
     private var sections: [ProfileSections] = []
     private var chatActions: [ChatAction] = []
-    private var attachmentActions: [AttachmentAction] = [.gallery, .documents]
+    private var chatOptions: [ChatOption] = []
 
     init(dcContext: DcContext, contactId: Int) {
         self.context = dcContext
@@ -43,19 +43,20 @@ class ContactDetailViewModel {
         self.chatId = dcContext.getChatIdByContactId(contactId: contactId)
         self.sharedChats = context.getChatlist(flags: 0, queryString: nil, queryId: contactId)
 
-        sections.append(.attachments)
-        sections.append(.startChat)
+        sections.append(.chatOptions)
         if sharedChats.length > 0 {
             sections.append(.sharedChats)
         }
         sections.append(.chatActions)
 
         if chatId != 0 {
-            chatActions = [.muteChat, .archiveChat, .blockContact, .deleteChat]
+            chatOptions = [.gallery, .documents, .muteChat, .startChat]
+            chatActions = [.archiveChat, .blockContact, .deleteChat]
             if UserDefaults.standard.bool(forKey: "ephemeral_messages") || dcContext.getChatEphemeralTimer(chatId: chatId) > 0 {
-                chatActions.insert(.ephemeralMessages, at: 0)
+                chatOptions.insert(.ephemeralMessages, at: 2)
             }
         } else {
+            chatOptions = [.gallery, .documents, .startChat]
             chatActions = [.blockContact]
         }
     }
@@ -68,8 +69,8 @@ class ContactDetailViewModel {
         return chatActions[row]
     }
 
-    func attachmentActionFor(row: Int) -> ContactDetailViewModel.AttachmentAction {
-        return attachmentActions[row]
+    func chatOptionFor(row: Int) -> ContactDetailViewModel.ChatOption {
+        return chatOptions[row]
     }
 
     var chatIsArchived: Bool {
@@ -86,9 +87,8 @@ class ContactDetailViewModel {
 
     func numberOfRowsInSection(_ section: Int) -> Int {
         switch sections[section] {
-        case .attachments: return 2
+        case .chatOptions: return chatOptions.count
         case .sharedChats: return sharedChats.length
-        case .startChat: return 1
         case .chatActions: return chatActions.count
         }
     }