Skip to content

Commit

Permalink
reload table after breaches are loaded to update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vphong committed Jul 10, 2020
1 parent f06d187 commit 88b49e7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
6 changes: 2 additions & 4 deletions Client/Frontend/Login Management/BreachAlertsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final public class BreachAlertsManager {
/// - Parameters:
/// - logins: a list of logins to compare breaches to
/// - Returns:
/// - an array of IndexPaths of breaches in the original list.
/// - an array of LoginRecords of breaches in the original list.
func findUserBreaches(_ logins: [LoginRecord]) -> Maybe<[LoginRecord]> {
var result: [LoginRecord] = []

Expand All @@ -71,9 +71,7 @@ final public class BreachAlertsManager {
for breach in self.breaches {
if let potentialBreaches = loginsDictionary[breach.domain] {
for item in potentialBreaches {
// date check
let pwLastChanged = TimeInterval(item.timePasswordChanged*1000)

let pwLastChanged = TimeInterval(item.timePasswordChanged/1000)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
if let breachDate = dateFormatter.date(from: breach.breachDate)?.timeIntervalSince1970, pwLastChanged < breachDate {
Expand Down
7 changes: 4 additions & 3 deletions Client/Frontend/Login Management/LoginDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class LoginDataSource: NSObject, UITableViewDataSource {
@objc func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = ThemedTableViewCell(style: .subtitle, reuseIdentifier: CellReuseIdentifier)

// Need to override the default background multi-select color to support theming
cell.multipleSelectionBackgroundView = UIView()
cell.applyTheme()

if indexPath.section == LoginsSettingsSection {
let hideSettings = viewModel.searchController?.isActive ?? false || tableView.isEditing
let setting = indexPath.row == 0 ? boolSettings.0 : boolSettings.1
Expand Down Expand Up @@ -72,9 +76,6 @@ class LoginDataSource: NSObject, UITableViewDataSource {
}
}
}
// Need to override the default background multi-select color to support theming
cell.multipleSelectionBackgroundView = UIView()
cell.applyTheme()
return cell
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ private extension LoginListViewController {

func loadLogins(_ query: String? = nil) {
loadingView.isHidden = false
viewModel.loadLogins(query, loginDataSource: self.loginDataSource)
viewModel.loadLogins(query, loginDataSource: self.loginDataSource)?.upon { _ in
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}

@objc func beginEditing() {
Expand Down
3 changes: 2 additions & 1 deletion Client/Frontend/Login Management/LoginListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class LoginListViewModel {
self.searchController = searchController
}

func loadLogins(_ query: String? = nil, loginDataSource: LoginDataSource) {
func loadLogins(_ query: String? = nil, loginDataSource: LoginDataSource) -> Deferred<Maybe<[LoginRecord]>>? {
// Fill in an in-flight query and re-query
activeLoginQuery?.fillIfUnfilled(Maybe(success: []))
activeLoginQuery = queryLogins(query ?? "")
Expand All @@ -44,6 +44,7 @@ final class LoginListViewModel {
self.userBreaches = self.breachAlertsManager.findUserBreaches(logins).successValue
}
activeLoginQuery! >>== self.setLogins
return activeLoginQuery
}

/// Searches SQLite database for logins that match query.
Expand Down
4 changes: 2 additions & 2 deletions ClientTests/BreachAlertsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class MockBreachAlertsClient: BreachAlertsClientProtocol {
class BreachAlertsTests: XCTestCase {
var breachAlertsManager: BreachAlertsManager!
let unbreachedLogin = [
LoginRecord(fromJSONDict: ["hostname" : "http://unbreached.com", "timePasswordChanged": 1590784648189])
LoginRecord(fromJSONDict: ["hostname" : "http://unbreached.com", "timePasswordChanged": 1594411049000])
]
let breachedLogin = [
LoginRecord(fromJSONDict: ["hostname" : "http://breached.com", "timePasswordChanged": 1])
LoginRecord(fromJSONDict: ["hostname" : "http://breached.com", "timePasswordChanged": 46800000])
]
override func setUp() {
self.breachAlertsManager = BreachAlertsManager(MockBreachAlertsClient())
Expand Down

0 comments on commit 88b49e7

Please sign in to comment.