Visitar URL original
fix: refresh share badges when folder etag is unchanged · owncloud/android@b3b7759 · GitHub
Skip to content

Commit b3b7759

Browse files
committed
fix: refresh share badges when folder etag is unchanged
When the etag still matches but sharedByLink, permissions, or the boolean sharedWithSharee value differ (null and false count as equal), that child is added to the files saved for the folder. The saved row keeps local properties, the existing etag, and the thumbnail-update flag, keeps the remote share fields, and is marked available offline through the parent when the parent is available offline. A unit test covers refreshFolder persisting a folder child in that case, and the unreleased changelog notes the badge refresh. Fixes #4938 Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent f07aa5b commit b3b7759

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

‎changelog/unreleased/4938‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bugfix: Refresh share badges when the folder etag is unchanged
2+
3+
Share badges have been refreshed on pull-to-refresh when a folder etag is unchanged
4+
after the folder is shared or unshared on ownCloud 10.
5+
6+
https://github.com/owncloud/android/issues/4938

‎owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ class OCFileRepository(
404404
}
405405
// Fix: What about renames? Need to fix storage path
406406
})
407+
} else if (shareMetadataChanged(localChildToSync, remoteChild)) {
408+
// oC10 does not change the etag when only share metadata changes.
409+
folderContentUpdated.add(childWithRefreshedShareMetadata(remoteChild, localChildToSync, remoteFolder))
407410
}
408411
}
409412

@@ -609,6 +612,26 @@ class OCFileRepository(
609612
deleteOrResetFileFromDatabase(ocFile, onlyFromLocalStorage)
610613
}
611614

615+
private fun shareMetadataChanged(localChild: OCFile, remoteChild: OCFile): Boolean =
616+
localChild.sharedByLink != remoteChild.sharedByLink ||
617+
(localChild.sharedWithSharee == true) != (remoteChild.sharedWithSharee == true) ||
618+
localChild.permissions != remoteChild.permissions
619+
620+
private fun childWithRefreshedShareMetadata(
621+
remoteChild: OCFile,
622+
localChild: OCFile,
623+
remoteFolder: OCFile,
624+
): OCFile =
625+
remoteChild.apply {
626+
copyLocalPropertiesFrom(localChild)
627+
// DO NOT update etag till contents are synced. Share fields stay on the remote child.
628+
etag = localChild.etag
629+
needsToUpdateThumbnail = localChild.needsToUpdateThumbnail
630+
if (remoteFolder.isAvailableOffline) {
631+
availableOfflineStatus = AVAILABLE_OFFLINE_PARENT
632+
}
633+
}
634+
612635
private fun deleteOrResetFileFromDatabase(ocFile: OCFile, onlyFromLocalStorage: Boolean) {
613636
if (onlyFromLocalStorage) {
614637
localFileDataSource.saveFile(ocFile.copy(storagePath = null, etagInConflict = null, lastUsage = null, etag = null))

‎owncloudData/src/test/java/com/owncloud/android/data/files/repository/OCFileRepositoryTest.kt‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,71 @@ class OCFileRepositoryTest {
16851685
}
16861686
}
16871687

1688+
@Suppress("MaxLineLength")
1689+
@Test
1690+
fun `refreshFolder saves a folder child when the etag matches but share badges changed`() {
1691+
val ocParentFolderWithoutSpaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.copy(spaceId = null)
1692+
val remoteFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(spaceId = null, sharedByLink = true)
1693+
val expectedFolderChild = OC_FOLDER_WITH_SPACE_ID.copy(sharedByLink = true)
1694+
every {
1695+
remoteFileDataSource.refreshFolder(
1696+
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
1697+
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
1698+
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
1699+
)
1700+
} returns listOf(ocParentFolderWithoutSpaceId, remoteFolderChild)
1701+
every {
1702+
localFileDataSource.getFileByRemotePath(
1703+
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
1704+
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
1705+
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
1706+
)
1707+
} returns OC_PARENT_FOLDER_WITH_SPACE_ID
1708+
every {
1709+
localFileDataSource.getFolderContent(
1710+
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
1711+
)
1712+
} returns listOf(OC_FOLDER_WITH_SPACE_ID)
1713+
every {
1714+
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
1715+
listOfFiles = listOf(expectedFolderChild),
1716+
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
1717+
)
1718+
} returns listOf(expectedFolderChild)
1719+
1720+
val listOfFiles = ocFileRepository.refreshFolder(
1721+
OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
1722+
OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
1723+
OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
1724+
false
1725+
)
1726+
assertEquals(listOf(expectedFolderChild), listOfFiles)
1727+
1728+
verify(exactly = 1) {
1729+
localSpacesDataSource.getWebDavUrlForSpace(
1730+
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId,
1731+
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner
1732+
)
1733+
remoteFileDataSource.refreshFolder(
1734+
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
1735+
accountName = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
1736+
spaceWebDavUrl = OC_SPACE_PERSONAL.root.webDavUrl
1737+
)
1738+
localFileDataSource.getFileByRemotePath(
1739+
remotePath = OC_PARENT_FOLDER_WITH_SPACE_ID.remotePath,
1740+
owner = OC_PARENT_FOLDER_WITH_SPACE_ID.owner,
1741+
spaceId = OC_PARENT_FOLDER_WITH_SPACE_ID.spaceId
1742+
)
1743+
localFileDataSource.getFolderContent(
1744+
folderId = OC_PARENT_FOLDER_WITH_SPACE_ID.id!!
1745+
)
1746+
localFileDataSource.saveFilesInFolderAndReturnTheFilesThatChanged(
1747+
listOfFiles = listOf(expectedFolderChild),
1748+
folder = OC_PARENT_FOLDER_WITH_SPACE_ID,
1749+
)
1750+
}
1751+
}
1752+
16881753
@Suppress("MaxLineLength")
16891754
@Test
16901755
fun `refreshFolder returns an empty list of OCFiles when folder and its content already exists in database but there are additional files in conflict in local to be removed`() {

0 commit comments

Comments
 (0)