Explorar o código

Merge pull request #1308 from deltachat/contact_request_tweaks

Contact request tweaks
bjoern %!s(int64=4) %!d(string=hai) anos
pai
achega
2f01270024

+ 28 - 6
deltachat-ios/Chat/ChatViewController.swift

@@ -55,7 +55,7 @@ class ChatViewController: UITableViewController {
     }()
 
     public lazy var contactRequestBar: ChatContactRequestBar = {
-        let view = ChatContactRequestBar()
+        let view = ChatContactRequestBar(isGroupRequest: dcContext.getChat(chatId: chatId).isGroup)
         view.delegate = self
         view.translatesAutoresizingMaskIntoConstraints = false
         return view
@@ -464,6 +464,14 @@ class ChatViewController: UITableViewController {
         AppStateRestorer.shared.resetLastActiveChat()
         handleUserVisibility(isVisible: false)
         
+        removeMessageObservers()
+        let nc = NotificationCenter.default
+        nc.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
+        nc.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
+        audioController.stopAnyOngoingPlaying()
+    }
+    
+    private func removeMessageObservers() {
         let nc = NotificationCenter.default
         if let msgChangedObserver = self.msgChangedObserver {
             nc.removeObserver(msgChangedObserver)
@@ -474,9 +482,6 @@ class ChatViewController: UITableViewController {
         if let ephemeralTimerModifiedObserver = self.ephemeralTimerModifiedObserver {
             nc.removeObserver(ephemeralTimerModifiedObserver)
         }
-        nc.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
-        nc.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
-        audioController.stopAnyOngoingPlaying()
     }
 
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -1053,6 +1058,19 @@ class ChatViewController: UITableViewController {
             }))
         present(alert, animated: true, completion: nil)
     }
