Skip to content

Commit

Permalink
issue #714 rename RecipientWithPubKeys to RecipientWithSortedPubKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
sosnovsky committed Oct 25, 2021
1 parent 118df91 commit 8776b63
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 82 deletions.
49 changes: 4 additions & 45 deletions FlowCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
9F0C3C1A231819C500299985 /* MessageKindProviderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F0C3C19231819C500299985 /* MessageKindProviderType.swift */; };
9F0C3C2623194E0A00299985 /* FolderViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F0C3C2523194E0A00299985 /* FolderViewModel.swift */; };
9F17976D2368EEBD002BF770 /* SetupViewDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F17976C2368EEBD002BF770 /* SetupViewDecorator.swift */; };
9F228BAA23C67729005D2CB6 /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCAEFF16F5D91A35791730 /* DataExtensions.swift */; };
9F23EA50237217140017DFED /* ComposeViewDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F23EA4F237217140017DFED /* ComposeViewDecorator.swift */; };
9F268891237DC55600428A94 /* SetupManuallyImportKeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F268890237DC55600428A94 /* SetupManuallyImportKeyViewController.swift */; };
9F2AC5B1267BDED100F6149B /* GmailSearchExpressionGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F2AC5B0267BDED100F6149B /* GmailSearchExpressionGenerator.swift */; };
Expand Down Expand Up @@ -205,7 +204,6 @@
9FD364862381EFCB00657302 /* SetupManuallyEnterPassPhraseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD364852381EFCB00657302 /* SetupManuallyEnterPassPhraseViewController.swift */; };
9FDF3654235A218E00614596 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDF3653235A218E00614596 /* main.swift */; };
9FDF3656235A22DA00614596 /* AppReset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDF3655235A22DA00614596 /* AppReset.swift */; };
9FDF3658235A233400614596 /* AppReset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDF3655235A22DA00614596 /* AppReset.swift */; };
9FE1B3802563F85400D6D086 /* MessagesListProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B37F2563F85400D6D086 /* MessagesListProvider.swift */; };
9FE1B3942563F98600D6D086 /* Imap+MessagesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B3932563F98600D6D086 /* Imap+MessagesList.swift */; };
9FE1B3A02565B0CE00D6D086 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B39F2565B0CD00D6D086 /* Message.swift */; };
Expand Down Expand Up @@ -283,7 +281,7 @@
D274724424FD1932006BA6EF /* FolderObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274724324FD1932006BA6EF /* FolderObject.swift */; };
D27B911924EFE79F002DF0A1 /* LocalContactsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911824EFE79F002DF0A1 /* LocalContactsProvider.swift */; };
D27B911D24EFE806002DF0A1 /* RecipientObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911C24EFE806002DF0A1 /* RecipientObject.swift */; };
D27B911F24EFE828002DF0A1 /* RecipientWithPubKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911E24EFE828002DF0A1 /* RecipientWithPubKeys.swift */; };
D27B911F24EFE828002DF0A1 /* RecipientWithSortedPubKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911E24EFE828002DF0A1 /* RecipientWithSortedPubKeys.swift */; };
D28325DD24895F5700D311BD /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 949ED9412303E3B400530579 /* Colors.xcassets */; };
D28655912423B4580066F52E /* HeaderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDF3639235A0B3B00614596 /* HeaderNode.swift */; };
D28655932423B4EE0066F52E /* MyMenuViewDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28655922423B4EE0066F52E /* MyMenuViewDecorator.swift */; };
Expand Down Expand Up @@ -354,13 +352,6 @@
remoteGlobalIDString = C132B9AF1EC2DBD800763715;
remoteInfo = FlowCrypt;
};
9FDF3646235A1B0100614596 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C132B9A81EC2DBD800763715 /* Project object */;
proxyType = 1;
remoteGlobalIDString = C132B9AF1EC2DBD800763715;
remoteInfo = FlowCrypt;
};
D2CDC3DB24052D0F002B045F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C132B9A81EC2DBD800763715 /* Project object */;
Expand Down Expand Up @@ -696,7 +687,7 @@
D274724324FD1932006BA6EF /* FolderObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderObject.swift; sourceTree = "<group>"; };
D27B911824EFE79F002DF0A1 /* LocalContactsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalContactsProvider.swift; sourceTree = "<group>"; };
D27B911C24EFE806002DF0A1 /* RecipientObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientObject.swift; sourceTree = "<group>"; };
D27B911E24EFE828002DF0A1 /* RecipientWithPubKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientWithPubKeys.swift; sourceTree = "<group>"; };
D27B911E24EFE828002DF0A1 /* RecipientWithSortedPubKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipientWithSortedPubKeys.swift; sourceTree = "<group>"; };
D28655922423B4EE0066F52E /* MyMenuViewDecorator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyMenuViewDecorator.swift; sourceTree = "<group>"; };
D28655942423BFF60066F52E /* SideMenuOptionalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuOptionalView.swift; sourceTree = "<group>"; };
D2891AC124C59EFA008918E3 /* KeyService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -748,13 +739,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
9FDF363E235A1B0100614596 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C132B9AD1EC2DBD800763715 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1786,7 +1770,7 @@
D27B912024EFE842002DF0A1 /* Models */ = {
isa = PBXGroup;
children = (
D27B911E24EFE828002DF0A1 /* RecipientWithPubKeys.swift */,
D27B911E24EFE828002DF0A1 /* RecipientWithSortedPubKeys.swift */,
51B4AE5227144E590001F33B /* PubKey.swift */,
51DA5BD52721AB07001C4359 /* PubKeyState.swift */,
);
Expand Down Expand Up @@ -2133,10 +2117,6 @@
CreatedOnToolsVersion = 12.4;
TestTargetID = C132B9AF1EC2DBD800763715;
};
9FDF3640235A1B0100614596 = {
CreatedOnToolsVersion = 11.0;
TestTargetID = C132B9AF1EC2DBD800763715;
};
C132B9AF1EC2DBD800763715 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 1020;
Expand Down Expand Up @@ -2201,13 +2181,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
9FDF363F235A1B0100614596 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C132B9AE1EC2DBD800763715 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -2435,15 +2408,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
9FDF363D235A1B0100614596 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9FDF3658235A233400614596 /* AppReset.swift in Sources */,
9F228BAA23C67729005D2CB6 /* DataExtensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
C132B9AC1EC2DBD800763715 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -2541,7 +2505,7 @@
9F3EF33123B1785600FA0CEF /* MsgListViewConroller.swift in Sources */,
9F31ABA0232C071700CF87EA /* GlobalRouter.swift in Sources */,
9F5C2A92257E94DF00DE9B4B /* Imap+MessageOperations.swift in Sources */,
D27B911F24EFE828002DF0A1 /* RecipientWithPubKeys.swift in Sources */,
D27B911F24EFE828002DF0A1 /* RecipientWithSortedPubKeys.swift in Sources */,
32DCA1414EEA727B86C337D5 /* Core.swift in Sources */,
9FB22CF725715DC50026EE64 /* KeyServiceErrorHandler.swift in Sources */,
9F0C3C1A231819C500299985 /* MessageKindProviderType.swift in Sources */,
Expand Down Expand Up @@ -2737,11 +2701,6 @@
target = C132B9AF1EC2DBD800763715 /* FlowCrypt */;
targetProxy = 9F2AC5CB267BE99E00F6149B /* PBXContainerItemProxy */;
};
9FDF3647235A1B0100614596 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C132B9AF1EC2DBD800763715 /* FlowCrypt */;
targetProxy = 9FDF3646235A1B0100614596 /* PBXContainerItemProxy */;
};
D2CDC3DC24052D0F002B045F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = D2531F2A23FEEF52007E5198 /* FlowCryptCommon */;
Expand Down
4 changes: 2 additions & 2 deletions FlowCrypt/Controllers/Compose/ComposeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ extension ComposeViewController {
}
}

