@@ -170,7 +170,7 @@ async function UIWindowShare(items, recipient){
170
170
recipients . forEach ( perm => {
171
171
//check if this user has been printed here before, important for multiple items
172
172
if ( ! printed_users . includes ( perm . user . username ) ) {
173
- perm_list += `<div data-permission="${ perm . permission } " class="item-perm-recipient-card item-prop-perm-entry" data-perm- uid="${ perm . user . uid } " style="margin-bottom:5px; margin-top:5px;">`
173
+ perm_list += `<div data-permission="${ perm . permission } " class="item-perm-recipient-card item-prop-perm-entry" data-recipient-username=" ${ perm . user . username } " data-perm- uid="${ perm . user . uid } " data-perm-email=" ${ perm . user . email } " style="margin-bottom:5px; margin-top:5px;">`
174
174
perm_list += `${ perm . user . email ?? perm . user . username } ` ;
175
175
perm_list += `<div style="float:right;"><span class="remove-permission-link remove-permission-icon" data-recipient-username="${ perm . user . username } " data-permission="${ perm . permission } ">✕</span></div>` ;
176
176
perm_list += `</div>` ;
@@ -205,6 +205,22 @@ async function UIWindowShare(items, recipient){
205
205
recipient_email = recipient_id ;
206
206
else
207
207
recipient_username = recipient_id ;
208
+
209
+ // see if the recipient is already in the list
210
+ let recipient_already_in_list = false ;
211
+ $ ( el_window ) . find ( '.item-perm-recipient-card' ) . each ( function ( ) {
212
+ if ( ( recipient_username && $ ( this ) . data ( 'recipient-username' ) === recipient_username ) || ( recipient_email && $ ( this ) . data ( 'recipient-email' ) === recipient_email ) ) {
213
+ recipient_already_in_list = true ;
214
+ return false ;
215
+ }
216
+ } )
217
+
218
+ if ( recipient_already_in_list ) {
219
+ $ ( el_window ) . find ( '.error' ) . html ( 'This user already has access' ) ;
220
+ $ ( el_window ) . find ( '.error' ) . fadeIn ( ) ;
221
+ return ;
222
+ }
223
+
208
224
// can't share with self
209
225
if ( recipient_username === window . user . username ) {
210
226
$ ( el_window ) . find ( '.error' ) . html ( 'You can\'t share with yourself' ) ;
@@ -244,33 +260,42 @@ async function UIWindowShare(items, recipient){
244
260
]
245
261
} ) ,
246
262
success : function ( response ) {
247
- // show success message
248
- $ ( el_window ) . find ( '.access-recipient-print' ) . html ( recipient_id ) ;
249
- let perm_id = `fs:${ items [ 0 ] . uid } :${ access_level } ` ;
250
-
251
- // append recipient to list
252
- let perm_list = '' ;
253
- perm_list += `<div data-permission="${ perm_id } " class="item-perm-recipient-card item-prop-perm-entry" style="margin-bottom:5px; margin-top:5px;">`
254
- perm_list += `${ recipient_username } ` ;
255
- perm_list += `<div style="float:right;"><span class="remove-permission-link remove-permission-icon" data-recipient-username="${ recipient_username } " data-permission="${ perm_id } ">✕</span></div>` ;
256
- perm_list += `</div>` ;
257
-
258
- // reset input
259
- $ ( el_window ) . find ( '.error' ) . hide ( ) ;
260
- $ ( el_window ) . find ( '.access-recipient' ) . val ( '' ) ;
261
-
262
- // disable 'Give Access' button
263
- $ ( el_window ) . find ( '.give-access-btn' ) . prop ( 'disabled' , true ) ;
264
-
265
- // append recipient to list
266
- $ ( el_window ) . find ( '.share-recipients' ) . append ( `${ perm_list } ` ) ;
267
-
268
- // add to contacts
269
- if ( ! contacts . includes ( recipient_username ) ) {
270
- contacts . push ( recipient_username ) ;
271
- puter . kv . set ( 'contacts' , JSON . stringify ( contacts ) ) ;
263
+ if ( response . status === "mixed" ) {
264
+ response . recipients . forEach ( recipient => {
265
+ if ( recipient . code === "user_does_not_exist" ) {
266
+ $ ( el_window ) . find ( '.error' ) . html ( recipient . message ) ;
267
+ $ ( el_window ) . find ( '.error' ) . fadeIn ( ) ;
268
+ cancelled_due_to_error = true ;
269
+ }
270
+ } ) ;
271
+ } else {
272
+ // show success message
273
+ $ ( el_window ) . find ( '.access-recipient-print' ) . html ( recipient_id ) ;
274
+ let perm_id = `fs:${ items [ 0 ] . uid } :${ access_level } ` ;
275
+
276
+ // append recipient to list
277
+ let perm_list = '' ;
278
+ perm_list += `<div data-permission="${ perm_id } " class="item-perm-recipient-card item-prop-perm-entry" style="margin-bottom:5px; margin-top:5px;">`
279
+ perm_list += `${ recipient_username } ` ;
280
+ perm_list += `<div style="float:right;"><span class="remove-permission-link remove-permission-icon" data-recipient-username="${ recipient_username } " data-permission="${ perm_id } ">✕</span></div>` ;
281
+ perm_list += `</div>` ;
282
+
283
+ // reset input
284
+ $ ( el_window ) . find ( '.error' ) . hide ( ) ;
285
+ $ ( el_window ) . find ( '.access-recipient' ) . val ( '' ) ;
286
+
287
+ // disable 'Give Access' button
288
+ $ ( el_window ) . find ( '.give-access-btn' ) . prop ( 'disabled' , true ) ;
289
+
290
+ // append recipient to list
291
+ $ ( el_window ) . find ( '.share-recipients' ) . append ( `${ perm_list } ` ) ;
292
+
293
+ // add to contacts
294
+ if ( ! contacts . includes ( recipient_username ) ) {
295
+ contacts . push ( recipient_username ) ;
296
+ puter . kv . set ( 'contacts' , JSON . stringify ( contacts ) ) ;
297
+ }
272
298
}
273
-
274
299
} ,
275
300
error : function ( err ) {
276
301
// at this point 'username_not_found' and 'shared_with_self' are the only
@@ -282,7 +307,7 @@ async function UIWindowShare(items, recipient){
282
307
}
283
308
// re-enable share button
284
309
$ ( el_window ) . find ( '.give-access-btn' ) . prop ( 'disabled' , false ) ;
285
-
310
+
286
311
}
287
312
} ) ;
288
313
0 commit comments