@@ -35,6 +35,7 @@ import it.niedermann.owncloud.notes.shared.util.StringConstants
3535import it.niedermann.owncloud.notes.shared.util.extensions.getErrorMessage
3636import it.niedermann.owncloud.notes.shared.util.extensions.toExpirationDateString
3737import org.json.JSONObject
38+ import retrofit2.Response
3839import java.util.Date
3940
4041class ShareRepository (
@@ -61,7 +62,7 @@ class ShareRepository(
6162 val notesPathResponseResult = getNotesPathResponseResult() ? : return null
6263 val notesPath = notesPathResponseResult.notesPath
6364 val notesSuffix = notesPathResponseResult.fileSuffix
64- return StringConstants .PATH + notesPath + StringConstants .PATH + note.title + notesSuffix
65+ return StringConstants .PATH + notesPath + StringConstants .PATH + note.category + StringConstants . PATH + note. title + notesSuffix
6566 }
6667
6768 fun getShareEntitiesForSpecificNote (note : Note ): List <ShareEntity > {
@@ -270,25 +271,37 @@ class ShareRepository(
270271 }
271272 }
272273
273- fun getShareFromNote (note : Note ): List <OCShare >? {
274+ fun getShareFromNote (note : Note ): List <OCShare > {
274275 val shareAPI = apiProvider.getShareAPI(applicationContext, account)
275- val path = getNotePath(note) ? : return null
276- val call = shareAPI.getShareFromNote(path)
277- val response = call.execute()
276+ val path = getNotePath(note) ? : return emptyList<OCShare >()
277+
278+ val callSharedWithMe = shareAPI.getShareFromNote(path, true )
279+ var response = callSharedWithMe.execute()
280+ val sharedWithMe = parseResponse(response)
278281
282+ val callSharedWithOthers = shareAPI.getShareFromNote(path, false )
283+ response = callSharedWithOthers.execute()
284+ val sharedWithOthers = parseResponse(response)
285+
286+ sharedWithOthers.addAll(sharedWithMe)
287+
288+ return sharedWithOthers
289+ }
290+
291+ private fun parseResponse (response : Response <OcsResponse <List <CreateShareResponse >>>): MutableList <OCShare > {
279292 return try {
280293 if (response.isSuccessful) {
281294 val body = response.body()
282295 Log_OC .d(tag, " Response successful: $body " )
283- body?.ocs?.data?.toOCShareList()
296+ body?.ocs?.data?.toOCShareList()?.toMutableList() ? : mutableListOf ()
284297 } else {
285298 val errorBody = response.errorBody()?.string()
286299 Log_OC .d(tag, " Response failed: $errorBody " )
287- null
300+ mutableListOf ()
288301 }
289302 } catch (e: Exception ) {
290303 Log_OC .d(tag, " Exception while getting share from note: " , e)
291- null
304+ mutableListOf ()
292305 }
293306 }
294307
0 commit comments