add @ symbol when there is mention in unread messages

pull/500/head
ryanzhao 3 years ago
parent e045808070
commit 42d4e07724

@ -1,4 +1,5 @@
import UIKit import UIKit
import SessionUIKit
final class ConversationCell : UITableViewCell { final class ConversationCell : UITableViewCell {
var threadViewModel: ThreadViewModel! { didSet { update() } } var threadViewModel: ThreadViewModel! { didSet { update() } }
@ -37,6 +38,26 @@ final class ConversationCell : UITableViewCell {
return result return result
}() }()
private lazy var hasMentionView: UIView = {
let result = UIView()
result.backgroundColor = Colors.accent
let size = ConversationCell.unreadCountViewSize
result.set(.width, to: size)
result.set(.height, to: size)
result.layer.masksToBounds = true
result.layer.cornerRadius = size / 2
return result
}()
private lazy var hasMentionLabel: UILabel = {
let result = UILabel()
result.font = .boldSystemFont(ofSize: Values.verySmallFontSize)
result.textColor = Colors.text
result.text = "@"
result.textAlignment = .center
return result
}()
private lazy var timestampLabel: UILabel = { private lazy var timestampLabel: UILabel = {
let result = UILabel() let result = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize) result.font = .systemFont(ofSize: Values.smallFontSize)
@ -98,9 +119,12 @@ final class ConversationCell : UITableViewCell {
// Unread count view // Unread count view
unreadCountView.addSubview(unreadCountLabel) unreadCountView.addSubview(unreadCountLabel)
unreadCountLabel.pin(to: unreadCountView) unreadCountLabel.pin(to: unreadCountView)
// Has mention view
hasMentionView.addSubview(hasMentionLabel)
hasMentionLabel.pin(to: hasMentionView)
// Label stack view // Label stack view
let topLabelSpacer = UIView.hStretchingSpacer() let topLabelSpacer = UIView.hStretchingSpacer()
let topLabelStackView = UIStackView(arrangedSubviews: [ displayNameLabel, unreadCountView, topLabelSpacer, timestampLabel ]) let topLabelStackView = UIStackView(arrangedSubviews: [ displayNameLabel, unreadCountView, hasMentionView, topLabelSpacer, timestampLabel ])
topLabelStackView.axis = .horizontal topLabelStackView.axis = .horizontal
topLabelStackView.alignment = .center topLabelStackView.alignment = .center
topLabelStackView.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer topLabelStackView.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer
@ -176,6 +200,7 @@ final class ConversationCell : UITableViewCell {
unreadCountLabel.text = unreadCount < 100 ? "\(unreadCount)" : "99+" unreadCountLabel.text = unreadCount < 100 ? "\(unreadCount)" : "99+"
let fontSize = (unreadCount < 100) ? Values.verySmallFontSize : 8 let fontSize = (unreadCount < 100) ? Values.verySmallFontSize : 8
unreadCountLabel.font = .boldSystemFont(ofSize: fontSize) unreadCountLabel.font = .boldSystemFont(ofSize: fontSize)
hasMentionView.isHidden = !threadViewModel.hasUnreadMentions
profilePictureView.update(for: thread) profilePictureView.update(for: thread)
displayNameLabel.text = getDisplayName() displayNameLabel.text = getDisplayName()
timestampLabel.text = DateUtil.formatDate(forDisplay: threadViewModel.lastMessageDate) timestampLabel.text = DateUtil.formatDate(forDisplay: threadViewModel.lastMessageDate)

@ -57,6 +57,9 @@ BOOL IsNoteToSelfEnabled(void);
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:)); NS_SWIFT_NAME(unreadMessageCount(transaction:));
- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(hasUnreadMentionMessage(transaction:));
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
/** /**

@ -264,6 +264,32 @@ BOOL IsNoteToSelfEnabled(void)
return count; return count;
} }
- (BOOL)hasUnreadMentionMessageWithTransaction:(YapDatabaseReadTransaction *)transaction
{
__block BOOL hasUnreadMention = false;
YapDatabaseViewTransaction *unreadMessages = [transaction ext:TSUnreadDatabaseViewExtensionName];
[unreadMessages enumerateKeysAndObjectsInGroup:self.uniqueId
usingBlock:^(NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
if (![object isKindOfClass:[TSIncomingMessage class]]) {
return;
}
TSIncomingMessage* unreadMessage = (TSIncomingMessage*)object;
if (unreadMessage.read) {
NSLog(@"Found an already read message in the * unread * messages list.");
return;
}
if (unreadMessage.isUserMentioned) {
hasUnreadMention = true;
*stop = YES;
}
}];
return hasUnreadMention;
}
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) { for (id<OWSReadTracking> message in [self unseenMessagesWithTransaction:transaction]) {

@ -15,6 +15,7 @@ public class ThreadViewModel: NSObject {
@objc public let name: String @objc public let name: String
@objc public let isMuted: Bool @objc public let isMuted: Bool
@objc public let isOnlyNotifyingForMentions: Bool @objc public let isOnlyNotifyingForMentions: Bool
@objc public let hasUnreadMentions: Bool
var isContactThread: Bool { var isContactThread: Bool {
return !isGroupThread return !isGroupThread
@ -49,6 +50,7 @@ public class ThreadViewModel: NSObject {
self.unreadCount = thread.unreadMessageCount(transaction: transaction) self.unreadCount = thread.unreadMessageCount(transaction: transaction)
self.hasUnreadMessages = unreadCount > 0 self.hasUnreadMessages = unreadCount > 0
self.hasUnreadMentions = thread.hasUnreadMentionMessage(transaction: transaction)
} }
@objc @objc

Loading…
Cancel
Save