@@ -6,44 +6,55 @@ import BitwardenSdk
66/// This decrypts and process data iteratively in batches to improve time and memory on the overall
77/// grouping/filtering/preparation.
88protocol VaultListDataPreparator { // sourcery: AutoMockable
9- /// Prepares data for the vault list builder.
9+ /// Prepares autofill's passwords data for the vault list builder.
1010 /// - Parameters:
1111 /// - ciphers: An array of `Cipher` objects to be processed.
12- /// - collections: An array of `Collection` objects to be processed.
13- /// - folders: An array of `Folder` objects to be processed.
1412 /// - filter: A `VaultListFilter` object that defines the filtering criteria for the vault list.
1513 /// - Returns: An optional `VaultListPreparedData` object containing the prepared data for the vault list.
1614 /// Returns `nil` if the vault is empty.
17- func prepareData (
15+ func prepareAutofillPasswordsData (
1816 from ciphers: [ Cipher ] ,
19- collections: [ Collection ] ,
20- folders: [ Folder ] ,
2117 filter: VaultListFilter
2218 ) async throws -> VaultListPreparedData ?
2319
24- /// Prepares group data for the vault list builder.
20+ /// Prepares autofill's data on passwords + Fido2 combined in a single section for the vault list builder.
21+ /// - Parameters:
22+ /// - ciphers: An array of `Cipher` objects to be processed.
23+ /// - filter: A `VaultListFilter` object that defines the filtering criteria for the vault list.
24+ /// - Returns: An optional `VaultListPreparedData` object containing the prepared data for the vault list.
25+ /// Returns `nil` if the vault is empty.
26+ func prepareAutofillCombinedSingleData(
27+ from ciphers: [ Cipher ] ,
28+ filter: VaultListFilter
29+ ) async throws -> VaultListPreparedData ?
30+
31+ /// Prepares data for the vault list builder.
2532 /// - Parameters:
2633 /// - ciphers: An array of `Cipher` objects to be processed.
2734 /// - collections: An array of `Collection` objects to be processed.
2835 /// - folders: An array of `Folder` objects to be processed.
2936 /// - filter: A `VaultListFilter` object that defines the filtering criteria for the vault list.
3037 /// - Returns: An optional `VaultListPreparedData` object containing the prepared data for the vault list.
3138 /// Returns `nil` if the vault is empty.
32- func prepareGroupData (
39+ func prepareData (
3340 from ciphers: [ Cipher ] ,
3441 collections: [ Collection ] ,
3542 folders: [ Folder ] ,
3643 filter: VaultListFilter
3744 ) async throws -> VaultListPreparedData ?
3845
39- /// Prepares autofill's passwords data for the vault list builder.
46+ /// Prepares group data for the vault list builder.
4047 /// - Parameters:
4148 /// - ciphers: An array of `Cipher` objects to be processed.
49+ /// - collections: An array of `Collection` objects to be processed.
50+ /// - folders: An array of `Folder` objects to be processed.
4251 /// - filter: A `VaultListFilter` object that defines the filtering criteria for the vault list.
4352 /// - Returns: An optional `VaultListPreparedData` object containing the prepared data for the vault list.
4453 /// Returns `nil` if the vault is empty.
45- func prepareAutofillPasswordsData (
54+ func prepareGroupData (
4655 from ciphers: [ Cipher ] ,
56+ collections: [ Collection ] ,
57+ folders: [ Folder ] ,
4758 filter: VaultListFilter
4859 ) async throws -> VaultListPreparedData ?
4960}
@@ -71,6 +82,78 @@ struct DefaultVaultListDataPreparator: VaultListDataPreparator {
7182
7283 // MARK: Methods
7384
85+ func prepareAutofillPasswordsData(
86+ from ciphers: [ Cipher ] ,
87+ filter: VaultListFilter
88+ ) async throws -> VaultListPreparedData ? {
89+ guard !ciphers. isEmpty, let uri = filter. uri else {
90+ return nil
91+ }
92+
93+ let cipherMatchingHelper = await cipherMatchingHelperFactory. make ( uri: uri)
94+
95+ var preparedDataBuilder = vaultListPreparedDataBuilderFactory. make ( )
96+ let restrictedOrganizationIds = await prepareRestrictedOrganizationIds ( builder: preparedDataBuilder)
97+
98+ await ciphersClientWrapperService. decryptAndProcessCiphersInBatch (
99+ ciphers: ciphers
100+ ) { decryptedCipher in
101+ guard decryptedCipher. deletedDate == nil ,
102+ decryptedCipher. passesRestrictItemTypesPolicy ( restrictedOrganizationIds) else {
103+ return
104+ }
105+
106+ let matchResult = cipherMatchingHelper. doesCipherMatch ( cipher: decryptedCipher)
107+
108+ preparedDataBuilder = await preparedDataBuilder. addItem (
109+ withMatchResult: matchResult,
110+ cipher: decryptedCipher
111+ )
112+ }
113+
114+ return preparedDataBuilder. build ( )
115+ }
116+
117+ func prepareAutofillCombinedSingleData(
118+ from ciphers: [ Cipher ] ,
119+ filter: VaultListFilter
120+ ) async throws -> VaultListPreparedData ? {
121+ guard !ciphers. isEmpty, let uri = filter. uri else {
122+ return nil
123+ }
124+
125+ let cipherMatchingHelper = await cipherMatchingHelperFactory. make ( uri: uri)
126+
127+ var preparedDataBuilder = vaultListPreparedDataBuilderFactory. make ( )
128+ let restrictedOrganizationIds = await prepareRestrictedOrganizationIds ( builder: preparedDataBuilder)
129+
130+ await ciphersClientWrapperService. decryptAndProcessCiphersInBatch (
131+ ciphers: ciphers
132+ ) { decryptedCipher in
133+ guard decryptedCipher. deletedDate == nil ,
134+ decryptedCipher. passesRestrictItemTypesPolicy ( restrictedOrganizationIds) else {
135+ return
136+ }
137+
138+ let matchResult = cipherMatchingHelper. doesCipherMatch ( cipher: decryptedCipher)
139+ guard matchResult != . none else {
140+ return
141+ }
142+
143+ guard decryptedCipher. type. loginListView? . hasFido2 == true else {
144+ preparedDataBuilder = await preparedDataBuilder. addItem (
145+ forGroup: . login,
146+ with: decryptedCipher
147+ )
148+ return
149+ }
150+
151+ preparedDataBuilder = await preparedDataBuilder. addFido2Item ( cipher: decryptedCipher)
152+ }
153+
154+ return preparedDataBuilder. build ( )
155+ }
156+
74157 func prepareData(
75158 from ciphers: [ Cipher ] ,
76159 collections: [ Collection ] ,
@@ -164,38 +247,6 @@ struct DefaultVaultListDataPreparator: VaultListDataPreparator {
164247 return preparedDataBuilder. build ( )
165248 }
166249
167- func prepareAutofillPasswordsData(
168- from ciphers: [ Cipher ] ,
169- filter: VaultListFilter
170- ) async throws -> VaultListPreparedData ? {
171- guard !ciphers. isEmpty, let uri = filter. uri else {
172- return nil
173- }
174-
175- let cipherMatchingHelper = await cipherMatchingHelperFactory. make ( uri: uri)
176-
177- var preparedDataBuilder = vaultListPreparedDataBuilderFactory. make ( )
178- let restrictedOrganizationIds : [ String ] = await prepareRestrictedOrganizationIds ( builder: preparedDataBuilder)
179-
180- await ciphersClientWrapperService. decryptAndProcessCiphersInBatch (
181- ciphers: ciphers
182- ) { decryptedCipher in
183- guard decryptedCipher. deletedDate == nil ,
184- decryptedCipher. passesRestrictItemTypesPolicy ( restrictedOrganizationIds) else {
185- return
186- }
187-
188- let matchResult = cipherMatchingHelper. doesCipherMatch ( cipher: decryptedCipher)
189-
190- preparedDataBuilder = await preparedDataBuilder. addItem (
191- withMatchResult: matchResult,
192- cipher: decryptedCipher
193- )
194- }
195-
196- return preparedDataBuilder. build ( )
197- }
198-
199250 // MARK: Private
200251
201252 /// Returns the restricted organization IDs for the `.restrictItemTypes` policy if enabled
0 commit comments