Эх сурвалжийг харах

revert separator line implementation, instead we're using an info-message cell showing 'x new messages'

cyberta 4 жил өмнө
parent
commit
530d061f49

+ 12 - 15
deltachat-ios/Chat/ChatViewController.swift

@@ -13,7 +13,6 @@ class ChatViewController: UITableViewController {
     let loadCount = 30
     let chatId: Int
     var messageIds: [Int] = []
-    var freshMessageIndex: IndexPath?
 
     var msgChangedObserver: NSObjectProtocol?
     var incomingMsgObserver: NSObjectProtocol?
@@ -538,6 +537,12 @@ class ChatViewController: UITableViewController {
                 cell.update(text: "ErrDaymarker")
             }
             return cell
+        } else if id == DC_MSG_ID_MARKER1 {
+            // unread messages marker
+            let cell = tableView.dequeueReusableCell(withIdentifier: "info", for: indexPath) as? InfoMessageCell ?? InfoMessageCell()
+            let freshMsgsCount = self.messageIds.count - (indexPath.row + 1)
+            cell.update(text: String.localized(stringID: "chat_n_new_messages", count: freshMsgsCount))
+            return cell
         }
         
         let message = DcMsg(id: id)
@@ -573,17 +578,11 @@ class ChatViewController: UITableViewController {
             showName = true
         }
 
-        var showFreshMessageSeparator = false
-        if let firstFreshMessage = self.freshMessageIndex, firstFreshMessage.row == indexPath.row {
-            showFreshMessageSeparator = true
-        }
-
         cell.baseDelegate = self
         cell.update(msg: message,
                     messageStyle: configureMessageStyle(for: message, at: indexPath),
                     showAvatar: showAvatar,
-                    showName: showName,
-                    showSeparator: showFreshMessageSeparator)
+                    showName: showName)
 
         return cell
     }
@@ -775,14 +774,13 @@ class ChatViewController: UITableViewController {
     private func loadMessages() {
 
         // update message ids
-        self.messageIds = self.getMessageIds()
+        var msgIds = self.getMessageIds()
         let freshMsgsCount = self.dcContext.getUnreadMessages(chatId: self.chatId)
-        if freshMsgsCount > 0 && self.messageIds.count >= freshMsgsCount {
-            let index = messageIds.count - freshMsgsCount
-            freshMessageIndex = IndexPath(row: index, section: 0)
-        } else {
-            freshMessageIndex = nil
+        if freshMsgsCount > 0 && msgIds.count >= freshMsgsCount {
+            let index = msgIds.count - freshMsgsCount
+            msgIds.insert(Int(DC_MSG_ID_MARKER1), at: index)
         }
+        self.messageIds = msgIds
 
         self.showEmptyStateView(self.messageIds.isEmpty)
 
@@ -1030,7 +1028,6 @@ 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, showSeparator: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: 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, showSeparator: showSeparator)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
     }
 
     public override func prepareForReuse() {

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

@@ -15,7 +15,6 @@ 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 {
@@ -69,14 +68,6 @@ 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
@@ -188,7 +179,6 @@ public class BaseMessageCell: UITableViewCell {
 
     func setupSubviews() {
         selectedBackgroundView = UIView()
-        contentView.addSubview(freshMessageSeparator)
         contentView.addSubview(messageBackgroundContainer)
         messageBackgroundContainer.addSubview(mainContentView)
         messageBackgroundContainer.addSubview(topLabel)
@@ -197,9 +187,6 @@ 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),
@@ -207,7 +194,7 @@ public class BaseMessageCell: UITableViewCell {
             topLabel.constraintAlignTopTo(messageBackgroundContainer, paddingTop: 6),
             topLabel.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 8),
             topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
-            messageBackgroundContainer.constraintToBottomOf(freshMessageSeparator, paddingTop: 3),
+            messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
             messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
             fullMessageButton.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 12),
             fullMessageButton.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 12),
@@ -217,9 +204,6 @@ 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)
@@ -286,7 +270,7 @@ public class BaseMessageCell: UITableViewCell {
     }
 
     // update classes inheriting BaseMessageCell first before calling super.update(...)
-    func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, showSeparator: Bool) {
+    func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
         if msg.isFromCurrentSender {
             topLabel.text = msg.isForwarded ? String.localized("forwarded_message") : nil
             topLabel.textColor = msg.isForwarded ? DcColors.grayDateColor : DcColors.defaultTextColor
@@ -324,8 +308,6 @@ public class BaseMessageCell: UITableViewCell {
             avatarView.isHidden = true
         }
 
-        freshMessageSeparatorHeightConstraint?.constant = showSeparator ? 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, showSeparator: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: 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, showSeparator: showSeparator)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
     }
     
 }

+ 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, showSeparator: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: 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, showSeparator: showSeparator)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
     }
 
     @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, showSeparator: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
         messageLabel.text = msg.text
-        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName, showSeparator: showSeparator)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
     }
 
     override func prepareForReuse() {