diff --git a/Sources/ChatListFeature/Controller/ChatListSearchTableController.swift b/Sources/ChatListFeature/Controller/ChatListSearchTableController.swift index 07efc15ce666f7b2183d915e832773529694eede..46e9c20bed9b21b96d883f0ffc07db81caad0de9 100644 --- a/Sources/ChatListFeature/Controller/ChatListSearchTableController.swift +++ b/Sources/ChatListFeature/Controller/ChatListSearchTableController.swift @@ -39,7 +39,7 @@ final class ChatSearchTableController: UITableViewController { name: group.name, date: group.createdAt, preview: nil, - hasUnread: false + unreadCount: 0 ) case .groupChat(let groupChatInfo): @@ -47,7 +47,7 @@ final class ChatSearchTableController: UITableViewController { name: groupChatInfo.group.name, date: groupChatInfo.lastMessage.date, preview: groupChatInfo.lastMessage.text, - hasUnread: groupChatInfo.lastMessage.isUnread + unreadCount: groupChatInfo.unreadCount ) case .contactChat(let contactChatInfo): @@ -55,7 +55,7 @@ final class ChatSearchTableController: UITableViewController { name: (contactChatInfo.contact.nickname ?? contactChatInfo.contact.username) ?? "", image: contactChatInfo.contact.photo, date: contactChatInfo.lastMessage.date, - hasUnread: contactChatInfo.lastMessage.isUnread, + unreadCount: contactChatInfo.unreadCount, preview: contactChatInfo.lastMessage.text ) } @@ -65,7 +65,7 @@ final class ChatSearchTableController: UITableViewController { name: (contact.nickname ?? contact.username) ?? "", image: contact.photo, date: nil, - hasUnread: false, + unreadCount: 0, preview: contact.username ?? "" ) } diff --git a/Sources/ChatListFeature/Controller/ChatListTableController.swift b/Sources/ChatListFeature/Controller/ChatListTableController.swift index 9c97a2414b9d6d99f9ed304c16ab470674d651ed..8527195eee326146909a865a6768e553c10a5e3d 100644 --- a/Sources/ChatListFeature/Controller/ChatListTableController.swift +++ b/Sources/ChatListFeature/Controller/ChatListTableController.swift @@ -123,7 +123,7 @@ extension ChatListTableController { name: group.name, date: group.createdAt, preview: nil, - hasUnread: false + unreadCount: 0 ) case .groupChat(let info): @@ -131,7 +131,7 @@ extension ChatListTableController { name: info.group.name, date: info.lastMessage.date, preview: info.lastMessage.text, - hasUnread: info.lastMessage.isUnread + unreadCount: info.unreadCount ) case .contactChat(let info): @@ -139,7 +139,7 @@ extension ChatListTableController { name: (info.contact.nickname ?? info.contact.username) ?? "", image: info.contact.photo, date: info.lastMessage.date, - hasUnread: info.lastMessage.isUnread, + unreadCount: info.unreadCount, preview: info.lastMessage.text ) } diff --git a/Sources/ChatListFeature/Views/ChatListCell.swift b/Sources/ChatListFeature/Views/ChatListCell.swift index 8eea62d2278b630efeb6afb1d12fad725cd23c18..bb455395abbc36921e364b27a5ca07e573726ea3 100644 --- a/Sources/ChatListFeature/Views/ChatListCell.swift +++ b/Sources/ChatListFeature/Views/ChatListCell.swift @@ -4,6 +4,7 @@ import Shared final class ChatListCell: UITableViewCell { private let titleLabel = UILabel() private let unreadView = UIView() + private let unreadCountLabel = UILabel() private let previewLabel = UILabel() private let dateLabel = UILabel() private let avatarView = AvatarView() @@ -31,10 +32,11 @@ final class ChatListCell: UITableViewCell { backgroundColor = Asset.neutralWhite.color dateLabel.textColor = Asset.neutralWeak.color titleLabel.textColor = Asset.neutralActive.color + unreadCountLabel.textColor = Asset.neutralWhite.color dateLabel.font = Fonts.Mulish.semiBold.font(size: 13.0) titleLabel.font = Fonts.Mulish.semiBold.font(size: 16.0) - + unreadCountLabel.font = Fonts.Mulish.semiBold.font(size: 13.0) timer = Timer.scheduledTimer(withTimeInterval: 59, repeats: true) { [weak self] _ in self?.updateTimeAgoLabel() @@ -47,6 +49,7 @@ final class ChatListCell: UITableViewCell { contentView.addSubview(avatarView) contentView.addSubview(previewLabel) contentView.addSubview(dateLabel) + unreadView.addSubview(unreadCountLabel) avatarView.snp.makeConstraints { $0.top.equalToSuperview().offset(14) @@ -54,6 +57,10 @@ final class ChatListCell: UITableViewCell { $0.width.height.equalTo(48) } + unreadCountLabel.snp.makeConstraints { + $0.center.equalToSuperview() + } + titleLabel.snp.makeConstraints { $0.top.equalToSuperview().offset(10) $0.left.equalTo(avatarView.snp.right).offset(16) @@ -85,6 +92,7 @@ final class ChatListCell: UITableViewCell { super.prepareForReuse() lastDate = nil titleLabel.text = nil + unreadCountLabel.text = nil previewLabel.attributedText = nil avatarView.prepareForReuse() } @@ -99,13 +107,14 @@ final class ChatListCell: UITableViewCell { name: String, image: Data?, date: Date?, - hasUnread: Bool, + unreadCount: Int, preview: String ) { titleLabel.text = name setPreview(string: preview) avatarView.setupProfile(title: name, image: image, size: .large) - unreadView.backgroundColor = hasUnread ? Asset.brandPrimary.color : .clear + unreadCountLabel.text = "\(unreadCount)" + unreadView.backgroundColor = unreadCount > 0 ? Asset.brandPrimary.color : .clear if let date = date { lastDate = date @@ -118,13 +127,14 @@ final class ChatListCell: UITableViewCell { name: String, date: Date, preview: String?, - hasUnread: Bool + unreadCount: Int ) { lastDate = date titleLabel.text = name setPreview(string: preview) avatarView.setupGroup(size: .large) - unreadView.backgroundColor = hasUnread ? Asset.brandPrimary.color : .clear + unreadCountLabel.text = "\(unreadCount)" + unreadView.backgroundColor = unreadCount > 0 ? Asset.brandPrimary.color : .clear } private func setPreview(string: String?) {