re-enable the handling for expiration timer update messages until the new design is enabled

pull/941/head
Ryan Zhao 3 years ago
parent f4a2d41d34
commit 8e64cda138

@ -7,47 +7,62 @@ import SessionUtilitiesKit
extension MessageReceiver { extension MessageReceiver {
internal static func handleExpirationTimerUpdate(_ db: Database, message: ExpirationTimerUpdate) throws { internal static func handleExpirationTimerUpdate(_ db: Database, message: ExpirationTimerUpdate) throws {
// Get the target thread // Get the target thread
// guard guard
// let targetId: String = MessageReceiver.threadInfo(db, message: message, openGroupId: nil)?.id, !DisappearingMessagesConfiguration.isNewConfigurationEnabled,
// let sender: String = message.sender, let targetId: String = MessageReceiver.threadInfo(db, message: message, openGroupId: nil)?.id,
// let thread: SessionThread = try? SessionThread.fetchOne(db, id: targetId) let sender: String = message.sender,
// else { return } let thread: SessionThread = try? SessionThread.fetchOne(db, id: targetId)
// else { return }
// // Update the configuration
// // // Update the configuration
// // Note: Messages which had been sent during the previous configuration will still //
// // use it's settings (so if you enable, send a message and then disable disappearing // Note: Messages which had been sent during the previous configuration will still
// // message then the message you had sent will still disappear) // use it's settings (so if you enable, send a message and then disable disappearing
// let config: DisappearingMessagesConfiguration = try thread.disappearingMessagesConfiguration // message then the message you had sent will still disappear)
// .fetchOne(db)
// .defaulting(to: DisappearingMessagesConfiguration.defaultWith(thread.id)) let defaultType: DisappearingMessagesConfiguration.DisappearingMessageType? = {
// .with( switch thread.variant {
// // If there is no duration then we should disable the expiration timer case .contact:
// isEnabled: ((message.duration ?? 0) > 0), if thread.id == getUserHexEncodedPublicKey() { fallthrough }
// durationSeconds: ( return .disappearAfterRead
// message.duration.map { TimeInterval($0) } ?? case .closedGroup:
// DisappearingMessagesConfiguration.defaultDuration return .disappearAfterSend
// ) case .openGroup:
// ) return nil // Shouldn't happen
// }
// // Add an info message for the user }()
// _ = try Interaction(
// serverHash: nil, // Intentionally null so sync messages are seen as duplicates let config: DisappearingMessagesConfiguration = try thread.disappearingMessagesConfiguration
// threadId: thread.id, .fetchOne(db)
// authorId: sender, .defaulting(to: DisappearingMessagesConfiguration.defaultWith(thread.id))
// variant: .infoDisappearingMessagesUpdate, .with(
// body: config.messageInfoString( // If there is no duration then we should disable the expiration timer
// with: (sender != getUserHexEncodedPublicKey(db) ? isEnabled: ((message.duration ?? 0) > 0),
// Profile.displayName(db, id: sender) : durationSeconds: (
// nil message.duration.map { TimeInterval($0) } ??
// ), DisappearingMessagesConfiguration.defaultDuration
// isPreviousOff: false ),
// ), type: defaultType
// timestampMs: Int64(message.sentTimestamp ?? 0) // Default to `0` if not set )
// ).inserted(db)
// // Add an info message for the user
// // Finally save the changes to the DisappearingMessagesConfiguration (If it's a duplicate _ = try Interaction(
// // then the interaction unique constraint will prevent the code from getting here) serverHash: nil, // Intentionally null so sync messages are seen as duplicates
// try config.save(db) threadId: thread.id,
authorId: sender,
variant: .infoDisappearingMessagesUpdate,
body: config.messageInfoString(
with: (sender != getUserHexEncodedPublicKey(db) ?
Profile.displayName(db, id: sender) :
nil
),
isPreviousOff: false
),
timestampMs: Int64(message.sentTimestamp ?? 0) // Default to `0` if not set
).inserted(db)
// Finally save the changes to the DisappearingMessagesConfiguration (If it's a duplicate
// then the interaction unique constraint will prevent the code from getting here)
try config.save(db)
} }
} }

Loading…
Cancel
Save