Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Ref #3939: When deleting history, delete its Screen Time entry. #8153

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import BraveCore
import Favicon
import UIKit
import DesignSystem
import ScreenTime

class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol {

Expand Down Expand Up @@ -293,6 +294,13 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol
// Reoving a history item should remove its corresponded Recently Closed item
RecentlyClosed.remove(with: historyItem.url.absoluteString)

do {
let screenTimeHistory = try STWebHistory(bundleIdentifier: Bundle.main.bundleIdentifier!)
screenTimeHistory.deleteHistory(for: historyItem.url)
} catch {
assertionFailure("STWebHistory could not be initialized: \(error)")
}

if isHistoryBeingSearched {
reloadDataAndShowLoading(with: searchQuery)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import BraveCore
import BraveShared
import CoreData
import Shared
import ScreenTime

extension BraveHistoryAPI {

Expand Down Expand Up @@ -53,10 +54,20 @@ extension BraveHistoryAPI {
}
}

func deleteAll(completion: @escaping () -> Void) {
func deleteAll(includeScreenTimeHistory: Bool = true, completion: @escaping () -> Void) {
soner-yuksel marked this conversation as resolved.
Show resolved Hide resolved
var screenTimeHistory: STWebHistory?
if includeScreenTimeHistory {
do {
screenTimeHistory = try STWebHistory(bundleIdentifier: Bundle.main.bundleIdentifier!)
} catch {
assertionFailure("STWebHistory could not be initialized: \(error)")
}
}

DispatchQueue.main.async {
self.removeAll {
Domain.deleteNonBookmarkedAndClearSiteVisits() {
screenTimeHistory?.deleteAllHistory()
completion()
}
}
Expand Down