feat: note to self disappearing message settings

pull/941/head
ryanzhao 2 years ago
parent 776b4c3234
commit 210cd29b72

@ -18,13 +18,15 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
public enum Section: SessionTableSection { public enum Section: SessionTableSection {
case type case type
case timer case timer
case timerWithOff case noteToSelf
case group
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 case .noteToSelf: return nil
case .group: return nil
} }
} }
@ -34,7 +36,8 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
switch self { switch self {
case .type: return nil case .type: return nil
case .timer: return nil case .timer: return nil
case .timerWithOff: return "DISAPPERING_MESSAGES_GROUP_WARNING_ADMIN_ONLY".localized() case .noteToSelf: return nil
case .group: return "DISAPPERING_MESSAGES_GROUP_WARNING_ADMIN_ONLY".localized()
} }
} }
} }
@ -116,6 +119,58 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
switch threadVariant { switch threadVariant {
case .contact: case .contact:
guard self?.threadId != getUserHexEncodedPublicKey() else {
return [
SectionModel(
model: .noteToSelf,
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,
lastChangeTimestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000)))
)
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig)
}
)
].appending(
contentsOf: DisappearingMessagesConfiguration
.validDurationsSeconds(.disappearAfterSend)
.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: .disappearAfterSend,
lastChangeTimestampMs: Int64(floor((Date().timeIntervalSince1970 * 1000)))
)
self?.shouldShowConfirmButton.send(updatedConfig != self?.config)
self?.currentSelection.send(updatedConfig)
}
)
}
)
)
]
}
return [ return [
SectionModel( SectionModel(
model: .type, model: .type,
@ -209,7 +264,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
case .closedGroup: case .closedGroup:
return [ return [
SectionModel( SectionModel(
model: .timerWithOff, model: .group,
elements: [ elements: [
SessionCell.Info( SessionCell.Info(
id: Item(title: "DISAPPEARING_MESSAGES_OFF".localized()), id: Item(title: "DISAPPEARING_MESSAGES_OFF".localized()),

Loading…
Cancel
Save