minor update to reduce database read on ui thread

pull/541/head
Ryan Zhao 3 years ago
parent cb127be5a2
commit e428333b7b

@ -291,6 +291,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
let viewItem = viewItems[indexPath.row] let viewItem = viewItems[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: MessageCell.getCellType(for: viewItem).identifier) as! MessageCell let cell = tableView.dequeueReusableCell(withIdentifier: MessageCell.getCellType(for: viewItem).identifier) as! MessageCell
cell.delegate = self cell.delegate = self
cell.thread = thread
cell.viewItem = viewItem cell.viewItem = viewItem
return cell return cell
} }

@ -1,4 +1,5 @@
import UIKit import UIKit
import SessionMessagingKit
public enum SwipeState { public enum SwipeState {
case began case began
@ -8,7 +9,16 @@ public enum SwipeState {
class MessageCell : UITableViewCell { class MessageCell : UITableViewCell {
weak var delegate: MessageCellDelegate? weak var delegate: MessageCellDelegate?
var viewItem: ConversationViewItem? { didSet { update() } } var thread: TSThread? {
didSet {
if viewItem != nil { update() }
}
}
var viewItem: ConversationViewItem? {
didSet {
if thread != nil { update() }
}
}
// MARK: Settings // MARK: Settings
class var identifier: String { preconditionFailure("Must be overridden by subclasses.") } class var identifier: String { preconditionFailure("Must be overridden by subclasses.") }

@ -257,7 +257,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
messageStatusImageView.image = image messageStatusImageView.image = image
messageStatusImageView.backgroundColor = backgroundColor messageStatusImageView.backgroundColor = backgroundColor
if let message = message as? TSOutgoingMessage { if let message = message as? TSOutgoingMessage {
messageStatusImageView.isHidden = (message.messageState == .sent && message.thread.lastInteraction != message) messageStatusImageView.isHidden = (message.messageState == .sent && thread?.lastInteraction != message)
} else { } else {
messageStatusImageView.isHidden = true messageStatusImageView.isHidden = true
} }
@ -349,7 +349,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
} }
case .mediaMessage: case .mediaMessage:
if viewItem.interaction is TSIncomingMessage, if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread, let thread = thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true { Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder() showMediaPlaceholder()
} else { } else {
@ -382,7 +382,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
} }
case .audio: case .audio:
if viewItem.interaction is TSIncomingMessage, if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread, let thread = thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true { Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder() showMediaPlaceholder()
} else { } else {
@ -393,7 +393,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
} }
case .genericAttachment: case .genericAttachment:
if viewItem.interaction is TSIncomingMessage, if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread, let thread = thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true { Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder() showMediaPlaceholder()
} else { } else {
@ -673,7 +673,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
private static func shouldShowProfilePicture(for viewItem: ConversationViewItem) -> Bool { private static func shouldShowProfilePicture(for viewItem: ConversationViewItem) -> Bool {
guard let message = viewItem.interaction as? TSMessage else { preconditionFailure() } guard let message = viewItem.interaction as? TSMessage else { preconditionFailure() }
let isGroupThread = message.thread.isGroupThread() let isGroupThread = viewItem.isGroupThread
let senderSessionID = (message as? TSIncomingMessage)?.authorId let senderSessionID = (message as? TSIncomingMessage)?.authorId
return isGroupThread && viewItem.shouldShowSenderProfilePicture && senderSessionID != nil return isGroupThread && viewItem.shouldShowSenderProfilePicture && senderSessionID != nil
} }

Loading…
Cancel
Save