Przeglądaj źródła

Merge pull request #1158 from deltachat/alias-support

allow different senders in one-to-one-chats
bjoern 4 lat temu
rodzic
commit
100169569c

+ 9 - 8
deltachat-ios/Chat/ChatViewController.swift

@@ -207,7 +207,6 @@ class ChatViewController: UITableViewController {
     private lazy var audioController = AudioController(dcContext: dcContext, chatId: chatId, delegate: self)
 
     private var disableWriting: Bool
-    private var showNamesAboveMessage: Bool
     var showCustomNavBar = true
     var highlightedMsg: Int?
 
@@ -228,7 +227,6 @@ class ChatViewController: UITableViewController {
         self.dcContext = dcContext
         self.chatId = chatId
         self.disableWriting = !dcChat.canSend
-        self.showNamesAboveMessage = dcChat.isGroup
         self.highlightedMsg = highlightedMsg
         super.init(nibName: nil, bundle: nil)
         hidesBottomBarWhenPushed = true
@@ -538,11 +536,18 @@ class ChatViewController: UITableViewController {
             cell = tableView.dequeueReusableCell(withIdentifier: "text", for: indexPath) as? TextMessageCell ?? TextMessageCell()
         }
 
+        var showAvatar = isGroupChat && !message.isFromCurrentSender
+        var showName = isGroupChat
+        if message.overrideSenderName != nil {
+            showAvatar = !message.isFromCurrentSender
+            showName = true
+        }
+
         cell.baseDelegate = self
         cell.update(msg: message,
                     messageStyle: configureMessageStyle(for: message, at: indexPath),
-                    isAvatarVisible: configureAvatarVisibility(for: message, at: indexPath),
-                    isGroup: isGroupChat)
+                    showAvatar: showAvatar,
+                    showName: showName)
 
         return cell
     }
@@ -644,10 +649,6 @@ class ChatViewController: UITableViewController {
         _ = handleUIMenu()
     }
 
-    func configureAvatarVisibility(for message: DcMsg, at indexPath: IndexPath) -> Bool {
-        return isGroupChat && !message.isFromCurrentSender
-    }
-
     func configureMessageStyle(for message: DcMsg, at indexPath: IndexPath) -> UIRectCorner {
 
         var corners: UIRectCorner = []

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

@@ -37,7 +37,7 @@ public class AudioMessageCell: BaseMessageCell {
         delegate?.playButtonTapped(cell: self, messageId: messageId)
     }
 
-    override func update(msg: DcMsg, messageStyle: UIRectCorner, isAvatarVisible: Bool, isGroup: Bool) {
+    override func update(msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool) {
         //audioPlayerView.reset()
         messageId = msg.id
         if let text = msg.text {
@@ -52,7 +52,7 @@ public class AudioMessageCell: BaseMessageCell {
             accessibilityLabel = String.localized("audio")
         }
 
-        super.update(msg: msg, messageStyle: messageStyle, isAvatarVisible: isAvatarVisible, isGroup: isGroup)
+        super.update(msg: msg, messageStyle: messageStyle, showAvatar: showAvatar, showName: showName)
     }
 
     public override func prepareForReuse() {

+ 5 - 5
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -270,7 +270,7 @@ public class BaseMessageCell: UITableViewCell {
     }
 
     // update classes inheriting BaseMessageCell first before calling super.update(...)
-    func update(msg: DcMsg, messageStyle: UIRectCorner, isAvatarVisible: Bool, isGroup: 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
@@ -282,12 +282,12 @@ public class BaseMessageCell: UITableViewCell {
 
         } else {
             topLabel.text = msg.isForwarded ? String.localized("forwarded_message") :
-                isGroup ? msg.getSenderName(msg.fromContact, markOverride: true) : nil
+                showName ? msg.getSenderName(msg.fromContact, markOverride: true) : nil
             topLabel.textColor = msg.isForwarded ? DcColors.grayDateColor :
-                isGroup ? msg.fromContact.color : DcColors.defaultTextColor
+                showName ? msg.fromContact.color : DcColors.defaultTextColor
             leadingConstraintCurrentSender?.isActive = false
             trailingConstraintCurrentSender?.isActive = false
-            if isGroup {
+            if showName {
                 leadingConstraint?.isActive = false
                 leadingConstraintGroup?.isActive = true
             } else {
@@ -297,7 +297,7 @@ public class BaseMessageCell: UITableViewCell {
             trailingConstraint?.isActive = true
         }
 
-        if isAvatarVisible {
+        if showAvatar {
             avatarView.isHidden = false
             avatarView.setName(msg.getSenderName(msg.fromContact))
             avatarView.setColor(msg.fromContact.color)

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