33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import { defineAsyncComponent } from 'vue'
76import { getBuilder } from '@nextcloud/browser-storage'
8- import { getGuestNickname , setGuestNickname } from '@nextcloud/auth'
7+ import { getGuestNickname , getGuestUser } from '@nextcloud/auth'
98import { getUploader } from '@nextcloud/upload'
10- import { spawnDialog } from '@nextcloud/dialogs'
9+ import { loadState } from '@nextcloud/initial-state'
10+ import { showGuestUserPrompt } from '@nextcloud/dialogs'
11+ import { t } from '@nextcloud/l10n'
1112
1213import logger from './services/logger'
14+ import { subscribe } from '@nextcloud/event-bus'
1315
1416const storage = getBuilder ( 'files_sharing' ) . build ( )
1517
@@ -25,31 +27,47 @@ function registerFileRequestHeader(nickname: string) {
2527
2628/**
2729 * Callback when a nickname was chosen
28- * @param nickname The chosen nickname
2930 */
30- function onSetNickname ( nickname : string ) : void {
31- // Set the nickname
32- setGuestNickname ( nickname )
33- // Set the dialog as shown
34- storage . setItem ( 'public-auth-prompt-shown' , 'true' )
31+ function onUpdatedNickname ( ) : void {
3532 // Register header for uploader
36- registerFileRequestHeader ( nickname )
33+ registerFileRequestHeader ( getGuestUser ( ) . displayName ?? '' )
3734}
35+ subscribe ( 'user:info:changed' , onUpdatedNickname )
3836
3937window . addEventListener ( 'DOMContentLoaded' , ( ) => {
4038 const nickname = getGuestNickname ( ) ?? ''
4139 const dialogShown = storage . getItem ( 'public-auth-prompt-shown' ) !== null
4240
41+ const owner = loadState ( 'files_sharing' , 'owner' , '' )
42+ const ownerDisplayName = loadState ( 'files_sharing' , 'ownerDisplayName' , '' )
43+ const label = loadState ( 'files_sharing' , 'label' , '' )
44+ const filename = loadState ( 'files_sharing' , 'filename' , '' )
45+
46+ // If the owner provided a custom label, use it instead of the filename
47+ const folder = label || filename
48+
49+ const options = {
50+ nickname,
51+ notice : t ( 'files_sharing' , 'To upload files to {folder}, you need to provide your name first.' , { folder } ) ,
52+ subtitle : undefined as string | undefined ,
53+ title : t ( 'files_sharing' , 'Upload files to {folder}' , { folder } ) ,
54+ }
55+
56+ // If the guest already has a nickname, we just make them double check
57+ if ( nickname ) {
58+ options . notice = t ( 'files_sharing' , 'Please confirm your name to upload files to {folder}' , { folder } )
59+ }
60+
61+ // If the account owner set their name as public,
62+ // we show it in the subtitle
63+ if ( owner ) {
64+ options . subtitle = t ( 'files_sharing' , '{ownerDisplayName} shared a folder with you.' , { ownerDisplayName } )
65+ }
66+
4367 // If we don't have a nickname or the public auth prompt hasn't been shown yet, show it
4468 // We still show the prompt if the user has a nickname to double check
4569 if ( ! nickname || ! dialogShown ) {
46- spawnDialog (
47- defineAsyncComponent ( ( ) => import ( './views/PublicAuthPrompt.vue' ) ) ,
48- {
49- nickname,
50- } ,
51- onSetNickname as ( ...rest : unknown [ ] ) => void ,
52- )
70+ showGuestUserPrompt ( options )
5371 } else {
5472 logger . debug ( 'Public auth prompt already shown.' , { nickname } )
5573 registerFileRequestHeader ( nickname )
0 commit comments