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