WIP: fetch disappearing message config from database

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

@ -556,7 +556,8 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
viewModel.threadData.threadIsNoteToSelf != updatedThreadData.threadIsNoteToSelf || viewModel.threadData.threadIsNoteToSelf != updatedThreadData.threadIsNoteToSelf ||
viewModel.threadData.threadMutedUntilTimestamp != updatedThreadData.threadMutedUntilTimestamp || viewModel.threadData.threadMutedUntilTimestamp != updatedThreadData.threadMutedUntilTimestamp ||
viewModel.threadData.threadOnlyNotifyForMentions != updatedThreadData.threadOnlyNotifyForMentions || viewModel.threadData.threadOnlyNotifyForMentions != updatedThreadData.threadOnlyNotifyForMentions ||
viewModel.threadData.userCount != updatedThreadData.userCount viewModel.threadData.userCount != updatedThreadData.userCount ||
viewModel.threadData.disappearingMessagesConfiguration != updatedThreadData.disappearingMessagesConfiguration
{ {
titleView.update( titleView.update(
with: updatedThreadData.displayName, with: updatedThreadData.displayName,
@ -564,7 +565,8 @@ final class ConversationVC: BaseVC, ConversationSearchControllerDelegate, UITabl
threadVariant: updatedThreadData.threadVariant, threadVariant: updatedThreadData.threadVariant,
mutedUntilTimestamp: updatedThreadData.threadMutedUntilTimestamp, mutedUntilTimestamp: updatedThreadData.threadMutedUntilTimestamp,
onlyNotifyForMentions: (updatedThreadData.threadOnlyNotifyForMentions == true), 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) .conversationQuery(threadId: threadId, userPublicKey: userPublicKey)
.fetchOne(db) .fetchOne(db)
return threadViewModel return threadViewModel
.map { $0.with(recentReactionEmoji: recentReactionEmoji) } .map { $0.with(recentReactionEmoji: recentReactionEmoji) }
} }

@ -110,7 +110,8 @@ final class ConversationTitleView: UIView {
threadVariant: threadVariant, threadVariant: threadVariant,
mutedUntilTimestamp: nil, mutedUntilTimestamp: nil,
onlyNotifyForMentions: false, 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, threadVariant: SessionThread.Variant,
mutedUntilTimestamp: TimeInterval?, mutedUntilTimestamp: TimeInterval?,
onlyNotifyForMentions: Bool, onlyNotifyForMentions: Bool,
userCount: Int? userCount: Int?,
disappearingMessagesConfig: DisappearingMessagesConfiguration?
) { ) {
guard Thread.isMainThread else { guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
@ -148,7 +150,8 @@ final class ConversationTitleView: UIView {
threadVariant: threadVariant, threadVariant: threadVariant,
mutedUntilTimestamp: mutedUntilTimestamp, mutedUntilTimestamp: mutedUntilTimestamp,
onlyNotifyForMentions: onlyNotifyForMentions, onlyNotifyForMentions: onlyNotifyForMentions,
userCount: userCount userCount: userCount,
disappearingMessagesConfig: disappearingMessagesConfig
) )
} }
return return
@ -157,7 +160,8 @@ final class ConversationTitleView: UIView {
let shouldHaveSubtitle: Bool = ( let shouldHaveSubtitle: Bool = (
Date().timeIntervalSince1970 <= (mutedUntilTimestamp ?? 0) || Date().timeIntervalSince1970 <= (mutedUntilTimestamp ?? 0) ||
onlyNotifyForMentions || onlyNotifyForMentions ||
userCount != nil userCount != nil ||
disappearingMessagesConfig?.isEnabled == true
) )
self.titleLabel.text = name self.titleLabel.text = name
@ -219,6 +223,25 @@ final class ConversationTitleView: UIView {
} }
// TODO: Disappearing message settings // 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( self?.pagedScrollView.update(
with: slides.compactMap{ $0 }, with: slides.compactMap{ $0 },
slideSize: CGSize( slideSize: CGSize(

@ -4,7 +4,7 @@ import Foundation
import GRDB import GRDB
import SessionUtilitiesKit 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" } public static var databaseTableName: String { "disappearingMessagesConfiguration" }
internal static let threadForeignKey = ForeignKey([Columns.threadId], to: [SessionThread.Columns.id]) internal static let threadForeignKey = ForeignKey([Columns.threadId], to: [SessionThread.Columns.id])
private static let thread = belongsTo(SessionThread.self, using: threadForeignKey) 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 threadId: String
public let isEnabled: Bool public let isEnabled: Bool
public let durationSeconds: TimeInterval public let durationSeconds: TimeInterval
public var type: DisappearingMessageType? = nil public var type: DisappearingMessageType?
// MARK: - Relationships // 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 threadContactIsTypingKey: SQL = SQL(stringLiteral: CodingKeys.threadContactIsTyping.stringValue)
public static let threadUnreadCountKey: SQL = SQL(stringLiteral: CodingKeys.threadUnreadCount.stringValue) public static let threadUnreadCountKey: SQL = SQL(stringLiteral: CodingKeys.threadUnreadCount.stringValue)
public static let threadUnreadMentionCountKey: SQL = SQL(stringLiteral: CodingKeys.threadUnreadMentionCount.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 contactProfileKey: SQL = SQL(stringLiteral: CodingKeys.contactProfile.stringValue)
public static let closedGroupNameKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupName.stringValue) public static let closedGroupNameKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupName.stringValue)
public static let closedGroupUserCountKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupUserCount.stringValue) public static let closedGroupUserCountKey: SQL = SQL(stringLiteral: CodingKeys.closedGroupUserCount.stringValue)
@ -106,6 +107,8 @@ public struct SessionThreadViewModel: FetchableRecordWithRowId, Decodable, Equat
// Thread display info // Thread display info
public let disappearingMessagesConfiguration: DisappearingMessagesConfiguration?
private let contactProfile: Profile? private let contactProfile: Profile?
private let closedGroupProfileFront: Profile? private let closedGroupProfileFront: Profile?
private let closedGroupProfileBack: Profile? private let closedGroupProfileBack: Profile?
@ -239,7 +242,8 @@ public extension SessionThreadViewModel {
threadIsNoteToSelf: Bool = false, threadIsNoteToSelf: Bool = false,
contactProfile: Profile? = nil, contactProfile: Profile? = nil,
currentUserIsClosedGroupMember: Bool? = nil, currentUserIsClosedGroupMember: Bool? = nil,
unreadCount: UInt = 0 unreadCount: UInt = 0,
disappearingMessagesConfiguration: DisappearingMessagesConfiguration? = nil
) { ) {
self.rowId = -1 self.rowId = -1
self.threadId = (threadId ?? SessionThreadViewModel.invalidId) self.threadId = (threadId ?? SessionThreadViewModel.invalidId)
@ -263,6 +267,8 @@ public extension SessionThreadViewModel {
// Thread display info // Thread display info
self.disappearingMessagesConfiguration = disappearingMessagesConfiguration
self.contactProfile = contactProfile self.contactProfile = contactProfile
self.closedGroupProfileFront = nil self.closedGroupProfileFront = nil
self.closedGroupProfileBack = nil self.closedGroupProfileBack = nil
@ -323,6 +329,7 @@ public extension SessionThreadViewModel {
threadContactIsTyping: self.threadContactIsTyping, threadContactIsTyping: self.threadContactIsTyping,
threadUnreadCount: self.threadUnreadCount, threadUnreadCount: self.threadUnreadCount,
threadUnreadMentionCount: self.threadUnreadMentionCount, threadUnreadMentionCount: self.threadUnreadMentionCount,
disappearingMessagesConfiguration: self.disappearingMessagesConfiguration,
contactProfile: self.contactProfile, contactProfile: self.contactProfile,
closedGroupProfileFront: self.closedGroupProfileFront, closedGroupProfileFront: self.closedGroupProfileFront,
closedGroupProfileBack: self.closedGroupProfileBack, closedGroupProfileBack: self.closedGroupProfileBack,
@ -376,6 +383,7 @@ public extension SessionThreadViewModel {
threadContactIsTyping: self.threadContactIsTyping, threadContactIsTyping: self.threadContactIsTyping,
threadUnreadCount: self.threadUnreadCount, threadUnreadCount: self.threadUnreadCount,
threadUnreadMentionCount: self.threadUnreadMentionCount, threadUnreadMentionCount: self.threadUnreadMentionCount,
disappearingMessagesConfiguration: self.disappearingMessagesConfiguration,
contactProfile: self.contactProfile, contactProfile: self.contactProfile,
closedGroupProfileFront: self.closedGroupProfileFront, closedGroupProfileFront: self.closedGroupProfileFront,
closedGroupProfileBack: self.closedGroupProfileBack, closedGroupProfileBack: self.closedGroupProfileBack,
@ -703,6 +711,7 @@ public extension SessionThreadViewModel {
/// but including this warning just in case there is a discrepancy) /// but including this warning just in case there is a discrepancy)
static func conversationQuery(threadId: String, userPublicKey: String) -> AdaptedFetchRequest<SQLRequest<SessionThreadViewModel>> { static func conversationQuery(threadId: String, userPublicKey: String) -> AdaptedFetchRequest<SQLRequest<SessionThreadViewModel>> {
let thread: TypedTableAlias<SessionThread> = TypedTableAlias() let thread: TypedTableAlias<SessionThread> = TypedTableAlias()
let disappearingMessagesConfiguration: TypedTableAlias<DisappearingMessagesConfiguration> = TypedTableAlias()
let contact: TypedTableAlias<Contact> = TypedTableAlias() let contact: TypedTableAlias<Contact> = TypedTableAlias()
let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias() let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias()
let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias() let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias()
@ -746,6 +755,8 @@ public extension SessionThreadViewModel {
\(Interaction.self).\(ViewModel.threadUnreadCountKey), \(Interaction.self).\(ViewModel.threadUnreadCountKey),
\(ViewModel.disappearingMessagesConfigurationKey).*,
\(ViewModel.contactProfileKey).*, \(ViewModel.contactProfileKey).*,
\(closedGroup[.name]) AS \(ViewModel.closedGroupNameKey), \(closedGroup[.name]) AS \(ViewModel.closedGroupNameKey),
\(closedGroupUserCountTableLiteral).\(ViewModel.closedGroupUserCountKey) AS \(ViewModel.closedGroupUserCountKey), \(closedGroupUserCountTableLiteral).\(ViewModel.closedGroupUserCountKey) AS \(ViewModel.closedGroupUserCountKey),
@ -761,6 +772,7 @@ public extension SessionThreadViewModel {
\(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey) \(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey)
FROM \(SessionThread.self) FROM \(SessionThread.self)
LEFT JOIN \(DisappearingMessagesConfiguration.self) ON \(disappearingMessagesConfiguration[.threadId]) = \(thread[.id])
LEFT JOIN \(Contact.self) ON \(contact[.id]) = \(thread[.id]) LEFT JOIN \(Contact.self) ON \(contact[.id]) = \(thread[.id])
LEFT JOIN ( LEFT JOIN (
-- Fetch all interaction-specific data in a subquery to be more efficient -- 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>> { static func conversationSettingsQuery(threadId: String, userPublicKey: String) -> AdaptedFetchRequest<SQLRequest<SessionThreadViewModel>> {
let thread: TypedTableAlias<SessionThread> = TypedTableAlias() let thread: TypedTableAlias<SessionThread> = TypedTableAlias()
let disappearingMessagesConfiguration: TypedTableAlias<DisappearingMessagesConfiguration> = TypedTableAlias()
let contact: TypedTableAlias<Contact> = TypedTableAlias() let contact: TypedTableAlias<Contact> = TypedTableAlias()
let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias() let closedGroup: TypedTableAlias<ClosedGroup> = TypedTableAlias()
let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias() let groupMember: TypedTableAlias<GroupMember> = TypedTableAlias()
@ -839,6 +852,8 @@ public extension SessionThreadViewModel {
\(thread[.mutedUntilTimestamp]) AS \(ViewModel.threadMutedUntilTimestampKey), \(thread[.mutedUntilTimestamp]) AS \(ViewModel.threadMutedUntilTimestampKey),
\(thread[.onlyNotifyForMentions]) AS \(ViewModel.threadOnlyNotifyForMentionsKey), \(thread[.onlyNotifyForMentions]) AS \(ViewModel.threadOnlyNotifyForMentionsKey),
\(ViewModel.disappearingMessagesConfigurationKey).*,
\(ViewModel.contactProfileKey).*, \(ViewModel.contactProfileKey).*,
\(ViewModel.closedGroupProfileFrontKey).*, \(ViewModel.closedGroupProfileFrontKey).*,
\(ViewModel.closedGroupProfileBackKey).*, \(ViewModel.closedGroupProfileBackKey).*,
@ -852,6 +867,7 @@ public extension SessionThreadViewModel {
\(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey) \(SQL("\(userPublicKey)")) AS \(ViewModel.currentUserPublicKeyKey)
FROM \(SessionThread.self) FROM \(SessionThread.self)
LEFT JOIN \(DisappearingMessagesConfiguration.self) ON \(disappearingMessagesConfiguration[.threadId]) = \(thread[.id])
LEFT JOIN \(Contact.self) ON \(contact[.id]) = \(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 \(Profile.self) AS \(ViewModel.contactProfileKey) ON \(ViewModel.contactProfileKey).\(profileIdColumnLiteral) = \(thread[.id])
LEFT JOIN \(OpenGroup.self) ON \(openGroup[.threadId]) = \(thread[.id]) LEFT JOIN \(OpenGroup.self) ON \(openGroup[.threadId]) = \(thread[.id])

Loading…
Cancel
Save