How to make message read and unbold the message text and also how to add unread message counter badge in Swift IOS


I want to bold the latestMessages and show unread Messages counter badge and when i select the particular conversation cell the message lable should be unbold and unread Messages counter badge disappear.

// ConversationViewController.swift

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) let model = conversations[indexPath.row] openConversation(model) }

// ConversationTableViewCell.swift

class ConversationTableViewCell: UITableViewCell {
public func configure(with model: Conversation) {

    userMessageLabel.text = model.latestMessage.text
    userNameLabel.text = model.name
    let path = "images/\(model.otherUseremail)_profile_picture.png"
    
    storageManager.shared.downloadUrl(for: path, completion: {[weak self] result in
        switch result {
        case.success(let url):
            DispatchQueue.main.async {
                self?.userImageView.sd_setImage(with: url, completed: nil)
            }
        case.failure(let error):
            print("Failed to get image url: \(error)")
        }
    })
    userMessageLabel.font = model.latestMessage.isRead ? .systemFont(ofSize: 17) : .boldSystemFont(ofSize: 25)
}

}

// ConversationModel.swift

struct Conversation {
    let id : String
    let name : String
    let otherUseremail : String
    let latestMessage: LatestMessage
}

struct LatestMessage {
    let date : String
    let text : String
    let isRead : Bool
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img