From 527865c428a93ead7fb78bdd7906a2004a4bb3ec Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 29 Aug 2024 14:55:38 +0200 Subject: [PATCH] Add entry to share contact (#2273) --- .../ContactDetailViewController.swift | 17 +++++++++++++++++ .../ViewModel/ContactDetailViewModel.swift | 11 ++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/deltachat-ios/Controller/ContactDetailViewController.swift b/deltachat-ios/Controller/ContactDetailViewController.swift index 515bbd929..1dbab77e5 100644 --- a/deltachat-ios/Controller/ContactDetailViewController.swift +++ b/deltachat-ios/Controller/ContactDetailViewController.swift @@ -29,6 +29,13 @@ class ContactDetailViewController: UITableViewController { return cell }() + private lazy var shareContactCell: ActionCell = { + let cell = ActionCell() + cell.actionTitle = String.localized("menu_share") + cell.actionColor = UIColor.systemBlue + return cell + }() + private lazy var ephemeralMessagesCell: UITableViewCell = { let cell = UITableViewCell(style: .value1, reuseIdentifier: nil) cell.textLabel?.text = String.localized("ephemeral_messages") @@ -199,6 +206,8 @@ class ContactDetailViewController: UITableViewController { } case .statusArea: return statusCell + case .shareContact: + return shareContactCell case .chatActions: switch viewModel.chatActionFor(row: row) { case .archiveChat: @@ -229,12 +238,15 @@ class ContactDetailViewController: UITableViewController { handleChatOption(indexPath: indexPath) case .statusArea: break + case .shareContact: + shareContact() case .chatActions: handleChatAction(indexPath: indexPath) case .sharedChats: let chatId = viewModel.getSharedChatIdAt(indexPath: indexPath) showChat(chatId: chatId) } + tableView.deselectRow(at: indexPath, animated: true) } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { @@ -329,6 +341,11 @@ class ContactDetailViewController: UITableViewController { } // MARK: - actions + @objc private func shareContact() { + // compare to `forward`. + // 1. select chat you want to forward this contact to. + // 2. stage this very contacts vcard + } @objc private func showCopyToClipboard() { UIMenuController.shared.menuItems = [ diff --git a/deltachat-ios/ViewModel/ContactDetailViewModel.swift b/deltachat-ios/ViewModel/ContactDetailViewModel.swift index 6bb06287a..8743f4c2c 100644 --- a/deltachat-ios/ViewModel/ContactDetailViewModel.swift +++ b/deltachat-ios/ViewModel/ContactDetailViewModel.swift @@ -8,6 +8,7 @@ class ContactDetailViewModel { enum ProfileSections { case chatOptions case statusArea + case shareContact case sharedChats case chatActions } @@ -72,6 +73,8 @@ class ContactDetailViewModel { sections.append(.statusArea) } + sections.append(.shareContact) + if sharedChats.length > 0 && !isSavedMessages && !isDeviceTalk { sections.append(.sharedChats) } @@ -142,7 +145,7 @@ class ContactDetailViewModel { func numberOfRowsInSection(_ section: Int) -> Int { switch sections[section] { case .chatOptions: return chatOptions.count - case .statusArea: return 1 + case .statusArea, .shareContact: return 1 case .sharedChats: return sharedChats.length case .chatActions: return chatActions.count } @@ -177,7 +180,7 @@ class ContactDetailViewModel { func titleFor(section: Int) -> String? { switch sections[section] { - case .chatOptions: return nil + case .chatOptions, .shareContact: return nil case .statusArea: return (isSavedMessages || isDeviceTalk) ? nil : String.localized("pref_default_status_label") case .sharedChats: return String.localized("profile_shared_chats") case .chatActions: return nil @@ -195,9 +198,7 @@ class ContactDetailViewModel { return String.localizedStringWithFormat(String.localized("last_seen_at"), DateUtils.getExtendedAbsTimeSpanString(timeStamp: Double(lastSeen))) } - case .statusArea: return nil - case .sharedChats: return nil - case .chatActions: return nil + case .statusArea, .sharedChats, .chatActions, .shareContact: return nil } }