Переглянути джерело

show padlock if message was encrypted (#400)

cyberta 5 роки тому
батько
коміт
2ee3e41575

+ 56 - 0
deltachat-ios/Assets.xcassets/ic_lock.imageset/Contents.json

@@ -0,0 +1,56 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_dark_18dp-2.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_white_18dp-2.png",
+      "appearances" : [
+        {
+          "appearance" : "luminosity",
+          "value" : "dark"
+        }
+      ],
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_dark_18dp.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_white_18dp.png",
+      "appearances" : [
+        {
+          "appearance" : "luminosity",
+          "value" : "dark"
+        }
+      ],
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_dark_18dp-1.png",
+      "scale" : "3x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_lock_white_18dp-1.png",
+      "appearances" : [
+        {
+          "appearance" : "luminosity",
+          "value" : "dark"
+        }
+      ],
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_dark_18dp-1.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_dark_18dp-2.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_dark_18dp.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_white_18dp-1.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_white_18dp-2.png


BIN
deltachat-ios/Assets.xcassets/ic_lock.imageset/ic_lock_white_18dp.png


+ 28 - 2
deltachat-ios/Controller/ChatViewController.swift

@@ -784,8 +784,8 @@ extension ChatViewController: MessagesDataSource {
             .paragraphStyle: NSParagraphStyle()
         ]
 
+        let text = NSMutableAttributedString()
         if isFromCurrentSender(message: message) {
-            let text = NSMutableAttributedString()
             if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
                 style.alignment = .right
                 timestampAttributes[.paragraphStyle] = style
@@ -817,6 +817,10 @@ extension ChatViewController: MessagesDataSource {
                 ]
             ))
 
+            if m.showPadlock() {
+                attachPadlock(to: text)
+            }
+
             return text
         }
 
@@ -827,7 +831,29 @@ extension ChatViewController: MessagesDataSource {
             }
         }
 
-        return NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes)
+        text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
+        if m.showPadlock() {
+            attachPadlock(to: text)
+        }
+        return text
+    }
+
+    private func attachPadlock(to text: NSMutableAttributedString) { let imageAttachment = NSTextAttachment()
+        imageAttachment.image = UIImage(named: "ic_lock.png")
+        imageAttachment.image?.accessibilityIdentifier = String.localized("encrypted_message")
+        let imageString = NSMutableAttributedString(attachment: imageAttachment)
+        imageString.addAttributes([NSAttributedString.Key.baselineOffset: -1], range: NSRange(location: 0, length: 1))
+        text.append(NSAttributedString(string: " "))
+        text.append(imageString)
+    }
+
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        super.traitCollectionDidChange(previousTraitCollection)
+        if #available(iOS 13.0, *) {
+            if self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
+                refreshMessages()
+            }
+        }
     }
 
     func updateMessage(_ messageId: Int) {

+ 4 - 0
deltachat-ios/DC/Wrapper.swift

@@ -855,6 +855,10 @@ class DcMsg: MessageType {
         return swiftString
     }
 
+    func showPadlock() -> Bool {
+        return dc_msg_get_showpadlock(messagePointer) == 1;
+    }
+
     func createChat() -> DcChat {
         let chatId = dc_create_chat_by_msg_id(mailboxPointer, UInt32(id))
         return DcChat(id: Int(chatId))