wrap up the disappearing message settings screen

pull/941/head
ryanzhao 2 years ago
parent 1a98b0be62
commit 9c165000c2

@ -87,16 +87,16 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
id: .off, id: .off,
title: "DISAPPEARING_MESSAGES_OFF".localized(), title: "DISAPPEARING_MESSAGES_OFF".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { (currentSelection.isEnabled == false) } isSelected: { (self?.currentSelection.value.isEnabled == false) }
), ),
onTap: { onTap: {
// let updatedConfig: DisappearingMessagesConfiguration = currentSelection let updatedConfig: DisappearingMessagesConfiguration = currentSelection
// .with( .with(
// isEnabled: false, isEnabled: false,
// durationSeconds: 0, durationSeconds: 0,
// type: nil type: nil
// ) )
// self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
), ),
SessionCell.Info( SessionCell.Info(
@ -104,16 +104,16 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
title: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized(), title: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_TITLE".localized(),
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_DESCRIPTION".localized(), subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_READ_DESCRIPTION".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { (currentSelection.type == DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead) } isSelected: { (self?.currentSelection.value.type == .disappearAfterRead) }
), ),
onTap: { onTap: {
// let updatedConfig: DisappearingMessagesConfiguration = currentSelection let updatedConfig: DisappearingMessagesConfiguration = currentSelection
// .with( .with(
// isEnabled: true, isEnabled: true,
// durationSeconds: (24 * 60 * 60), durationSeconds: (24 * 60 * 60),
// type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterRead
// ) )
// self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
), ),
SessionCell.Info( SessionCell.Info(
@ -121,16 +121,16 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(), title: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_TITLE".localized(),
subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(), subtitle: "DISAPPERING_MESSAGES_TYPE_AFTER_SEND_DESCRIPTION".localized(),
rightAccessory: .radio( rightAccessory: .radio(
isSelected: { (currentSelection.type == DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend) } isSelected: { (self?.currentSelection.value.type == .disappearAfterSend) }
), ),
onTap: { onTap: {
// let updatedConfig: DisappearingMessagesConfiguration = currentSelection let updatedConfig: DisappearingMessagesConfiguration = currentSelection
// .with( .with(
// isEnabled: true, isEnabled: true,
// durationSeconds: (24 * 60 * 60), durationSeconds: (24 * 60 * 60),
// type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend type: DisappearingMessagesConfiguration.DisappearingMessageType.disappearAfterSend
// ) )
// self?.currentSelection.send(updatedConfig) self?.currentSelection.send(updatedConfig)
} }
) )
] ]
@ -165,41 +165,41 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel<ThreadDisappear
private func saveChanges() { private func saveChanges() {
let threadId: String = self.threadId let threadId: String = self.threadId
let updatedConfig: DisappearingMessagesConfiguration = self.currentSelection.value let updatedConfig: DisappearingMessagesConfiguration = self.currentSelection.value
guard self.config != updatedConfig else { return } guard self.config != updatedConfig else { return }
dependencies.storage.writeAsync { db in // dependencies.storage.writeAsync { db in
guard let thread: SessionThread = try SessionThread.fetchOne(db, id: threadId) else { // guard let thread: SessionThread = try SessionThread.fetchOne(db, id: threadId) else {
return // return
} // }
//
let config: DisappearingMessagesConfiguration = try DisappearingMessagesConfiguration // let config: DisappearingMessagesConfiguration = try DisappearingMessagesConfiguration
.fetchOne(db, id: threadId) // .fetchOne(db, id: threadId)
.defaulting(to: DisappearingMessagesConfiguration.defaultWith(threadId)) // .defaulting(to: DisappearingMessagesConfiguration.defaultWith(threadId))
.with( // .with(
isEnabled: (currentSelection != 0), // isEnabled: (currentSelection != 0),
durationSeconds: currentSelection // durationSeconds: currentSelection
) // )
.saved(db) // .saved(db)
//
let interaction: Interaction = try Interaction( // let interaction: Interaction = try Interaction(
threadId: threadId, // threadId: threadId,
authorId: getUserHexEncodedPublicKey(db), // authorId: getUserHexEncodedPublicKey(db),
variant: .infoDisappearingMessagesUpdate, // variant: .infoDisappearingMessagesUpdate,
body: config.messageInfoString(with: nil), // body: config.messageInfoString(with: nil),
timestampMs: Int64(floor(Date().timeIntervalSince1970 * 1000)) // timestampMs: Int64(floor(Date().timeIntervalSince1970 * 1000))
) // )
.inserted(db) // .inserted(db)
//
try MessageSender.send( // try MessageSender.send(
db, // db,
message: ExpirationTimerUpdate( // message: ExpirationTimerUpdate(
syncTarget: nil, // syncTarget: nil,
duration: UInt32(floor(updatedConfig.isEnabled ? updatedConfig.durationSeconds : 0)) // duration: UInt32(floor(updatedConfig.isEnabled ? updatedConfig.durationSeconds : 0))
), // ),
interactionId: interaction.id, // interactionId: interaction.id,
in: thread // in: thread
) // )
} // }
} }
} }

Loading…
Cancel
Save