summaryrefslogtreecommitdiff
path: root/Juick/Views/BubbleMessageCell.swift
blob: fcd93813359da4740e63ad536eba3dfc2bb8cfbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
//  BubbleMessageCell.swift
//  Juick
//
//  Created by Vitaly Takmazov on 13.05.2023.
//  Copyright © 2023 com.juick. All rights reserved.
//

import UIKit

@objc
class BubbleMessageCell: UITableViewCell {
    @IBOutlet weak var avatarView: UIImageView!
    @IBOutlet weak var unreadMarker: UILabel!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var message: UITextView!
    
    @objc
    func configure(message: Message, isMe: Bool) {
        self.message.backgroundColor = isMe ? UIColor(named: "Title") : UIColor(named: "Chat")
        self.message.textColor = isMe ? UIColor.white : UIColor(named: "Text")
        self.message.dataDetectorTypes = .all
        self.message.tintColor = isMe ? UIColor.white : UIColor(named: "Title")
        self.name.text = message.user.uname
        self.message.text = message.text
        self.unreadMarker.text = ""
        AppDelegate.shared().api.fetchImage(with: URL(string: message.user.avatar)) { data in
            if let imageData = data {
                UIView.transition(with: self.avatarView, duration: 0.3, options: .transitionCrossDissolve, animations: {
                    self.avatarView.image = UIImage(data: imageData)
                })
            }
        }
    }
}