@@ -66,46 +66,55 @@ class AccountListViewModel: AccountListViewModelProtocol {
66
66
}
67
67
}
68
68
69
+ func refreshBoxItems( ) -> Promise < Void > {
70
+ return all ( accountInfos
71
+ . map { BoxCredential ( tokenStorage: BoxTokenStorage ( userID: $0. accountUID) ) }
72
+ . map { self . createAccountCellContent ( for: $0) }
73
+ ) . then { accounts in
74
+ self . accounts = accounts
75
+ }
76
+ }
77
+
69
78
func createAccountCellContent( from accountInfo: AccountInfo ) throws -> AccountCellContent {
70
79
switch cloudProviderType {
80
+ case . box:
81
+ return createAccountCellContentPlaceholder ( )
71
82
case . dropbox:
72
- let credential = DropboxCredential ( tokenUID: accountInfo. accountUID)
73
- return createAccountCellContentPlaceholder ( for: credential)
83
+ return createAccountCellContentPlaceholder ( )
74
84
case . googleDrive:
75
85
let credential = GoogleDriveCredential ( userID: accountInfo. accountUID)
76
86
return try createAccountCellContent ( for: credential)
87
+ case . localFileSystem:
88
+ throw AccountListError . unsupportedCloudProviderType
77
89
case . oneDrive:
78
90
let credential = try OneDriveCredential ( with: accountInfo. accountUID)
79
91
return try createAccountCellContent ( for: credential)
80
92
case . pCloud:
81
- let credential = try PCloudCredential ( userID: accountInfo. accountUID)
82
- return createAccountCellContentPlaceholder ( for: credential)
83
- case . webDAV:
84
- guard let credential = WebDAVCredentialManager . shared. getCredentialFromKeychain ( with: accountInfo. accountUID) else {
85
- throw CloudProviderAccountError . accountNotFoundError
86
- }
87
- return createAccountCellContent ( for: credential)
88
- case . localFileSystem:
89
- throw AccountListError . unsupportedCloudProviderType
93
+ return createAccountCellContentPlaceholder ( )
90
94
case . s3:
91
95
guard let credential = S3CredentialManager . shared. getCredential ( with: accountInfo. accountUID) else {
92
96
throw CloudProviderAccountError . accountNotFoundError
93
97
}
94
98
let displayName = try S3CredentialManager . shared. getDisplayName ( for: credential)
95
99
return createAccountCellContent ( for: credential, displayName: displayName)
100
+ case . webDAV:
101
+ guard let credential = WebDAVCredentialManager . shared. getCredentialFromKeychain ( with: accountInfo. accountUID) else {
102
+ throw CloudProviderAccountError . accountNotFoundError
103
+ }
104
+ return createAccountCellContent ( for: credential)
96
105
}
97
106
}
98
107
108
+ private func createAccountCellContentPlaceholder( ) -> AccountCellContent {
109
+ return AccountCellContent ( mainLabelText: " (…) " , detailLabelText: nil )
110
+ }
111
+
99
112
private func createAccountCellContent( for credential: DropboxCredential ) -> Promise < AccountCellContent > {
100
113
return credential. getUsername ( ) . then { username in
101
114
AccountCellContent ( mainLabelText: username, detailLabelText: nil )
102
115
}
103
116
}
104
117
105
- private func createAccountCellContentPlaceholder( for credential: DropboxCredential ) -> AccountCellContent {
106
- return AccountCellContent ( mainLabelText: " (…) " , detailLabelText: nil )
107
- }
108
-
109
118
private func createAccountCellContent( for credential: GoogleDriveCredential ) throws -> AccountCellContent {
110
119
let username = try credential. getUsername ( )
111
120
return AccountCellContent ( mainLabelText: username, detailLabelText: nil )
@@ -122,8 +131,10 @@ class AccountListViewModel: AccountListViewModelProtocol {
122
131
}
123
132
}
124
133
125
- private func createAccountCellContentPlaceholder( for credential: PCloudCredential ) -> AccountCellContent {
126
- return AccountCellContent ( mainLabelText: " (…) " , detailLabelText: nil )
134
+ func createAccountCellContent( for credential: BoxCredential ) -> Promise < AccountCellContent > {
135
+ return credential. getUsername ( ) . then { username in
136
+ AccountCellContent ( mainLabelText: username, detailLabelText: nil )
137
+ }
127
138
}
128
139
129
140
func createAccountCellContent( for credential: WebDAVCredential ) -> AccountCellContent {
@@ -203,6 +214,12 @@ class AccountListViewModel: AccountListViewModelProtocol {
203
214
} . catch { error in
204
215
self . databaseChangedPublisher. send ( . failure( error) )
205
216
}
217
+ } else if self . cloudProviderType == . box {
218
+ self . refreshBoxItems ( ) . then {
219
+ self . databaseChangedPublisher. send ( . success( self . accounts) )
220
+ } . catch { error in
221
+ self . databaseChangedPublisher. send ( . failure( error) )
222
+ }
206
223
}
207
224
} )
208
225
return databaseChangedPublisher. eraseToAnyPublisher ( )
0 commit comments