7676import it .niedermann .owncloud .notes .share .listener .ShareeListAdapterListener ;
7777import it .niedermann .owncloud .notes .share .model .CreateShareResponse ;
7878import it .niedermann .owncloud .notes .share .model .CreateShareResponseExtensionsKt ;
79+ import it .niedermann .owncloud .notes .share .model .UpdateShareRequest ;
7980import it .niedermann .owncloud .notes .share .model .UsersAndGroupsSearchConfig ;
8081import it .niedermann .owncloud .notes .share .repository .ShareRepository ;
8182import it .niedermann .owncloud .notes .shared .model .Capabilities ;
8485import it .niedermann .owncloud .notes .shared .util .ShareUtil ;
8586import it .niedermann .owncloud .notes .shared .util .clipboard .ClipboardUtil ;
8687import it .niedermann .owncloud .notes .shared .util .extensions .BundleExtensionsKt ;
88+ import it .niedermann .owncloud .notes .util .DateUtil ;
8789
8890public class NoteShareActivity extends BrandedActivity implements ShareeListAdapterListener , NoteShareItemAction , QuickSharingPermissionsBottomSheetDialog .QuickPermissionSharingBottomSheetActions , SharePasswordDialogFragment .SharePasswordDialogListener {
8991
@@ -161,7 +163,7 @@ private void initializeArguments() {
161163 final var ssoAcc = SingleAccountHelper .getCurrentSingleSignOnAccount (NoteShareActivity .this );
162164 repository = new ShareRepository (NoteShareActivity .this , ssoAcc );
163165 capabilities = repository .getCapabilities ();
164- repository .getSharesForNotesAndSaveShareEntities ();
166+ repository .fetchSharesForNotesAndSaveShareEntities ();
165167
166168 runOnUiThread (() -> {
167169 binding .fileName .setText (note .getTitle ());
@@ -396,7 +398,7 @@ public void createPublicShareLink() {
396398 requestPasswordForShareViaLink (true , capabilities .getAskForOptionalPassword ());
397399 } else {
398400 executorService .submit (() -> {
399- final var result = repository .addShare (note , ShareType .PUBLIC_LINK , "" , "false" , "" , 0 , "" );
401+ final var result = repository .addShare (note , ShareType .PUBLIC_LINK , "" );
400402 runOnUiThread (() -> {
401403 if (result instanceof ApiResult .Success <OcsResponse <CreateShareResponse >> successResponse && binding .sharesList .getAdapter () instanceof ShareeListAdapter adapter ) {
402404 DisplayUtils .showSnackMessage (NoteShareActivity .this , successResponse .getMessage ());
@@ -519,17 +521,16 @@ public void updateShareeListAdapter() {
519521 return ;
520522 }
521523
522- List <OCShare > tempShares = new ArrayList <>();
523-
524- // to show share with users/groups info
524+ List <OCShare > remoteNotes ;
525525 if (note != null ) {
526- // get shares from local DB
527- populateSharesList (tempShares );
526+ remoteNotes = repository .fetchSharesFromNote (note );
527+ } else {
528+ remoteNotes = new ArrayList <>();
528529 }
529530
530531 runOnUiThread (() -> {
531532 shares .clear ();
532- shares .addAll (tempShares );
533+ shares .addAll (remoteNotes );
533534
534535 adapter .removeAll ();
535536 adapter .addShares (shares );
@@ -544,35 +545,6 @@ public void updateShareeListAdapter() {
544545 });
545546 }
546547
547- private void populateSharesList (List <OCShare > targetList ) {
548- // Get shares from local DB
549- final var shareEntities = repository .getShareEntitiesForSpecificNote (note );
550- for (var entity : shareEntities ) {
551- if (entity .getId () != null ) {
552- addSharesToList (entity .getId (), targetList );
553- }
554- }
555-
556- // Get shares from remote
557- final var remoteShares = repository .getShareFromNote (note );
558- if (remoteShares != null ) {
559- for (var entity : remoteShares ) {
560- addSharesToList (entity .getId (), targetList );
561- }
562- }
563- }
564-
565- private void addSharesToList (long id , List <OCShare > targetList ) {
566- final var result = repository .getShares (id );
567- if (result != null ) {
568- for (OCShare ocShare : result ) {
569- if (!targetList .contains (ocShare )) {
570- targetList .add (ocShare );
571- }
572- }
573- }
574- }
575-
576548 private void addPublicShares (ShareeListAdapter adapter ) {
577549 List <OCShare > publicShares = new ArrayList <>();
578550
@@ -672,13 +644,13 @@ public void search(String query) {
672644
673645 @ Override
674646 public void advancedPermissions (OCShare share ) {
675- modifyExistingShare (share , NoteShareDetailActivity .SCREEN_TYPE_PERMISSION );
647+ modifyExistingShare (share , NoteShareDetailActivity .SCREEN_TYPE_PERMISSION , false );
676648 }
677649
678650
679651 @ Override
680652 public void sendNewEmail (OCShare share ) {
681- modifyExistingShare (share , NoteShareDetailActivity .SCREEN_TYPE_NOTE );
653+ modifyExistingShare (share , NoteShareDetailActivity .SCREEN_TYPE_NOTE , true );
682654 }
683655
684656 @ Override
@@ -711,13 +683,14 @@ public void addAnotherLink(OCShare share) {
711683 createPublicShareLink ();
712684 }
713685
714- private void modifyExistingShare (OCShare share , int screenTypePermission ) {
686+ private void modifyExistingShare (OCShare share , int screenTypePermission , boolean sendEmail ) {
715687 Bundle bundle = new Bundle ();
716688
717689 bundle .putSerializable (NoteShareDetailActivity .ARG_OCSHARE , share );
718690 bundle .putInt (NoteShareDetailActivity .ARG_SCREEN_TYPE , screenTypePermission );
719691 bundle .putBoolean (NoteShareDetailActivity .ARG_RESHARE_SHOWN , !isReshareForbidden (share ));
720692 bundle .putBoolean (NoteShareDetailActivity .ARG_EXP_DATE_SHOWN , getExpDateShown ());
693+ bundle .putBoolean (NoteShareDetailActivity .ARG_SEND_EMAIL , sendEmail );
721694
722695 Intent intent = new Intent (this , NoteShareDetailActivity .class );
723696 intent .putExtras (bundle );
@@ -759,12 +732,17 @@ public void onQuickPermissionChanged(OCShare share, int permission) {
759732 }
760733
761734 private void updateShare (OCShare share ) {
735+ if (note == null ) {
736+ Log_OC .e (TAG , "note is null, cannot update share" );
737+ return ;
738+ }
739+
762740 executorService .submit (() -> {
763741 try {
764- final var updatedShares = repository .getShares ( share . getId () );
742+ final var updatedShares = repository .fetchSharesFromNote ( note );
765743
766744 runOnUiThread (() -> {
767- if (updatedShares != null && binding .sharesList .getAdapter () instanceof ShareeListAdapter adapter ) {
745+ if (binding .sharesList .getAdapter () instanceof ShareeListAdapter adapter ) {
768746 OCShare updatedShare = null ;
769747 for (int i =0 ;i <updatedShares .size ();i ++) {
770748 if (updatedShares .get (i ).getId () == share .getId ()) {
@@ -857,8 +835,7 @@ public void shareFileViaPublicShare(@Nullable Note note, @Nullable String passwo
857835 "" ,
858836 "false" ,
859837 password ,
860- repository .getCapabilities ().getDefaultPermission (),
861- ""
838+ repository .getCapabilities ().getDefaultPermission ()
862839 );
863840
864841 runOnUiThread (() -> {
@@ -881,14 +858,22 @@ public void setPasswordToShare(@NotNull OCShare share, @Nullable String password
881858
882859 executorService .submit (() -> {
883860 {
884- final var requestBody = repository .getUpdateShareRequest (
885- false ,
886- share ,
887- "" ,
888- password ,
889- false ,
890- -1 ,
891- share .getPermissions ()
861+ boolean isDownloadAndAllowsSyncEnabled = repository .isAllowDownloadAndSync (share );
862+
863+ String attributes = UpdateShareRequest .Companion .createAttributes (
864+ repository .getCapabilities (),
865+ isDownloadAndAllowsSyncEnabled ,
866+ share .getShareType ()
867+ );
868+
869+ final var requestBody = new UpdateShareRequest (
870+ share .getPermissions (),
871+ password ,
872+ share .getNote (),
873+ share .getLabel (),
874+ DateUtil .INSTANCE .getExpirationDate (share .getExpirationDate ()),
875+ Boolean .toString (share .isHideFileDownload ()),
876+ attributes
892877 );
893878 final var result = repository .updateShare (share .getId (), requestBody );
894879
0 commit comments