diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 7cd7e8b75..60a4bc81a 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -25,29 +25,13 @@ extension ConversationVC: // Don't take the user to settings for unapproved threads guard viewModel.threadData.threadRequiresApproval == false else { return } - openSettings() + openSettingsFromTitleView() } - - @objc func openSettings() { + + @objc func openSettingsFromTitleView() { switch self.titleView.currentLabelType { case.empty, .notificationSettings, .userCount: - let viewController = SessionTableViewController(viewModel: ThreadSettingsViewModel( - threadId: self.viewModel.threadData.threadId, - threadVariant: self.viewModel.threadData.threadVariant, - didTriggerSearch: { [weak self] in - DispatchQueue.main.async { - self?.showSearchUI() - self?.popAllConversationSettingsViews { - // Note: Without this delay the search bar doesn't show - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - self?.searchController.uiSearchController.searchBar.becomeFirstResponder() - } - } - } - } - ) - ) - navigationController?.pushViewController(viewController, animated: true) + openSettings() break case .disappearingMessageSetting: let viewController = SessionTableViewController(viewModel: ThreadDisappearingMessagesViewModel( @@ -61,6 +45,26 @@ extension ConversationVC: break } } + + @objc func openSettings() { + let viewController = SessionTableViewController(viewModel: ThreadSettingsViewModel( + threadId: self.viewModel.threadData.threadId, + threadVariant: self.viewModel.threadData.threadVariant, + didTriggerSearch: { [weak self] in + DispatchQueue.main.async { + self?.showSearchUI() + self?.popAllConversationSettingsViews { + // Note: Without this delay the search bar doesn't show + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + self?.searchController.uiSearchController.searchBar.becomeFirstResponder() + } + } + } + } + ) + ) + navigationController?.pushViewController(viewController, animated: true) + } // MARK: - ScrollToBottomButtonDelegate @@ -452,13 +456,6 @@ extension ConversationVC: body: text, timestampMs: sentTimestampMs, hasMention: Interaction.isUserMentioned(db, threadId: threadId, body: text), - // No matter the disappearing message type is D.A.R or D.A.S, it is the same on the sender's side - expiresInSeconds: try? DisappearingMessagesConfiguration - .select(.durationSeconds) - .filter(id: threadId) - .filter(DisappearingMessagesConfiguration.Columns.isEnabled == true) - .asRequest(of: TimeInterval.self) - .fetchOne(db), linkPreviewUrl: linkPreviewDraft?.urlString ).inserted(db) @@ -575,13 +572,7 @@ extension ConversationVC: variant: .standardOutgoing, body: text, timestampMs: sentTimestampMs, - hasMention: Interaction.isUserMentioned(db, threadId: threadId, body: text), - expiresInSeconds: try? DisappearingMessagesConfiguration - .select(.durationSeconds) - .filter(id: threadId) - .filter(DisappearingMessagesConfiguration.Columns.isEnabled == true) - .asRequest(of: TimeInterval.self) - .fetchOne(db) + hasMention: Interaction.isUserMentioned(db, threadId: threadId, body: text) ).inserted(db) try MessageSender.send( diff --git a/Session/Conversations/Settings/ThreadDisappearingMessagesViewModel.swift b/Session/Conversations/Settings/ThreadDisappearingMessagesViewModel.swift index 8a7ae9d93..657129aef 100644 --- a/Session/Conversations/Settings/ThreadDisappearingMessagesViewModel.swift +++ b/Session/Conversations/Settings/ThreadDisappearingMessagesViewModel.swift @@ -239,7 +239,7 @@ class ThreadDisappearingMessagesViewModel: SessionTableViewModel InsertionSuccess) throws { diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift index 4cda81fd5..5d2eef893 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift @@ -91,14 +91,6 @@ extension MessageReceiver { if let interactionId: Int64 = try handleEmojiReactIfNeeded(db, message: message, associatedWithProto: proto, sender: sender, messageSentTimestamp: messageSentTimestamp, openGroupId: openGroupId, thread: thread) { return interactionId } - - // Retrieve the disappearing messages config to set the 'expiresInSeconds' value - // accoring to the config - let disappearingMessagesConfiguration: DisappearingMessagesConfiguration = (try? thread.disappearingMessagesConfiguration.fetchOne(db)) - .defaulting(to: DisappearingMessagesConfiguration.defaultWith(thread.id)) - - let expiresStartedAtMs: Double? = (disappearingMessagesConfiguration.isEnabled && disappearingMessagesConfiguration.type == .disappearAfterSend) ? Double(message.sentTimestamp ?? 0) : nil - // Try to insert the interaction // // Note: There are now a number of unique constraints on the database which @@ -121,12 +113,6 @@ extension MessageReceiver { body: message.text, quoteAuthorId: dataMessage.quote?.author ), - // Note: Ensure we don't ever expire open group messages - expiresInSeconds: (disappearingMessagesConfiguration.isEnabled && message.openGroupServerMessageId == nil ? - disappearingMessagesConfiguration.durationSeconds : - nil - ), - expiresStartedAtMs: expiresStartedAtMs, // OpenGroupInvitations are stored as LinkPreview's in the database linkPreviewUrl: (message.linkPreview?.url ?? message.openGroupInvitation?.url), // Keep track of the open group server message ID ↔ message ID relationship diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index 1e6f6f773..51ca714c2 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -356,6 +356,9 @@ public enum MessageReceiver { lastChangeTimestampMs: protoLastChangeTimestampMs ) + let expireInSeconds: TimeInterval? = (remoteConfig.isEnabled && message.openGroupServerMessageId == nil) ? remoteConfig.durationSeconds : nil + let expiresStartedAtMs: Double? = (remoteConfig.isEnabled && remoteConfig.type == .disappearAfterSend) ? Double(message.sentTimestamp ?? 0) : nil + _ = try Interaction( serverHash: nil, // Intentionally null so sync messages are seen as duplicates threadId: threadId, @@ -368,7 +371,9 @@ public enum MessageReceiver { ), isPreviousOff: !localConfig.isEnabled ), - timestampMs: protoLastChangeTimestampMs + timestampMs: protoLastChangeTimestampMs, + expiresInSeconds: expireInSeconds, + expiresStartedAtMs: expiresStartedAtMs ).inserted(db) try remoteConfig.save(db) diff --git a/SessionShareExtension/ThreadPickerVC.swift b/SessionShareExtension/ThreadPickerVC.swift index 7db42407d..b3c4bf796 100644 --- a/SessionShareExtension/ThreadPickerVC.swift +++ b/SessionShareExtension/ThreadPickerVC.swift @@ -198,12 +198,6 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView body: body, timestampMs: Int64(floor(Date().timeIntervalSince1970 * 1000)), hasMention: Interaction.isUserMentioned(db, threadId: threadId, body: body), - expiresInSeconds: try? DisappearingMessagesConfiguration - .select(.durationSeconds) - .filter(id: threadId) - .filter(DisappearingMessagesConfiguration.Columns.isEnabled == true) - .asRequest(of: TimeInterval.self) - .fetchOne(db), linkPreviewUrl: (isSharingUrl ? attachments.first?.linkPreviewDraft?.urlString : nil) ).inserted(db)