title: Swift JSQMessagesViewController name on top
body: <p>I am displaying the sender name of the receiver. However, I don't want to display the name on every single text that the person sends. For example, if he/she sends a a message consecutively, I just want it to display the name on top of the first message. I'll provide a screenshot of my chat here:</p>
  
  <p><a href="https://i.stack.imgur.com/4xbPkm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4xbPkm.png" alt="screenshot of my chat"></a></p>
  
  <p>In other words, I just want it to display the name of the user on the very 'first' message he/she sends. I tried to solve this issue, in the <code>attributedTextForMessageBubbleTopLabelAt</code> with no luck. </p>
  
  <p>I have tried to check if the senderId of the previous message is equal to the previous senderId - and then somehow find out if it can be shown or not. But, this has resulted in many, many failed attempts with optional errors, index out of range, and just simply not working solutions.</p>
  
  <p>This is the code I have right now:</p>
  
  <pre><code>let message = messages[indexPath.item]
  
      switch message.senderId {
  
      case FIRAuth.auth()!.currentUser!.uid:
          return nil
          break
  
      default:
  
          guard let senderDisplayName = message.senderDisplayName else {
              assertionFailure()
              return nil
          }
  
          let paragraphStyle = NSMutableParagraphStyle()
          paragraphStyle.alignment = NSTextAlignment.left
  
          let attributedString = NSAttributedString(string: message.senderDisplayName,
                                                    attributes: [
                                                      NSParagraphStyleAttributeName: paragraphStyle,
                                                      NSBaselineOffsetAttributeName: NSNumber(value: 0)
              ])
  
          return attributedString
          break
  
      }
  </code></pre>