Skip to content

Commit

Permalink
Remove duck.ai 10min timer (#3731)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1201011656765697/1208991512395317/f

**Description**:
Remove AI Chat 10min session timer
  • Loading branch information
Bunn authored Dec 17, 2024
1 parent c065764 commit 864144a
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 192 deletions.
4 changes: 0 additions & 4 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ extension Pixel {
case appDidBecomeActiveTime(time: BucketAggregation)

// MARK: AI Chat
case openAIChatBefore10min
case openAIChatAfter10min
case aiChatNoRemoteSettingsFound(settings: String)
case openAIChatFromAddressBar

Expand Down Expand Up @@ -1882,8 +1880,6 @@ extension Pixel.Event {
case .appDidBecomeActiveTime(let time): return "m_debug_app-did-become-active-time-\(time)"

// MARK: AI Chat
case .openAIChatAfter10min: return "m_aichat_open_after_10_min"
case .openAIChatBefore10min: return "m_aichat_open_before_10_min"
case .aiChatNoRemoteSettingsFound(let settings):
return "m_aichat_no_remote_settings_found-\(settings.lowercased())"
case .openAIChatFromAddressBar: return "m_aichat_addressbar_icon"
Expand Down
4 changes: 0 additions & 4 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
1EFDCBC127D2393C00916BC5 /* DownloadsDeleteHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EFDCBC027D2393C00916BC5 /* DownloadsDeleteHelper.swift */; };
22CB1ED8203DDD2C00D2C724 /* AppDeepLinksTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22CB1ED7203DDD2C00D2C724 /* AppDeepLinksTests.swift */; };
2DC3FC65C6D9DA634426672D /* AutofillNoAuthAvailableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC3FBD62FBAF21E87610FA8 /* AutofillNoAuthAvailableView.swift */; };
31043B162CFA5B8E0028A97F /* AIChatPixelHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31043B152CFA5B890028A97F /* AIChatPixelHandler.swift */; };
310742A62848CD780012660B /* BackForwardMenuHistoryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310742A52848CD780012660B /* BackForwardMenuHistoryItem.swift */; };
310742AB2848E6FD0012660B /* BackForwardMenuHistoryItemURLSanitizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310742A92848E5B70012660B /* BackForwardMenuHistoryItemURLSanitizerTests.swift */; };
310C4B45281B5A9A00BA79A9 /* AutofillLoginDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 310C4B44281B5A9A00BA79A9 /* AutofillLoginDetailsView.swift */; };
Expand Down Expand Up @@ -1503,7 +1502,6 @@
1EFDCBC027D2393C00916BC5 /* DownloadsDeleteHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadsDeleteHelper.swift; sourceTree = "<group>"; };
22CB1ED7203DDD2C00D2C724 /* AppDeepLinksTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDeepLinksTests.swift; sourceTree = "<group>"; };
2DC3FBD62FBAF21E87610FA8 /* AutofillNoAuthAvailableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutofillNoAuthAvailableView.swift; sourceTree = "<group>"; };
31043B152CFA5B890028A97F /* AIChatPixelHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AIChatPixelHandler.swift; sourceTree = "<group>"; };
310742A52848CD780012660B /* BackForwardMenuHistoryItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackForwardMenuHistoryItem.swift; sourceTree = "<group>"; };
310742A92848E5B70012660B /* BackForwardMenuHistoryItemURLSanitizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackForwardMenuHistoryItemURLSanitizerTests.swift; sourceTree = "<group>"; };
310C4B44281B5A9A00BA79A9 /* AutofillLoginDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutofillLoginDetailsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3682,7 +3680,6 @@
isa = PBXGroup;
children = (
311711902D00E53A0063AC3D /* OmnibarAccessoryHandling.swift */,
31043B152CFA5B890028A97F /* AIChatPixelHandler.swift */,
316AA4592CF8E31F00A2ED28 /* AIChatSettings.swift */,
);
path = AIChat;
Expand Down Expand Up @@ -8108,7 +8105,6 @@
9817C9C321EF594700884F65 /* AutoClear.swift in Sources */,
9FE05CEE2C36424E00D9046B /* OnboardingPixelReporter.swift in Sources */,
310C4B47281B60E300BA79A9 /* AutofillLoginDetailsViewModel.swift in Sources */,
31043B162CFA5B8E0028A97F /* AIChatPixelHandler.swift in Sources */,
85EE7F572246685B000FE757 /* WebContainerViewController.swift in Sources */,
CB48D3332B90CE9F00631D8B /* PageRefreshStore.swift in Sources */,
1EC458462948932500CB2B13 /* UIHostingControllerExtension.swift in Sources */,
Expand Down
32 changes: 0 additions & 32 deletions DuckDuckGo/AIChat/AIChatPixelHandler.swift

This file was deleted.

