Skip to content

Commit 8394fb4

Browse files
committed
fix(share-list-fragment): simplify logic
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent e4ed039 commit 8394fb4

1 file changed

Lines changed: 19 additions & 27 deletions

File tree

app/src/main/java/com/owncloud/android/ui/adapter/OCShareToOCFileConverter.kt

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object OCShareToOCFileConverter {
4141
path.isNotEmpty() && path.startsWith(OCFile.PATH_SEPARATOR)
4242
}
4343
.map { (path, sharesForPath) ->
44-
buildOcFile(path, sharesForPath, storageManager)
44+
buildOCFile(path, sharesForPath, storageManager)
4545
}
4646
.sortedByDescending { it.firstShareTimestamp }
4747

@@ -88,38 +88,30 @@ object OCShareToOCFileConverter {
8888
(cachedFiles + newFiles).distinctBy { it.remotePath }
8989
}
9090

91-
private fun buildOcFile(path: String, shares: List<OCShare>, storageManager: FileDataStorageManager): OCFile {
91+
private fun buildOCFile(path: String, shares: List<OCShare>, storageManager: FileDataStorageManager): OCFile {
9292
require(shares.all { it.path == path })
9393

9494
val firstShare = shares.first()
9595
val firstShareTimestamp = shares.minOf { it.sharedDate * MILLIS_PER_SECOND }
9696

97-
val existingFile = (
98-
storageManager.getFileByDecryptedRemotePath(path)
99-
?.applyShareData(firstShare, firstShareTimestamp)
100-
)
101-
val fileCreatedFromShare = OCFile(path).applyShareData(firstShare, firstShareTimestamp)
102-
val file = existingFile ?: fileCreatedFromShare.apply {
103-
decryptedRemotePath = path
104-
fileLength = -1
105-
modificationTimestamp = -1
106-
}
97+
val linkShares = shares.filter { it.shareType in LINK_SHARE_TYPES }
98+
val userShares = shares.filter { it.shareType !in LINK_SHARE_TYPES }
10799

108-
return file.apply {
109-
isSharedViaLink = shares.any { it.shareType in LINK_SHARE_TYPES }
110-
isSharedWithSharee = shares.any { it.shareType !in LINK_SHARE_TYPES }
111-
if (isSharedWithSharee) {
112-
sharees = shares
113-
.filter { it.shareType !in LINK_SHARE_TYPES }
114-
.map {
115-
ShareeUser(
116-
userId = it.userId,
117-
displayName = it.sharedWithDisplayName,
118-
shareType = it.shareType
119-
)
120-
}
121-
}
122-
}
100+
val file = (storageManager.getFileByDecryptedRemotePath(path) ?: newOCFile(path))
101+
102+
file.applyShareData(firstShare, firstShareTimestamp)
103+
104+
file.isSharedViaLink = linkShares.isNotEmpty()
105+
file.isSharedWithSharee = userShares.isNotEmpty()
106+
file.sharees = userShares.map { ShareeUser(it.userId, it.sharedWithDisplayName, it.shareType) }
107+
108+
return file
109+
}
110+
111+
private fun newOCFile(path: String) = OCFile(path).also {
112+
it.decryptedRemotePath = path
113+
it.fileLength = -1
114+
it.modificationTimestamp = -1
123115
}
124116

125117
private fun OCFile.applyShareData(firstShare: OCShare, firstShareTimestamp: Long) = apply {

0 commit comments

Comments
 (0)