Merge branch 'develop' of github.com:twofas/2fas-ios into release/v5.3.5

This commit is contained in:
Zbigniew Cisiński 2024-03-14 19:11:10 +01:00
commit 34b75bf45f
3 changed files with 3 additions and 201 deletions

View File

@ -20,7 +20,7 @@ We welcome meaningful code contributions to the 2FAS for iOS project. If you are
1. Fork this repository to your own GitHub account
2. Clone the repository to your local machine
3. Copy example Keys.swift from TwoFAS/opensource folder to TwoFAS/Protection (override the encrypted file)
4. Copy IconDescriptionDatabaseImpl+Database.swift and ServiceDefinitionDatabaseImpl+Database.swift from TwoFAS/opensource to TwoFAS/Content/Sources (override files)
4. Copy IconDescriptionDatabaseImpl+Database.swift and ServiceDefinitionDatabaseImpl+Database.swift from TwoFAS/opensource to TwoFAS/Content/Sources (override files). Remove all files with "*DatabaseImpl+Database[number].swift" in it.
5. Copy Assets.car from TwoFAS/opensource to TwoFAS/Content/Assets (override the file)
6. Create a new branch for your changes (e.g. `feature/new-login-screen`)
7. Make your changes

View File

@ -20,56 +20,7 @@
import UIKit
import Common
public protocol IconDescriptionDatabase: AnyObject {
func name(for iconTypeID: IconTypeID) -> String?
func iconDescription(for iconTypeID: IconTypeID) -> IconDescription?
func listAll() -> [IconDescription]
func grouppedList() -> [IconDescriptionGroup]
}
public final class IconDescriptionDatabaseImpl {
public static var bundle: Bundle {
Bundle.module
}
private let database = IconDescriptionDatabaseGenerated()
public init() {}
}
extension IconDescriptionDatabaseImpl: IconDescriptionDatabase {
public func name(for iconTypeID: IconTypeID) -> String? {
iconDescription(for: iconTypeID)?.name
}
public func iconDescription(for iconTypeID: IconTypeID) -> IconDescription? {
database.icons.first(where: { $0.iconTypeID == iconTypeID })
}
public func listAll() -> [IconDescription] {
database.icons
}
public func grouppedList() -> [IconDescriptionGroup] {
let all = listAll()
let grouped: [IconDescriptionGroup] = Dictionary(grouping: all, by: { def -> String in
let first = def.name.first!
if first.isNumber {
return "0-9"
} else {
return String(first.uppercased())
}
})
.sorted(by: { $0.key < $1.key })
.map { key, icons in
let sortedIcons = icons.sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
return IconDescriptionGroup(title: key, icons: sortedIcons)
}
return grouped
}
}
private final class IconDescriptionDatabaseGenerated {
final class IconDescriptionDatabaseGenerated {
var icons: [IconDescription] {
[]
}

View File

@ -20,156 +20,7 @@
import UIKit
import Common
public protocol ServiceDefinitionDatabase: AnyObject {
func listAll() -> [ServiceDefinition]
func service(using serviceTypeID: ServiceTypeID) -> ServiceDefinition?
func serviceName(for serviceTypeID: ServiceTypeID?) -> String?
func findService(using issuer: String) -> ServiceDefinition?
func findServices(byTag searchText: String) -> [ServiceDefinition]
func findServicesByTagOrIssuer(
_ searchText: String,
exactMatch: Bool,
useTags: Bool
) -> [ServiceDefinition]
func findServices(domain searchText: String) -> [ServiceDefinition]
func findLegacyService(using string: String) -> ServiceTypeID?
func findLegacyIcon(using string: String) -> IconTypeID?
}
public final class ServiceDefinitionDatabaseImpl {
private let db = ServiceDefinitionDatabaseGenerated()
private let legacyExchangeDb = LegacyExchangeDatabase()
private let legacyServiceDB: LegacyServiceDatabase = LegacyServiceDatabaseImpl()
public init() {}
}
extension ServiceDefinitionDatabaseImpl: ServiceDefinitionDatabase {
public func listAll() -> [ServiceDefinition] {
db.services
}
public func service(using serviceTypeID: ServiceTypeID) -> ServiceDefinition? {
db.services.first(where: { $0.serviceTypeID == serviceTypeID })
}
public func serviceName(for serviceTypeID: ServiceTypeID?) -> String? {
guard let serviceTypeID else { return nil }
return service(using: serviceTypeID)?.name
}
public func findLegacyService(using string: String) -> ServiceTypeID? {
guard let serviceType = legacyExchangeDb.looselyCheckImportType(for: string) else { return nil }
return legacyServiceDB.serviceTypeID(for: serviceType)
}
public func findLegacyIcon(using string: String) -> IconTypeID? {
guard let serviceTypeID = findLegacyService(using: string),
let iconTypeID = service(using: serviceTypeID)?.iconTypeID
else { return nil }
return iconTypeID
}
public func findService(using issuer: String) -> ServiceDefinition? {
// TODO: Duplicated from New Code interactor - remove when migration is properly set up
let definitions = listAll()
for def in definitions {
if let issuerList = def.issuer {
for iss in issuerList {
if iss.lowercased() == issuer.lowercased() {
return def
}
}
}
if let issuerRules = def.matchingRules?.filter({ $0.field == .issuer }), !issuerRules.isEmpty {
for rule in issuerRules {
if rule.isMatching(for: issuer) {
return def
}
}
}
}
return nil
}
public func findServices(byTag searchText: String) -> [ServiceDefinition] {
let query = searchText.uppercased()
let definitions = listAll()
return definitions.filter({ service in
guard let tags = service.tags else { return false }
return tags.contains(where: { $0.contains(query) })
})
}
public func findServicesByTagOrIssuer(
_ searchText: String,
exactMatch: Bool,
useTags: Bool
) -> [ServiceDefinition] {
let query = searchText.uppercased()
let definitions = listAll()
return definitions.filter({ service in
let name = service.name.uppercased()
if exactMatch {
if name == query {
return true
}
} else {
if name.contains(query) {
return true
}
}
if let issuerList = service.issuer {
for issuer in issuerList {
if exactMatch {
if issuer.uppercased() == query {
return true
}
} else {
if issuer.uppercased().contains(query) {
return true
}
}
}
}
if let issuerRules = service.matchingRules?.filter({ $0.field == .issuer }), !issuerRules.isEmpty {
for rule in issuerRules {
if rule.isMatching(for: query) {
return true
}
}
}
if useTags {
return service.tags?.contains(where: {
if exactMatch {
return $0.uppercased() == query
} else {
return $0.uppercased().contains(query)
}
}) ?? false
}
return false
})
}
public func findServices(domain searchText: String) -> [ServiceDefinition] {
let query = searchText.uppercased()
let definitions = listAll()
return definitions.filter({ service in
query.contains(service.name.uppercased()) ||
service.issuer?.first(where: { query.contains($0.uppercased()) }) != nil
})
}
}
private final class ServiceDefinitionDatabaseGenerated {
final class ServiceDefinitionDatabaseGenerated {
var services: [ServiceDefinition] {
[]
}