use of com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation in project android by owncloud.
the class UnshareOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
// Get Share for a file
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath, mShareType, mShareWith);
if (share != null) {
OCFile file = getStorageManager().getFileByPath(mRemotePath);
RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getRemoteId());
result = operation.execute(client);
if (result.isSuccess()) {
Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted");
if (ShareType.PUBLIC_LINK.equals(mShareType)) {
file.setShareViaLink(false);
file.setPublicLink("");
} else if (ShareType.USER.equals(mShareType) || ShareType.GROUP.equals(mShareType) || ShareType.FEDERATED.equals(mShareType)) {
// Check if it is the last share
ArrayList<OCShare> sharesWith = getStorageManager().getSharesWithForAFile(mRemotePath, getStorageManager().getAccount().name);
if (sharesWith.size() == 1) {
file.setShareWithSharee(false);
}
}
getStorageManager().saveFile(file);
getStorageManager().removeShare(share);
} else if (result.getCode() != ResultCode.SERVICE_UNAVAILABLE && !existsFile(client, file.getRemotePath())) {
// unshare failed because file was deleted before
getStorageManager().removeFile(file, true, true);
}
} else {
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
}
return result;
}
Aggregations