WIP: add receivedAtTimestampMs to MessageViewModel

pull/782/head
Ryan Zhao 2 years ago
parent 7f5e03fad9
commit d97730ab63

@ -38,7 +38,7 @@ extension ContextMenuVC {
private lazy var displayNameLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.verySmallFontSize)
result.font = .boldSystemFont(ofSize: Values.verySmallFontSize)
result.themeTextColor = .textPrimary
return result
@ -83,7 +83,35 @@ extension ContextMenuVC {
backgroundView.addSubview(stackView)
stackView.pin(to: backgroundView)
messageSentDateLabel.text = "MESSAGE_INFO_SENT".localized() + ":\n" + cellViewModel.dateForUI.fromattedForMessageInfo
stackView.addArrangedSubview(messageSentDateLabel)
messageReceivedDateLabel.text = "MESSAGE_INFO_RECEIVED".localized() + ":\n" + cellViewModel.receivedDateForUI.fromattedForMessageInfo
stackView.addArrangedSubview(messageReceivedDateLabel)
let senderTitleLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: Values.mediumFontSize)
result.themeTextColor = .textPrimary
result.text = "MESSAGE_INFO_FROM".localized() + ":"
return result
}()
stackView.addArrangedSubview(senderTitleLabel)
let displayNameStackView: UIStackView = UIStackView(arrangedSubviews: [ displayNameLabel, sessionIDLabel ])
displayNameStackView.axis = .vertical
displayNameLabel.text = cellViewModel.authorName
sessionIDLabel.text = cellViewModel.authorId
let profileStackView: UIStackView = UIStackView(arrangedSubviews: [ profilePictureView, displayNameStackView ])
profileStackView.axis = .horizontal
profilePictureView.update(
publicKey: cellViewModel.authorId,
profile: cellViewModel.profile,
threadVariant: cellViewModel.threadVariant
)
stackView.addArrangedSubview(profileStackView)
}
}
}

@ -66,6 +66,7 @@ final class ContextMenuVC: UIViewController {
result.layer.shadowOpacity = 0.4
result.layer.shadowRadius = 4
result.alpha = 0
result.set(.width, lessThanOrEqualTo: 280)
return result
}()
@ -183,7 +184,6 @@ final class ContextMenuVC: UIViewController {
view.addSubview(menuView)
// MessageInfo
view.addSubview(messageInfoView)
// Timestamp
@ -230,18 +230,22 @@ final class ContextMenuVC: UIViewController {
snapshot.frame = self.frame
emojiBar.pin(.bottom, to: .top, of: view, withInset: targetFrame.minY - spacing)
menuView.pin(.top, to: .top, of: view, withInset: targetFrame.maxY + spacing)
messageInfoView.pin(.top, to: .top, of: view, withInset: targetFrame.maxY + spacing)
switch cellViewModel.variant {
case .standardOutgoing:
menuView.pin(.right, to: .right, of: view, withInset: -(UIScreen.main.bounds.width - targetFrame.maxX))
messageInfoView.pin(.right, to: .right, of: view, withInset: -(UIScreen.main.bounds.width - targetFrame.maxX))
emojiBar.pin(.right, to: .right, of: view, withInset: -(UIScreen.main.bounds.width - targetFrame.maxX))
case .standardIncoming, .standardIncomingDeleted:
menuView.pin(.left, to: .left, of: view, withInset: targetFrame.minX)
messageInfoView.pin(.left, to: .left, of: view, withInset: targetFrame.minX)
emojiBar.pin(.left, to: .left, of: view, withInset: targetFrame.minX)
default: // Should generally only be the 'delete' action
menuView.pin(.left, to: .left, of: view, withInset: targetFrame.minX)
messageInfoView.pin(.left, to: .left, of: view, withInset: targetFrame.minX)
}
// Tap gesture
@ -269,6 +273,7 @@ final class ContextMenuVC: UIViewController {
UIView.animate(withDuration: 0.2) { [weak self] in
self?.emojiBar.alpha = 1
self?.menuView.alpha = 1
self?.messageInfoView.alpha = 1
self?.timestampLabel.alpha = 1
self?.fallbackTimestampLabel.alpha = 1
}

@ -29,6 +29,14 @@ public extension Date {
return "DATE_NOW".localized()
}
var fromattedForMessageInfo: String {
let formatter: DateFormatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "h:mm a EEE, DD/MM/YYYY"
return formatter.string(from: self)
}
}
// MARK: - Formatters

@ -73,6 +73,7 @@ public struct MessageViewModel: FetchableRecordWithRowId, Decodable, Equatable,
public let id: Int64
public let variant: Interaction.Variant
public let timestampMs: Int64
public let receivedTimestampMs: Int64
public let authorId: String
private let authorNameInternal: String?
public let body: String?
@ -122,6 +123,9 @@ public struct MessageViewModel: FetchableRecordWithRowId, Decodable, Equatable,
/// This value will be used to populate the Context Menu and date header (if present)
public var dateForUI: Date { Date(timeIntervalSince1970: (TimeInterval(self.timestampMs) / 1000)) }
/// This value will be used to populate the Message Info (if present)
public var receivedDateForUI: Date { Date(timeIntervalSince1970: (TimeInterval(self.receivedTimestampMs) / 1000)) }
/// This value specifies whether the body contains only emoji characters
public let containsOnlyEmoji: Bool?
@ -161,6 +165,7 @@ public struct MessageViewModel: FetchableRecordWithRowId, Decodable, Equatable,
id: self.id,
variant: self.variant,
timestampMs: self.timestampMs,
receivedTimestampMs: self.receivedTimestampMs,
authorId: self.authorId,
authorNameInternal: self.authorNameInternal,
body: self.body,
@ -316,6 +321,7 @@ public struct MessageViewModel: FetchableRecordWithRowId, Decodable, Equatable,
id: self.id,
variant: self.variant,
timestampMs: self.timestampMs,
receivedTimestampMs: self.receivedTimestampMs,
authorId: self.authorId,
authorNameInternal: self.authorNameInternal,
body: (!self.variant.isInfoMessage ?
@ -494,6 +500,7 @@ public extension MessageViewModel {
init(
variant: Interaction.Variant = .standardOutgoing,
timestampMs: Int64 = Int64.max,
receivedTimestampMs: Int64 = Int64.max,
body: String? = nil,
quote: Quote? = nil,
cellType: CellType = .typingIndicator,
@ -520,6 +527,7 @@ public extension MessageViewModel {
self.id = targetId
self.variant = variant
self.timestampMs = timestampMs
self.receivedTimestampMs = receivedTimestampMs
self.authorId = ""
self.authorNameInternal = nil
self.body = body
@ -650,7 +658,7 @@ public extension MessageViewModel {
let groupMemberProfileIdColumnLiteral: SQL = SQL(stringLiteral: GroupMember.Columns.profileId.name)
let groupMemberRoleColumnLiteral: SQL = SQL(stringLiteral: GroupMember.Columns.role.name)
let numColumnsBeforeLinkedRecords: Int = 20
let numColumnsBeforeLinkedRecords: Int = 21
let finalGroupSQL: SQL = (groupSQL ?? "")
let request: SQLRequest<ViewModel> = """
SELECT
@ -668,6 +676,7 @@ public extension MessageViewModel {
\(interaction[.id]),
\(interaction[.variant]),
\(interaction[.timestampMs]),
\(interaction[.receivedAtTimestampMs]),
\(interaction[.authorId]),
IFNULL(\(profile[.nickname]), \(profile[.name])) AS \(ViewModel.authorNameInternalKey),
\(interaction[.body]),

Loading…
Cancel
Save