浏览代码

show sender's name and color in quote

cyberta 4 年之前
父节点
当前提交
7e594d1309

+ 16 - 0
DcCore/DcCore/DC/Wrapper.swift

@@ -796,6 +796,10 @@ public class DcMsg {
         messagePointer = dc_msg_new(DcContext.shared.contextPointer, type)
     }
 
+    init(pointer: OpaquePointer) {
+        messagePointer = pointer
+    }
+
     deinit {
         dc_msg_unref(messagePointer)
     }
@@ -856,6 +860,18 @@ public class DcMsg {
         }
     }
 
+    public var quoteText: String? {
+        guard let cString = dc_msg_get_quoted_text(messagePointer) else { return nil }
+        let swiftString = String(cString: cString)
+        dc_str_unref(cString)
+        return swiftString
+    }
+
+    public var quoteMessage: DcMsg? {
+        guard let msgpointer = dc_msg_get_quoted_msg(messagePointer) else { return nil }
+        return DcMsg(pointer: msgpointer)
+    }
+
     public var viewtype: MessageViewType? {
         switch dc_msg_get_viewtype(messagePointer) {
         case 0:

+ 15 - 0
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -255,6 +255,20 @@ public class BaseMessageCell: UITableViewCell {
         if !msg.isInfo {
             bottomLabel.attributedText = getFormattedBottomLine(message: msg)
         }
+
+        if let quoteText = msg.quoteText {
+            quoteView.isHidden = false
+            quoteView.quote.text = quoteText
+
+            if let quoteMsg = msg.quoteMessage {
+                let contact = quoteMsg.fromContact
+                quoteView.senderTitle.text = contact.displayName
+                quoteView.senderTitle.textColor = contact.color
+            }
+        } else {
+            quoteView.isHidden = true
+        }
+
         messageLabel.delegate = self
     }
 
@@ -357,6 +371,7 @@ public class BaseMessageCell: UITableViewCell {
         messageLabel.text = nil
         messageLabel.attributedText = nil
         messageLabel.delegate = nil
+        quoteView.prepareForReuse()
     }
 
     // MARK: - Context menu

+ 14 - 5
deltachat-ios/Chat/Views/QuoteView.swift

@@ -1,4 +1,5 @@
 import UIKit
+import DcCore
 
 public class QuoteView: UIView {
     lazy var citeBar: UIView = {
@@ -12,15 +13,16 @@ public class QuoteView: UIView {
 
     public lazy var quote: UILabel = {
         let view = UILabel()
-        view.font = UIFont.preferredFont(for: .caption1, weight: .regular)
+        view.font = UIFont.preferredFont(for: .caption2, weight: .light)
         view.text = "quote"
+        view.textColor = DcColors.grayTextColor
         view.translatesAutoresizingMaskIntoConstraints = false
         return view
     }()
 
     public lazy var senderTitle: UILabel = {
         let view = UILabel()
-        view.font = UIFont.preferredFont(for: .caption1, weight: .bold)
+        view.font = UIFont.preferredFont(for: .caption2, weight: .semibold)
         view.text = "title"
         view.translatesAutoresizingMaskIntoConstraints = false
         return view
@@ -41,12 +43,12 @@ public class QuoteView: UIView {
         addSubview(quote)
 
         addConstraints([
-            senderTitle.constraintAlignTopTo(self, paddingTop: 4),
+            senderTitle.constraintAlignTopTo(self),
             senderTitle.constraintAlignLeadingTo(self, paddingLeading: 24),
-            senderTitle.constraintAlignTrailingTo(self, paddingTrailing: 4),
+            senderTitle.constraintAlignTrailingTo(self, paddingTrailing: 8),
             quote.constraintAlignLeadingTo(self, paddingLeading: 24),
             quote.constraintToBottomOf(senderTitle),
-            quote.constraintAlignTrailingTo(self, paddingTrailing: 4),
+            quote.constraintAlignTrailingTo(self, paddingTrailing: 8),
             quote.constraintAlignBottomTo(self, paddingBottom: 4),
             citeBar.constraintAlignLeadingTo(self, paddingLeading: 16),
             citeBar.constraintAlignTopTo(senderTitle, paddingTop: 4),
@@ -54,4 +56,11 @@ public class QuoteView: UIView {
             citeBar.constraintWidthTo(3)
         ])
     }
+
+    public func prepareForReuse() {
+        quote.text = nil
+        quote.attributedText = nil
+        senderTitle.text = nil
+        senderTitle.attributedText = nil
+    }
 }