Skip to content
Snippets Groups Projects
Commit 22484cab authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Fixed unread count

parent 40155411
No related branches found
No related tags found
2 merge requests!40v1.1.2b166,!38Using new database structure
......@@ -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 ?? ""
)
}
......
......@@ -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
)
}
......
......@@ -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?) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment