WIP: fetch disappearing message config from database

pull/941/head
ryanzhao 2 years ago
parent 6c4adc08e1
commit 54914d69c6

@ -556,7 +556,8 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
viewModel.threadData.threadIsNoteToSelf != updatedThreadData.threadIsNoteToSelf ||
viewModel.threadData.threadMutedUntilTimestamp != updatedThreadData.threadMutedUntilTimestamp ||
viewModel.threadData.threadOnlyNotifyForMentions != updatedThreadData.threadOnlyNotifyForMentions ||
viewModel.threadData.userCount != updatedThreadData.userCount
viewModel.threadData.userCount != updatedThreadData.userCount ||
viewModel.threadData.disappearingMessagesConfiguration != updatedThreadData.disappearingMessagesConfiguration
{
titleView.update(
with: updatedThreadData.displayName,
@ -564,7 +565,8 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
threadVariant: updatedThreadData.threadVariant,
mutedUntilTimestamp: updatedThreadData.threadMutedUntilTimestamp,
onlyNotifyForMentions: (updatedThreadData.threadOnlyNotifyForMentions == true),
userCount: updatedThreadData.userCount
userCount: updatedThreadData.userCount,
disappearingMessagesConfig: updatedThreadData.disappearingMessagesConfiguration
)
}

@ -137,6 +137,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
.conversationQuery(threadId: threadId, userPublicKey: userPublicKey)
.fetchOne(db)
return threadViewModel
.map { $0.with(recentReactionEmoji: recentReactionEmoji) }
}

