|
|
@ -18,22 +18,23 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
|
|
|
|
public enum Section: SessionTableSection {
|
|
|
|
public enum Section: SessionTableSection {
|
|
|
|
case type
|
|
|
|
case type
|
|
|
|
case timer
|
|
|
|
case timer
|
|
|
|
|
|
|
|
case timerWithOff
|
|
|
|
|
|
|
|
|
|
|
|
var title: String? {
|
|
|
|
var title: String? {
|
|
|
|
switch self {
|
|
|
|
switch self {
|
|
|
|
case .type: return "DISAPPERING_MESSAGES_TYPE_TITLE".localized()
|
|
|
|
case .type: return "DISAPPERING_MESSAGES_TYPE_TITLE".localized()
|
|
|
|
case .timer: return "DISAPPERING_MESSAGES_TIMER_TITLE".localized()
|
|
|
|
case .timer: return "DISAPPERING_MESSAGES_TIMER_TITLE".localized()
|
|
|
|
|
|
|
|
case .timerWithOff: return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var style: SessionTableSectionStyle { return .title }
|
|
|
|
var style: SessionTableSectionStyle { return .title }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum Item: Differentiable {
|
|
|
|
public struct Item: Equatable, Hashable, Differentiable {
|
|
|
|
case off
|
|
|
|
let title: String
|
|
|
|
case disappearAfterRead
|
|
|
|
|
|
|
|
case disappearAfterSend
|
|
|
|
public var differenceIdentifier: String { title }
|
|
|
|
case currentSetting
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Variables
|
|
|
|
// MARK: - Variables
|
|
|
@ -79,79 +80,135 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
|
|
|
|
private lazy var _observableSettingsData: ObservableData = {
|
|
|
|
private lazy var _observableSettingsData: ObservableData = {
|
|
|
|
self.currentSelection
|
|
|
|
self.currentSelection
|
|
|
|
.map { [weak self] currentSelection in
|
|
|
|
.map { [weak self] currentSelection in
|
|
|
|
return [
|
|
|
|
guard let threadVariant = self?.threadVariant else { return [] }
|
|
|
|
SectionModel(
|
|
|
|
|
|
|
|
model: .type,
|
|
|
|
switch threadVariant {
|
|
|
|
elements: [
|
|
|
|
case .contact:
|
|
|
|
SessionCell.Info(
|
|
|
|
return [
|
|
|
|
id: .off,
|
|
|
|
SectionModel(
|
|
|
|
title: "DISAPPEARING_MESSAGES_OFF".localized(),
|
|
|
|
model: .type,
|
|
|
|
rightAccessory: .radio(
|
|
|
|
elements: [
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == false) }
|
|
|
|
SessionCell.Info(
|
|
|
|
),
|
|
|
|
id: Item(title: "DISAPPEARING_MESSAGES_OFF".localized()),
|
|
|
|
onTap: {
|
|
|
|
title: "DISAPPEARING_MESSAGES_OFF".localized(),
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
rightAccessory: .radio(
|
|
|
|
.with(
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == false) }
|
|
|
|
isEnabled: false,
|
|
|
|
),
|
|
|
|
durationSeconds: 0,
|
|
|
|
onTap: {
|
|
|
|
type: nil
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
)
|
|
|
|
.with(
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
isEnabled: false,
|
|
|
|
}
|
|
|
|
durationSeconds: 0,
|
|
|
|
),
|
|
|
|
type: nil
|
|
|
|
SessionCell.Info(
|
|
|
|
)
|
|
|
|
id: .disappearAfterRead,
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
title: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized(),
|
|
|
|
}
|
|
|
|
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_DESCRIPTION".localized(),
|
|
|
|
),
|
|
|
|
rightAccessory: .radio(
|
|
|
|
SessionCell.Info(
|
|
|
|
isSelected: { (self?.currentSelection.value.type == .disappearAfterRead) }
|
|
|
|
id: Item(title: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized()),
|
|
|
|
),
|
|
|
|
title: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized(),
|
|
|
|
onTap: {
|
|
|
|
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_DESCRIPTION".localized(),
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
rightAccessory: .radio(
|
|
|
|
.with(
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == true) && (self?.currentSelection.value.type == .disappearAfterRead) }
|
|
|
|
isEnabled: true,
|
|
|
|
),
|
|
|
|
durationSeconds: (24 * 60 * 60),
|
|
|
|
onTap: {
|
|
|
|
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
)
|
|
|
|
.with(
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
isEnabled: true,
|
|
|
|
}
|
|
|
|
durationSeconds: (24 * 60 * 60),
|
|
|
|
),
|
|
|
|
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead
|
|
|
|
SessionCell.Info(
|
|
|
|
)
|
|
|
|
id: .disappearAfterSend,
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
|
|
|
|
}
|
|
|
|
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
|
|
|
|
|
|
|
|
rightAccessory: .radio(
|
|
|
|
|
|
|
|
isSelected: { (self?.currentSelection.value.type == .disappearAfterSend) }
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
onTap: {
|
|
|
|
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
|
|
|
|
.with(
|
|
|
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
|
|
|
durationSeconds: (24 * 60 * 60),
|
|
|
|
|
|
|
|
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
].appending(
|
|
|
|
|
|
|
|
(currentSelection.isEnabled == false) ? nil :
|
|
|
|
|
|
|
|
SectionModel(
|
|
|
|
|
|
|
|
model: .timer,
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
SessionCell.Info(
|
|
|
|
|
|
|
|
id: .currentSetting,
|
|
|
|
|
|
|
|
title: currentSelection.durationSeconds.formatted(format: .long),
|
|
|
|
|
|
|
|
rightAccessory: .icon(
|
|
|
|
|
|
|
|
UIImage(named: "ic_chevron_down")?
|
|
|
|
|
|
|
|
.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: { }
|
|
|
|
SessionCell.Info(
|
|
|
|
|
|
|
|
id: Item(title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized()),
|
|
|
|
|
|
|
|
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
|
|
|
|
|
|
|
|
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
|
|
|
|
|
|
|
|
rightAccessory: .radio(
|
|
|
|
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == true) && (self?.currentSelection.value.type == .disappearAfterSend) }
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
onTap: {
|
|
|
|
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
|
|
|
|
.with(
|
|
|
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
|
|
|
durationSeconds: (24 * 60 * 60),
|
|
|
|
|
|
|
|
type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
].appending(
|
|
|
|
|
|
|
|
(currentSelection.isEnabled == false) ? nil :
|
|
|
|
|
|
|
|
SectionModel(
|
|
|
|
|
|
|
|
model: .timer,
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
SessionCell.Info(
|
|
|
|
|
|
|
|
id: Item(title: "Current Setting"),
|
|
|
|
|
|
|
|
title: currentSelection.durationSeconds.formatted(format: .long),
|
|
|
|
|
|
|
|
rightAccessory: .icon(
|
|
|
|
|
|
|
|
UIImage(named: "ic_chevron_down")?
|
|
|
|
|
|
|
|
.withRenderingMode(.alwaysTemplate)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
onTap: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
case .closedGroup:
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
SectionModel(
|
|
|
|
|
|
|
|
model: .timerWithOff,
|
|
|
|
|
|
|
|
elements: [
|
|
|
|
|
|
|
|
SessionCell.Info(
|
|
|
|
|
|
|
|
id: Item(title: "DISAPPEARING_MESSAGES_OFF".localized()),
|
|
|
|
|
|
|
|
title: "DISAPPEARING_MESSAGES_OFF".localized(),
|
|
|
|
|
|
|
|
rightAccessory: .radio(
|
|
|
|
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == false) }
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
onTap: {
|
|
|
|
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
|
|
|
|
.with(
|
|
|
|
|
|
|
|
isEnabled: false,
|
|
|
|
|
|
|
|
durationSeconds: 0,
|
|
|
|
|
|
|
|
type: nil
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
].appending(
|
|
|
|
|
|
|
|
contentsOf: DisappearingMessagesConfiguration
|
|
|
|
|
|
|
|
.validDurationsSeconds(.disappearAfterRead)
|
|
|
|
|
|
|
|
.map { duration in
|
|
|
|
|
|
|
|
let title: String = duration.formatted(format: .long)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SessionCell.Info(
|
|
|
|
|
|
|
|
id: Item(title: title),
|
|
|
|
|
|
|
|
title: title,
|
|
|
|
|
|
|
|
rightAccessory: .radio(
|
|
|
|
|
|
|
|
isSelected: { (self?.currentSelection.value.isEnabled == true) && (self?.currentSelection.value.durationSeconds == duration) }
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
onTap: {
|
|
|
|
|
|
|
|
let updatedConfig: DisappearingMessagesConfiguration = currentSelection
|
|
|
|
|
|
|
|
.with(
|
|
|
|
|
|
|
|
isEnabled: true,
|
|
|
|
|
|
|
|
durationSeconds: duration,
|
|
|
|
|
|
|
|
type: .disappearAfterRead
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self?.currentSelection.send(updatedConfig)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
case . openGroup:
|
|
|
|
|
|
|
|
return [] // Should not happen
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.removeDuplicates()
|
|
|
|
.removeDuplicates()
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|