+    
+    private func askToDeleteChat() {
+        let title = String.localized(stringID: "ask_delete_chat", count: 1)
+        confirmationAlert(title: title, actionTitle: String.localized("delete"), actionStyle: .destructive,
+                          actionHandler: { [weak self] _ in
+                            guard let self = self else { return }
+                            // remove message observers early to avoid careless calls to dcContext methods
+                            self.removeMessageObservers()
+                            self.dcContext.deleteChat(chatId: self.chatId)
+                            self.navigationController?.popViewController(animated: true)
+                          })
+    }
+    
 
     private func askToChatWith(email: String) {
         let contactId = self.dcContext.createContact(name: "", email: email)
@@ -1690,15 +1708,19 @@ extension ChatViewController: ChatEditingDelegate {
 
 // MARK: - ChatContactRequestBar
 extension ChatViewController: ChatContactRequestDelegate {
-    func onAcceptPressed() {
+    func onAcceptRequest() {
         dcContext.acceptChat(chatId: chatId)
         configureUIForWriting()
     }
 
-    func onBlockPressed() {
+    func onBlockRequest() {
         dcContext.blockChat(chatId: chatId)
         self.navigationController?.popViewController(animated: true)
     }
+    
+    func onDeleteRequest() {
+        self.askToDeleteChat()
+    }
 }
 
 // MARK: - QLPreviewControllerDelegate

+ 20 - 17
deltachat-ios/Chat/Views/ChatContactRequestBar.swift

@@ -3,8 +3,9 @@ import InputBarAccessoryView
 import DcCore
 
 public protocol ChatContactRequestDelegate: class {
-    func onAcceptPressed()
-    func onBlockPressed()
+    func onAcceptRequest()
+    func onBlockRequest()
+    func onDeleteRequest()
 }
 
 public class ChatContactRequestBar: UIView, InputItem {
@@ -16,6 +17,8 @@ public class ChatContactRequestBar: UIView, InputItem {
     public func keyboardEditingBeginsAction() {}
 
     weak var delegate: ChatContactRequestDelegate?
+    
+    private var isGroupRequest: Bool = false
 
     private lazy var acceptButton: UIButton = {
         let view = UIButton()
@@ -27,15 +30,15 @@ public class ChatContactRequestBar: UIView, InputItem {
 
     private lazy var blockButton: UIButton = {
         let view = UIButton()
-        view.setTitle(String.localized("block"), for: .normal)
-        view.setTitleColor(.systemBlue, for: .normal)
+        view.setTitle(isGroupRequest ? String.localized("delete") : String.localized("block"), for: .normal)
+        view.setTitleColor(.systemRed, for: .normal)
         view.translatesAutoresizingMaskIntoConstraints = false
         view.isUserInteractionEnabled = true
         return view
     }()
 
     private lazy var mainContentView: UIStackView = {
-        let view = UIStackView(arrangedSubviews: [acceptButton, blockButton])
+        let view = UIStackView(arrangedSubviews: [blockButton, acceptButton])
         view.axis = .horizontal
         view.distribution = .fillEqually
         view.alignment = .center
@@ -43,14 +46,10 @@ public class ChatContactRequestBar: UIView, InputItem {
         return view
     }()
 
-    convenience init() {
-        self.init(frame: .zero)
-
-    }
-
-    public override init(frame: CGRect) {
-        super.init(frame: frame)
-        self.setupSubviews()
+    public required init(isGroupRequest: Bool) {
+        self.isGroupRequest = isGroupRequest
+        super.init(frame: .zero)
+        setupSubviews()
     }
 
     required init(coder: NSCoder) {
@@ -72,17 +71,21 @@ public class ChatContactRequestBar: UIView, InputItem {
         let acceptGestureListener = UITapGestureRecognizer(target: self, action: #selector(onAcceptPressed))
         acceptButton.addGestureRecognizer(acceptGestureListener)
 
-        let blockGestureListener = UITapGestureRecognizer(target: self, action: #selector(onBlockPressed))
+        let blockGestureListener = UITapGestureRecognizer(target: self, action: #selector(onRejectPressed))
         blockButton.addGestureRecognizer(blockGestureListener)
 
     }
 
     @objc func onAcceptPressed() {
-        delegate?.onAcceptPressed()
+        delegate?.onAcceptRequest()
     }
 
-    @objc func onBlockPressed() {
-        delegate?.onBlockPressed()
+    @objc func onRejectPressed() {
+        if isGroupRequest {
+            delegate?.onDeleteRequest()
+        } else {
+            delegate?.onBlockRequest()
+        }
     }
 
     public override var intrinsicContentSize: CGSize {

+ 3 - 3
deltachat-ios/View/ContactCell.swift

@@ -116,7 +116,7 @@ class ContactCell: UITableViewCell {
     }()
 
     private lazy var contactRequest: UIView = {
-        return createTagLabel(tag: String.localized("chat_contact_request"))
+        return createTagLabel(tag: String.localized("chat_request_label"))
     }()
 
     private let unreadMessageCounter: MessageCounter = {
@@ -233,7 +233,7 @@ class ContactCell: UITableViewCell {
     func setStatusIndicators(unreadCount: Int, status: Int, visibility: Int32, isLocationStreaming: Bool, isMuted: Bool, isContactRequest: Bool) {
         if isLargeText {
             unreadMessageCounter.setCount(unreadCount)
-            unreadMessageCounter.isHidden = unreadCount == 0
+            unreadMessageCounter.isHidden = unreadCount == 0 || isContactRequest
             unreadMessageCounter.backgroundColor = isMuted ? .gray : .red
             pinnedIndicator.isHidden = true
             deliveryStatusIndicator.isHidden = true
@@ -250,7 +250,7 @@ class ContactCell: UITableViewCell {
         } else if unreadCount > 0 {
             pinnedIndicator.isHidden = !(visibility == DC_CHAT_VISIBILITY_PINNED)
             unreadMessageCounter.setCount(unreadCount)
-            unreadMessageCounter.isHidden = false
+            unreadMessageCounter.isHidden = isContactRequest
             unreadMessageCounter.backgroundColor = isMuted ? .gray : .red
             deliveryStatusIndicator.isHidden = true
             archivedIndicator.isHidden = true

+ 0 - 1
scripts/untranslated.xml

@@ -12,5 +12,4 @@
     
     <string name="perm_ios_explain_access_to_camera_denied">To take photos, capture videos or use the QR-Code scanner, open the system settings and enable \"Camera\".</string>
     <string name="open_settings">Open Settings</string>
-    <string name="accept">Accept</string>
 </resources>