@ -110,7 +110,8 @@ final class ConversationTitleView: UIView {
threadVariant: threadVariant,
mutedUntilTimestamp: nil,
onlyNotifyForMentions: false,
userCount: (threadVariant != .contact ? 0 : nil)
userCount: (threadVariant != .contact ? 0 : nil),
disappearingMessagesConfig: nil
)
}
@ -138,7 +139,8 @@ final class ConversationTitleView: UIView {
threadVariant: SessionThread.Variant,
mutedUntilTimestamp: TimeInterval?,
onlyNotifyForMentions: Bool,
userCount: Int?
userCount: Int?,
disappearingMessagesConfig: DisappearingMessagesConfiguration?
) {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in
@ -148,7 +150,8 @@ final class ConversationTitleView: UIView {
threadVariant: threadVariant,
mutedUntilTimestamp: mutedUntilTimestamp,
onlyNotifyForMentions: onlyNotifyForMentions,
userCount: userCount
userCount: userCount,
disappearingMessagesConfig: disappearingMessagesConfig
)
}
return
@ -157,7 +160,8 @@ final class ConversationTitleView: UIView {
let shouldHaveSubtitle: Bool = (
Date().timeIntervalSince1970 <= (mutedUntilTimestamp ?? 0) ||
onlyNotifyForMentions ||
userCount != nil
userCount != nil ||
disappearingMessagesConfig?.isEnabled == true
)
self.titleLabel.text = name
@ -219,6 +223,25 @@ final class ConversationTitleView: UIView {
}
// TODO: Disappearing message settings
if let config = disappearingMessagesConfig, config.isEnabled == true {
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "ic_timer")?.withTint(textPrimary)
imageAttachment.bounds = CGRect(
x: 0,
y: -2,
width: Values.smallFontSize,
height: Values.smallFontSize
)
self?.notificationSettingsLabel.attributedText = NSAttributedString(attachment: imageAttachment)
.appending(string: " ")
.appending(string: config.type == .disappearAfterRead ? "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized() : "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized())
.appending(string: " - ")
.appending(string: config.durationString)
self?.disappearingMessageSettingLabel.isHidden = false
slides.append(self?.disappearingMessageSettingLabel)
}
self?.pagedScrollView.update(
with: slides.compactMap{ $0 },
slideSize: CGSize(

@ -4,7 +4,7 @@ import Foundation
import GRDB
import SessionUtilitiesKit
public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatable, Hashable, FetchableRecord, PersistableRecord, TableRecord, ColumnExpressible {
public static var databaseTableName: String { "disappearingMessagesConfiguration" }
internal static let threadForeignKey = ForeignKey([Columns.threadId], to: [SessionThread.Columns.id])
private static let thread = belongsTo(SessionThread.self, using: threadForeignKey)
@ -27,7 +27,7 @@ public struct DisappearingMessagesConfiguration: Codable, Identifiable, Equatabl
public let threadId: String
public let isEnabled: Bool
public let durationSeconds: TimeInterval
public var type: DisappearingMessageType? = nil
public var type: DisappearingMessageType?
// MARK: - Relationships

@ -32,6 +32,7 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat
public static let threadContactIsTypingKey: SQL = SQL(stringLiteral: CodingKeys.threadContactIsTyping.stringValue)
public static let threadUnreadCountKey: SQL = SQL(stringLiteral: CodingKeys.threadUnreadCount.stringValue)
public static let threadUnreadMentionCountKey: SQL = SQL(stringLiteral: CodingKeys.threadUnreadMentionCount.stringValue)
public static let disappearingMessagesConfigurationKey: SQL = SQL(stringLiteral: CodingKeys.disappearingMessagesConfiguration.stringValue)
public static let contactProfileKey: SQL = SQL(stringLiteral: CodingKeys.contactProfile.stringValue)
public static let closedGroupNameKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupName.stringValue)
public static let closedGroupUserCountKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupUserCount.stringValue)
@ -106,6 +107,8 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat
// Thread display info
public let disappearingMessagesConfiguration: DisappearingMessagesConfiguration?
private let contactProfile: Profile?
private let closedGroupProfileFront: Profile?
private let closedGroupProfileBack: Profile?
@ -239,7 +242,8 @@ public extension SessionThreadViewModel {
threadIsNoteToSelf: Bool = false,
contactProfile: Profile? = nil,
currentUserIsClosedGroupMember: Bool? = nil,
unreadCount: UInt = 0
unreadCount: UInt = 0,
disappearingMessagesConfiguration: DisappearingMessagesConfiguration? = nil
) {
self.rowId = -1
self.threadId = (threadId ?? SessionThreadViewModel.invalidId)
@ -263,6 +267,8 @@ public extension SessionThreadViewModel {
// Thread display info
self.disappearingMessagesConfiguration = disappearingMessagesConfiguration
self.contactProfile = contactProfile
self.closedGroupProfileFront = nil
self.closedGroupProfileBack = nil
@ -323,6 +329,7 @@ public extension SessionThreadViewModel {
threadContactIsTyping: self.threadContactIsTyping,
threadUnreadCount: self.threadUnreadCount,
threadUnreadMentionCount: self.threadUnreadMentionCount,
disappearingMessagesConfiguration: self.disappearingMessagesConfiguration,
contactProfile: self.contactProfile,
closedGroupProfileFront: self.closedGroupProfileFront,
closedGroupProfileBack: self.closedGroupProfileBack,
@ -376,6 +383,7 @@ public extension SessionThreadViewModel {
threadContactIsTyping: self.threadContactIsTyping,
threadUnreadCount: self.threadUnreadCount,
threadUnreadMentionCount: self.threadUnreadMentionCount,
disappearingMessagesConfiguration: self.disappearingMessagesConfiguration,
contactProfile: self.contactProfile,
closedGroupProfileFront: self.closedGroupProfileFront,
closedGroupProfileBack: self.closedGroupProfileBack,
@ -703,6 +711,7 @@ public extension SessionThreadViewModel {
/// but including this warning just in case there is a discrepancy)
static func conversationQuery(threadId: String, userPublicKey: String) -> AdaptedFetchRequest<SQLRequest<SessionThreadViewModel>> {
let thread: TypedTableAlias<SessionThread> = TypedTableAlias()
let disappearingMessagesConfiguration: TypedTableAlias<DisappearingMessagesConfiguration> = TypedTableAlias()
let contact: TypedTableAlias<Contact> = TypedTableAlias()
let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias()
let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias()
@ -745,6 +754,8 @@ public extension SessionThreadViewModel {
\(thread[.messageDraft]) AS \(ViewModel.threadMessageDraftKey),
\(Interaction.self).\(ViewModel.threadUnreadCountKey),
\(ViewModel.disappearingMessagesConfigurationKey).*,
\(ViewModel.contactProfileKey).*,
\(closedGroup[.name]) AS \(ViewModel.closedGroupNameKey),
@ -761,6 +772,7 @@ public extension SessionThreadViewModel {
\(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey)
FROM \(SessionThread.self)
LEFT JOIN \(DisappearingMessagesConfiguration.self) ON \(disappearingMessagesConfiguration[.threadId]) = \(thread[.id])
LEFT JOIN \(Contact.self) ON \(contact[.id]) = \(thread[.id])
LEFT JOIN (
-- Fetch all interaction-specific data in a subquery to be more efficient
@ -811,6 +823,7 @@ public extension SessionThreadViewModel {
static func conversationSettingsQuery(threadId: String, userPublicKey: String) -> AdaptedFetchRequest<SQLRequest<SessionThreadViewModel>> {
let thread: TypedTableAlias<SessionThread> = TypedTableAlias()
let disappearingMessagesConfiguration: TypedTableAlias<DisappearingMessagesConfiguration> = TypedTableAlias()
let contact: TypedTableAlias<Contact> = TypedTableAlias()
let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias()
let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias()
@ -838,6 +851,8 @@ public extension SessionThreadViewModel {
\(contact[.isBlocked]) AS \(ViewModel.threadIsBlockedKey),
\(thread[.mutedUntilTimestamp]) AS \(ViewModel.threadMutedUntilTimestampKey),
\(thread[.onlyNotifyForMentions]) AS \(ViewModel.threadOnlyNotifyForMentionsKey),
\(ViewModel.disappearingMessagesConfigurationKey).*,
\(ViewModel.contactProfileKey).*,
\(ViewModel.closedGroupProfileFrontKey).*,
@ -852,6 +867,7 @@ public extension SessionThreadViewModel {
\(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey)
FROM \(SessionThread.self)
LEFT JOIN \(DisappearingMessagesConfiguration.self) ON \(disappearingMessagesConfiguration[.threadId]) = \(thread[.id])
LEFT JOIN \(Contact.self) ON \(contact[.id]) = \(thread[.id])
LEFT JOIN \(Profile.self) AS \(ViewModel.contactProfileKey) ON \(ViewModel.contactProfileKey).\(profileIdColumnLiteral) = \(thread[.id])
LEFT JOIN \(OpenGroup.self) ON \(openGroup[.threadId]) = \(thread[.id])

Loading…
Cancel
Save