Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from 64characters/discarding-contact-matching…
…-index Discarding contact matching index
- Loading branch information
Showing
17 changed files
with
528 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
Telephone/ABAddressBookNotificationsToContactsChangeEventTargetAdapter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// ABAddressBookNotificationsToContactsChangeEventTargetAdapter.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
import AddressBook | ||
import Foundation | ||
import UseCases | ||
|
||
final class ABAddressBookNotificationsToContactsChangeEventTargetAdapter { | ||
private let center: NotificationCenter | ||
private let target: ContactsChangeEventTarget | ||
|
||
init(center: NotificationCenter, target: ContactsChangeEventTarget) { | ||
self.center = center | ||
self.target = target | ||
center.addObserver(self, selector: #selector(contactsDidChange), name: .abDatabaseChanged, object: nil) | ||
center.addObserver(self, selector: #selector(contactsDidChange), name: .abDatabaseChangedExternally, object: nil) | ||
} | ||
|
||
deinit { | ||
center.removeObserver(self, name: .abDatabaseChanged, object: nil) | ||
center.removeObserver(self, name: .abDatabaseChangedExternally, object: nil) | ||
} | ||
|
||
@objc private func contactsDidChange(_ notification: Notification) { | ||
target.contactsDidChange() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Telephone/CNContactStoreNotificationsToContactsChangeEventTargetAdapter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// CNContactStoreNotificationsToContactsChangeEventTargetAdapter.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
import Contacts | ||
import Foundation | ||
import UseCases | ||
|
||
@available(OSX 10.11, *) | ||
final class CNContactStoreNotificationsToContactsChangeEventTargetAdapter { | ||
private let center: NotificationCenter | ||
private let target: ContactsChangeEventTarget | ||
|
||
init(center: NotificationCenter, target: ContactsChangeEventTarget) { | ||
self.center = center | ||
self.target = target | ||
center.addObserver(self, selector: #selector(contactsDidChange), name: .CNContactStoreDidChange, object: nil) | ||
} | ||
|
||
deinit { | ||
center.removeObserver(self, name: .CNContactStoreDidChange, object: nil) | ||
} | ||
|
||
@objc private func contactsDidChange(_ notification: Notification) { | ||
target.contactsDidChange() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// ContactsChangeEventTarget.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
public protocol ContactsChangeEventTarget { | ||
func contactsDidChange() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// EnqueuingContactsChangeEventTarget.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
public final class EnqueuingContactsChangeEventTarget { | ||
fileprivate let origin: ContactsChangeEventTarget | ||
fileprivate let queue: ExecutionQueue | ||
|
||
public init(origin: ContactsChangeEventTarget, queue: ExecutionQueue) { | ||
self.origin = origin | ||
self.queue = queue | ||
} | ||
} | ||
|
||
extension EnqueuingContactsChangeEventTarget: ContactsChangeEventTarget { | ||
public func contactsDidChange() { | ||
queue.add { | ||
self.origin.contactsDidChange() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// ContactMatchingIndexFactoryStub.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
import UseCases | ||
|
||
public final class ContactMatchingIndexFactoryStub { | ||
fileprivate let indexes: [ContactMatchingIndex] | ||
fileprivate var callCount = 0 | ||
|
||
public init(indexes: [ContactMatchingIndex]) { | ||
self.indexes = indexes | ||
} | ||
} | ||
|
||
extension ContactMatchingIndexFactoryStub: ContactMatchingIndexFactory { | ||
public func make() -> ContactMatchingIndex { | ||
let result = indexes[callCount] | ||
callCount += 1 | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// ContactsChangeEventTargetSpy.swift | ||
// Telephone | ||
// | ||
// Copyright © 2008-2016 Alexey Kuznetsov | ||
// Copyright © 2016-2017 64 Characters | ||
// | ||
// Telephone is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Telephone is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
|
||
import UseCases | ||
|
||
public final class ContactsChangeEventTargetSpy { | ||
public fileprivate(set) var didCallContactsDidChange = false | ||
public init() {} | ||
} | ||
|
||
extension ContactsChangeEventTargetSpy: ContactsChangeEventTarget { | ||
public func contactsDidChange() { | ||
didCallContactsDidChange = true | ||
} | ||
} |
Oops, something went wrong.