private func getRecipientState(from recipient: RecipientWithPubKeys) -> RecipientState {
private func getRecipientState(from recipient: RecipientWithSortedPubKeys) -> RecipientState {
switch recipient.keyState {
case .active:
return decorator.recipientKeyFoundState
Expand Down Expand Up @@ -921,7 +921,7 @@ private actor ServiceActor {
return try await cloudContactProvider.searchContacts(query: query)
}

func searchContact(with email: String) async throws -> RecipientWithPubKeys {
func searchContact(with email: String) async throws -> RecipientWithSortedPubKeys {
return try await contactsService.searchContact(with: email)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import Foundation

protocol ContactDetailDecoratorType {
var title: String { get }
func userNodeInput(with contact: RecipientWithPubKeys) -> ContactUserCellNode.Input
func userNodeInput(with contact: RecipientWithSortedPubKeys) -> ContactUserCellNode.Input
func keyNodeInput(with key: PubKey) -> ContactKeyCellNode.Input
}

struct ContactDetailDecorator: ContactDetailDecoratorType {
let title = "contact_detail_screen_title".localized

func userNodeInput(with contact: RecipientWithPubKeys) -> ContactUserCellNode.Input {
func userNodeInput(with contact: RecipientWithSortedPubKeys) -> ContactUserCellNode.Input {
ContactUserCellNode.Input(
user: (contact.name ?? contact.email).attributed(.regular(16))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ContactDetailViewController: TableNodeViewController {
typealias ContactDetailAction = (Action) -> Void

enum Action {
case delete(_ recipient: RecipientWithPubKeys)
case delete(_ recipient: RecipientWithSortedPubKeys)
}

private enum Section: Int, CaseIterable {
Expand All @@ -27,13 +27,13 @@ final class ContactDetailViewController: TableNodeViewController {

private let decorator: ContactDetailDecoratorType
private let contactsProvider: LocalContactsProviderType
private var recipient: RecipientWithPubKeys
private var recipient: RecipientWithSortedPubKeys
private let action: ContactDetailAction?

init(
decorator: ContactDetailDecoratorType = ContactDetailDecorator(),
contactsProvider: LocalContactsProviderType = LocalContactsProvider(),
recipient: RecipientWithPubKeys,
recipient: RecipientWithSortedPubKeys,
action: ContactDetailAction?
) {
self.decorator = decorator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import UIKit

protocol ContactsListDecoratorType {
var title: String { get }
func contactNodeInput(with recipient: RecipientWithPubKeys) -> ContactCellNode.Input
func contactNodeInput(with recipient: RecipientWithSortedPubKeys) -> ContactCellNode.Input
}

struct ContactsListDecorator: ContactsListDecoratorType {
let title = "contacts_screen_title".localized

func contactNodeInput(with recipient: RecipientWithPubKeys) -> ContactCellNode.Input {
func contactNodeInput(with recipient: RecipientWithSortedPubKeys) -> ContactCellNode.Input {
let name: String

if let recipientName = recipient.name, recipientName.isNotEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FlowCryptUI
final class ContactsListViewController: TableNodeViewController {
private let decorator: ContactsListDecoratorType
private let contactsProvider: LocalContactsProviderType
private var recipients: [RecipientWithPubKeys] = []
private var recipients: [RecipientWithSortedPubKeys] = []
private var selectedIndexPath: IndexPath?

init(
Expand Down Expand Up @@ -109,8 +109,8 @@ extension ContactsListViewController {
navigationController?.pushViewController(contactDetailViewController, animated: true)
}

private func delete(with context: Either<RecipientWithPubKeys, IndexPath>) {
let recipientToRemove: RecipientWithPubKeys
private func delete(with context: Either<RecipientWithSortedPubKeys, IndexPath>) {
let recipientToRemove: RecipientWithSortedPubKeys
let indexPathToRemove: IndexPath
switch context {
case .left(let recipient):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protocol ContactsServiceType: PublicKeyProvider, ContactsProviderType {
}

protocol ContactsProviderType {
func searchContact(with email: String) async throws -> RecipientWithPubKeys
func searchContact(with email: String) async throws -> RecipientWithSortedPubKeys
func searchContacts(query: String) -> [String]
}

Expand All @@ -43,7 +43,7 @@ struct ContactsService: ContactsServiceType {
}

extension ContactsService: ContactsProviderType {
func searchContact(with email: String) async throws -> RecipientWithPubKeys {
func searchContact(with email: String) async throws -> RecipientWithSortedPubKeys {
guard let contact = localContactsProvider.searchRecipient(with: email) else {
let recipient = try await pubLookup.lookup(with: email)
localContactsProvider.save(recipient: recipient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import RealmSwift

protocol LocalContactsProviderType: PublicKeyProvider {
func updateLastUsedDate(for email: String)
func searchRecipient(with email: String) -> RecipientWithPubKeys?
func searchRecipient(with email: String) -> RecipientWithSortedPubKeys?
func searchEmails(query: String) -> [String]
func save(recipient: RecipientWithPubKeys)
func remove(recipient: RecipientWithPubKeys)
func updateKeys(for recipient: RecipientWithPubKeys)
func getAllRecipients() -> [RecipientWithPubKeys]
func save(recipient: RecipientWithSortedPubKeys)
func remove(recipient: RecipientWithSortedPubKeys)
func updateKeys(for recipient: RecipientWithSortedPubKeys)
func getAllRecipients() -> [RecipientWithSortedPubKeys]
}

struct LocalContactsProvider {
Expand Down Expand Up @@ -47,18 +47,18 @@ extension LocalContactsProvider: LocalContactsProviderType {
.map { $0.armored } ?? []
}

func save(recipient: RecipientWithPubKeys) {
func save(recipient: RecipientWithSortedPubKeys) {
localContactsCache.save(RecipientObject(recipient))
}

func remove(recipient: RecipientWithPubKeys) {
func remove(recipient: RecipientWithSortedPubKeys) {
localContactsCache.remove(
object: RecipientObject(recipient),
with: recipient.email
)
}

func updateKeys(for recipient: RecipientWithPubKeys) {
func updateKeys(for recipient: RecipientWithSortedPubKeys) {
guard let recipientObject = find(with: recipient.email) else {
localContactsCache.save(RecipientObject(recipient))
return
Expand All @@ -74,7 +74,7 @@ extension LocalContactsProvider: LocalContactsProviderType {
}
}

func searchRecipient(with email: String) -> RecipientWithPubKeys? {
func searchRecipient(with email: String) -> RecipientWithSortedPubKeys? {
guard let recipientObject = find(with: email) else { return nil }
return parseRecipient(from: recipientObject)
}
Expand All @@ -86,7 +86,7 @@ extension LocalContactsProvider: LocalContactsProviderType {
.map(\.email)
}

func getAllRecipients() -> [RecipientWithPubKeys] {
func getAllRecipients() -> [RecipientWithSortedPubKeys] {
localContactsCache.realm
.objects(RecipientObject.self)
.map(parseRecipient)
Expand All @@ -111,11 +111,11 @@ extension LocalContactsProvider {
forPrimaryKey: email)
}

private func parseRecipient(from object: RecipientObject) -> RecipientWithPubKeys {
private func parseRecipient(from object: RecipientObject) -> RecipientWithSortedPubKeys {
let keyDetails = object.pubKeys
.compactMap { try? core.parseKeys(armoredOrBinary: $0.armored.data()).keyDetails }
.flatMap { $0 }
return RecipientWithPubKeys(object, keyDetails: Array(keyDetails))
return RecipientWithSortedPubKeys(object, keyDetails: Array(keyDetails))
}

private func add(pubKey: PubKey, to recipient: RecipientObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

struct RecipientWithPubKeys {
struct RecipientWithSortedPubKeys {
let email: String
/// name if known
let name: String?
Expand All @@ -18,7 +18,7 @@ struct RecipientWithPubKeys {
var pubKeys: [PubKey]
}

extension RecipientWithPubKeys {
extension RecipientWithSortedPubKeys {
init(_ recipientObject: RecipientObject, keyDetails: [KeyDetails] = []) {
self.email = recipientObject.email
self.name = recipientObject.name.nilIfEmpty
Expand All @@ -27,7 +27,7 @@ extension RecipientWithPubKeys {
}
}

extension RecipientWithPubKeys {
extension RecipientWithSortedPubKeys {
init(email: String, keyDetails: [KeyDetails]) {
self.email = email
self.name = keyDetails.first?.users.first ?? email
Expand All @@ -36,16 +36,16 @@ extension RecipientWithPubKeys {
}
}

extension RecipientWithPubKeys {
extension RecipientWithSortedPubKeys {
mutating func remove(pubKey: PubKey) {
pubKeys.removeAll(where: { $0 == pubKey })
}

var keyState: PubKeyState { pubKeys.first?.keyState ?? .empty }
}

extension RecipientWithPubKeys: Equatable {
static func == (lhs: RecipientWithPubKeys, rhs: RecipientWithPubKeys) -> Bool {
extension RecipientWithSortedPubKeys: Equatable {
static func == (lhs: RecipientWithSortedPubKeys, rhs: RecipientWithSortedPubKeys) -> Bool {
lhs.email == rhs.email
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

protocol PubLookupType {
func lookup(with email: String) async throws -> RecipientWithPubKeys
func lookup(with email: String) async throws -> RecipientWithSortedPubKeys
}

class PubLookup: PubLookupType {
Expand All @@ -22,13 +22,13 @@ class PubLookup: PubLookupType {
self.attesterApi = attesterApi
}

func lookup(with email: String) async throws -> RecipientWithPubKeys {
func lookup(with email: String) async throws -> RecipientWithSortedPubKeys {
let wkdResult = try await wkd.lookupEmail(email)
if !wkdResult.isEmpty {
return RecipientWithPubKeys(email: email, keyDetails: wkdResult)
return RecipientWithSortedPubKeys(email: email, keyDetails: wkdResult)
}

let attesterResult = try await attesterApi.lookupEmail(email: email)
return RecipientWithPubKeys(email: email, keyDetails: attesterResult)
return RecipientWithSortedPubKeys(email: email, keyDetails: attesterResult)
}
}
Loading

0 comments on commit 8776b63

Please sign in to comment.