3 changes: 1 addition & 2 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ class MainViewController: UIViewController {
let settings = AIChatSettings(privacyConfigurationManager: ContentBlocking.shared.privacyConfigurationManager,
internalUserDecider: AppDependencyProvider.shared.internalUserDecider)
let aiChatViewController = AIChatViewController(settings: settings,
webViewConfiguration: WKWebViewConfiguration.persistent(),
pixelHandler: AIChatPixelHandler())
webViewConfiguration: WKWebViewConfiguration.persistent())
aiChatViewController.delegate = self
return aiChatViewController
}()
Expand Down
38 changes: 1 addition & 37 deletions LocalPackages/AIChat/Sources/AIChat/AIChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,17 @@ protocol AIChatViewModeling {
/// The configuration settings for the web view used in the AI Chat.
/// This configuration can include preferences such as data storage
var webViewConfiguration: WKWebViewConfiguration { get }

/// A publisher that emits a signal after a 10-minute interval.
/// This is used to notify the controller that it should perform a reload or cleanup operation,
var cleanupPublisher: PassthroughSubject<Void, Never> { get }

/// Cancels the currently active cleanup timer.
func cancelTimer()

/// Initiates the cleanup timer, which is set to trigger after a specified duration.
/// The purpose of this timer is to clear previous chat conversations
func startCleanupTimer()
}


final class AIChatViewModel: AIChatViewModeling {
private let settings: AIChatSettingsProvider
private var cleanupTimerCancellable: AnyCancellable?

let webViewConfiguration: WKWebViewConfiguration
let cleanupPublisher = PassthroughSubject<Void, Never>()

let cleanupTime: TimeInterval

init(webViewConfiguration: WKWebViewConfiguration, settings: AIChatSettingsProvider, cleanupTime: TimeInterval = 600) {
self.cleanupTime = cleanupTime
init(webViewConfiguration: WKWebViewConfiguration, settings: AIChatSettingsProvider) {
self.webViewConfiguration = webViewConfiguration
self.settings = settings
}

func cancelTimer() {
Logger.aiChat.debug("Cancelling cleanup timer")
cleanupTimerCancellable?.cancel()
}

func startCleanupTimer() {
cancelTimer()

Logger.aiChat.debug("Starting cleanup timer")

cleanupTimerCancellable = Just(())
.delay(for: .seconds(cleanupTime), scheduler: RunLoop.main)
.sink { [weak self] in
Logger.aiChat.debug("Cleanup timer done")
self?.cleanupPublisher.send()
}
}

var aiChatURL: URL {
settings.aiChatURL
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,19 @@ public final class AIChatViewController: UIViewController {
public weak var delegate: AIChatViewControllerDelegate?
private let chatModel: AIChatViewModeling
private var webViewController: AIChatWebViewController?
private var cleanupCancellable: AnyCancellable?
private var didCleanup: Bool = false
private let timerPixelHandler: TimerPixelHandler

/// Initializes a new instance of `AIChatViewController` with the specified remote settings and web view configuration.
///
/// - Parameters:
/// - remoteSettings: An object conforming to `AIChatSettingsProvider` that provides remote settings.
/// - webViewConfiguration: A `WKWebViewConfiguration` object used to configure the web view.
/// - pixelHandler: A `AIChatPixelHandling` object used to send pixel events.
public convenience init(settings: AIChatSettingsProvider, webViewConfiguration: WKWebViewConfiguration, pixelHandler: AIChatPixelHandling) {
public convenience init(settings: AIChatSettingsProvider, webViewConfiguration: WKWebViewConfiguration) {
let chatModel = AIChatViewModel(webViewConfiguration: webViewConfiguration, settings: settings)
self.init(chatModel: chatModel, pixelHandler: pixelHandler)
self.init(chatModel: chatModel)
}

internal init(chatModel: AIChatViewModeling, pixelHandler: AIChatPixelHandling) {
internal init(chatModel: AIChatViewModeling) {
self.chatModel = chatModel
self.timerPixelHandler = TimerPixelHandler(pixelHandler: pixelHandler)

super.init(nibName: nil, bundle: nil)
}
Expand All @@ -67,30 +62,23 @@ extension AIChatViewController {
public override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .black
subscribeToCleanupPublisher()
}

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
addWebViewController()
}

public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
timerPixelHandler.sendOpenPixel()
chatModel.cancelTimer()
}

public override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
chatModel.startCleanupTimer()
/// Clean up the previous conversation and prepare duck.ai for future presentation
webViewController?.reload()
}

public override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

if viewIfLoaded?.window == nil {
chatModel.cancelTimer()
removeWebViewController()
}
}
Expand Down Expand Up @@ -127,19 +115,6 @@ extension AIChatViewController {
}
}

// MARK: - Event handling
extension AIChatViewController {

private func subscribeToCleanupPublisher() {
cleanupCancellable = chatModel.cleanupPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] in
self?.webViewController?.reload()
self?.timerPixelHandler.markCleanup()
}
}
}

extension AIChatViewController: AIChatWebViewControllerDelegate {
func aiChatWebViewController(_ viewController: AIChatWebViewController, didRequestToLoad url: URL) {
delegate?.aiChatViewController(self, didRequestToLoad: url)
Expand Down
56 changes: 0 additions & 56 deletions LocalPackages/AIChat/Sources/AIChat/TimerPixelHandler.swift

This file was deleted.

0 comments on commit 864144a

Please sign in to comment.