فهرست منبع

show separator line before assumed last unread message

cyberta 4 سال پیش
والد
کامیت
3f56353ec0

+ 17 - 1
deltachat-ios/Chat/ChatViewController.swift

@@ -13,6 +13,7 @@ class ChatViewController: UITableViewController {
     let loadCount = 30
     let chatId: Int
     var messageIds: [Int] = []
+    var freshMessageIndex: IndexPath?
 
     var msgChangedObserver: NSObjectProtocol?
     var incomingMsgObserver: NSObjectProtocol?
@@ -572,11 +573,17 @@ class ChatViewController: UITableViewController {
             showName = true
         }
 
+        var showFreshMessageIndicator = false
+        if let freshMessages = self.freshMessageIndex, freshMessages.row == indexPath.row {
+            showFreshMessageIndicator = true
+        }
+
         cell.baseDelegate = self
         cell.update(msg: message,
                     messageStyle: configureMessageStyle(for: message, at: indexPath),
                     showAvatar: showAvatar,
-                    showName: showName)
+                    showName: showName,
+                    showFreshMessageSeparator: showFreshMessageIndicator)
 
         return cell
     }
@@ -769,6 +776,14 @@ class ChatViewController: UITableViewController {
 
         // update message ids
         self.messageIds = self.getMessageIds()
+        let freshMessageCounter = dcContext.getFreshMessagesCount(chatId: self.chatId)
+        if !messageIds.isEmpty && freshMessageCounter > 0 {
+            let index = messageIds.count - freshMessageCounter
+            freshMessageIndex = IndexPath(row: index, section: 0)
+        } else {
+            freshMessageIndex = nil
+        }
+
         self.showEmptyStateView(self.messageIds.isEmpty)
 
         self.reloadData()
@@ -1015,6 +1030,7 @@ class ChatViewController: UITableViewController {
         confirmationAlert(title: title, actionTitle: String.localized("delete"), actionStyle: .destructive,
                           actionHandler: { _ in
                             self.dcContext.deleteMessages(msgIds: ids)
+                            self.freshMessageIndex = nil
                             if self.tableView.isEditing {
                                 self.setEditing(isEditing: false)
                             }

+ 2 - 2
deltachat-ios/Chat/Views/Cells/AudioMessageCell.swift

@@ -39,7 +39,7 @@ public class AudioMessageCell: BaseMessageCell {
         delegate?.playButtonTapped(cell: self, messageId: messageId)
     }
 
-    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showFreshMessageSeparator: Bool) {
         messageId = msg.id
         if let text = msg.text {
             mainContentView.spacing = text.isEmpty ? 0 : 8
@@ -61,7 +61,7 @@ public class AudioMessageCell: BaseMessageCell {
         })
         
 
-        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName, showFreshMessageSeparator: showFreshMessageSeparator)
     }
 
     public override func prepareForReuse() {

+ 20 - 2
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -15,6 +15,7 @@ public class BaseMessageCell: UITableViewCell {
     private var mainContentViewLeadingConstraint: NSLayoutConstraint?
     private var mainContentViewTrailingConstraint: NSLayoutConstraint?
     private var fullMessageZeroHeightConstraint: NSLayoutConstraint?
+    private var freshMessageSeparatorHeightConstraint: NSLayoutConstraint?
 
     public var mainContentViewHorizontalPadding: CGFloat {
         get {
@@ -68,6 +69,14 @@ public class BaseMessageCell: UITableViewCell {
 
     public weak var baseDelegate: BaseMessageCellDelegate?
 
+    public lazy var freshMessageSeparator: UIView = {
+        let view = UIView()
+        view.backgroundColor = DcColors.colorDisabled
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.isAccessibilityElement = false
+        return view
+    }()
+
     public lazy var quoteView: QuoteView = {
         let view = QuoteView()
         view.translatesAutoresizingMaskIntoConstraints = false
@@ -179,6 +188,7 @@ public class BaseMessageCell: UITableViewCell {
 
     func setupSubviews() {
         selectedBackgroundView = UIView()
+        contentView.addSubview(freshMessageSeparator)
         contentView.addSubview(messageBackgroundContainer)
         messageBackgroundContainer.addSubview(mainContentView)
         messageBackgroundContainer.addSubview(topLabel)
@@ -187,6 +197,9 @@ public class BaseMessageCell: UITableViewCell {
         contentView.addSubview(avatarView)
 
         contentView.addConstraints([
+            freshMessageSeparator.constraintAlignLeadingTo(contentView),
+            freshMessageSeparator.constraintAlignTrailingTo(contentView),
+            freshMessageSeparator.constraintAlignTopTo(contentView),
             avatarView.constraintAlignLeadingTo(contentView, paddingLeading: 2),
             avatarView.constraintAlignBottomTo(contentView),
             avatarView.constraintWidthTo(28, priority: .defaultHigh),
@@ -194,7 +207,7 @@ public class BaseMessageCell: UITableViewCell {
             topLabel.constraintAlignTopTo(messageBackgroundContainer, paddingTop: 6),
             topLabel.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 8),
             topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
-            messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
+            messageBackgroundContainer.constraintToBottomOf(freshMessageSeparator, paddingTop: 3),
             messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
             fullMessageButton.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 12),
             fullMessageButton.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 12),
@@ -204,6 +217,9 @@ public class BaseMessageCell: UITableViewCell {
             bottomLabel.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 6)
         ])
 
+        freshMessageSeparatorHeightConstraint = freshMessageSeparator.constraintHeightTo(0)
+        freshMessageSeparatorHeightConstraint?.isActive = true
+
         leadingConstraint = messageBackgroundContainer.constraintAlignLeadingTo(contentView, paddingLeading: 6)
         leadingConstraintGroup = messageBackgroundContainer.constraintToTrailingOf(avatarView, paddingLeading: 2)
         trailingConstraint = messageBackgroundContainer.constraintAlignTrailingMaxTo(contentView, paddingTrailing: 36)
@@ -270,7 +286,7 @@ public class BaseMessageCell: UITableViewCell {
     }
 
     // update classes inheriting BaseMessageCell first before calling super.update(...)
-    func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
+    func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showFreshMessageSeparator: Bool) {
         if msg.isFromCurrentSender {
             topLabel.text = msg.isForwarded ? String.localized("forwarded_message") : nil
             topLabel.textColor = msg.isForwarded ? DcColors.grayDateColor : DcColors.defaultTextColor
@@ -308,6 +324,8 @@ public class BaseMessageCell: UITableViewCell {
             avatarView.isHidden = true
         }
 
+        freshMessageSeparatorHeightConstraint?.constant = showFreshMessageSeparator ? 1 : 0
+
         isFullMessageButtonHidden = !msg.hasHtml
 
         messageBackgroundContainer.update(rectCorners: messageStyle,

+ 2 - 2
deltachat-ios/Chat/Views/Cells/FileTextCell.swift

@@ -29,7 +29,7 @@ class FileTextCell: BaseMessageCell {
         fileView.prepareForReuse()
     }
 
-    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showFreshMessageSeparator: Bool) {
         if let text = msg.text, !text.isEmpty {
             messageLabel.text = text
             spacer?.isActive = true
@@ -39,7 +39,7 @@ class FileTextCell: BaseMessageCell {
         
         fileView.configure(message: msg)
         accessibilityLabel = "\(String.localized("document")), \(fileView.configureAccessibilityLabel())"
-        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName, showFreshMessageSeparator: showFreshMessageSeparator)
     }
     
 }

+ 2 - 2
deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

@@ -42,7 +42,7 @@ class ImageTextCell: BaseMessageCell {
         contentImageView.addGestureRecognizer(gestureRecognizer)
     }
 
-    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showFreshMessageSeparator: Bool) {
         messageLabel.text = msg.text
         bottomCompactView = msg.text?.isEmpty ?? true
         mainContentView.spacing = msg.text?.isEmpty ?? false ? 0 : 6
@@ -91,7 +91,7 @@ class ImageTextCell: BaseMessageCell {
                 setAspectRatioFor(message: msg, with: placeholderImage, isPlaceholder: true)
             }
         }
-        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName, showFreshMessageSeparator: showFreshMessageSeparator)
     }
 
     @objc func onImageTapped() {

+ 2 - 2
deltachat-ios/Chat/Views/Cells/TextMessageCell.swift

@@ -11,9 +11,9 @@ class TextMessageCell: BaseMessageCell {
         messageLabel.paddingTrailing = 12
     }
 
-    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showFreshMessageSeparator: Bool) {
         messageLabel.text = msg.text
-        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName, showFreshMessageSeparator: showFreshMessageSeparator)
     }
 
     override func prepareForReuse() {