Skip to content

Commit

Permalink
refactor: reorganize some code
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
  • Loading branch information
elzody committed Apr 24, 2024
1 parent 4b3b2eb commit b44cb56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/Listener/ShareLinkListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(Event $event): void {
$this->initialStateService->provideCapabilities();
Util::addScript('richdocuments', 'richdocuments-files');
Util::addScript('richdocuments', 'richdocuments-viewer', 'viewer');
Util::addScript('richdocuments', 'richdocuments-public');
Util::addScript('richdocuments', 'richdocuments-public', 'viewer');
}
}
}
35 changes: 8 additions & 27 deletions src/helpers/guestName.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,12 @@

import { getCurrentUser } from '@nextcloud/auth'

let guestName = ''

const getGuestNameCookie = function() {
if (guestName === '') {
const name = 'guestUser='
const matchedCookie = document.cookie.split(';')
.map((cookie) => {
try {
return decodeURIComponent(cookie.trim())
} catch (e) {
return cookie.trim()
}
}).find((cookie) => {
return cookie.indexOf(name) === 0
})
guestName = matchedCookie ? matchedCookie.substring(name.length) : ''
}
return guestName
const cookieAlreadySet = (cookieName) => {
return document.cookie
.split(';')
.some(cookie => {
return cookie.trim().startsWith(`${cookieName}=`)
})
}

const setGuestName = function(username) {
Expand All @@ -49,20 +37,13 @@ const setGuestName = function(username) {
}

const shouldAskForGuestName = () => {
const noGuestCookie = !cookieAlreadySet('guestUser')
const noCurrentUser = !getCurrentUser() || getCurrentUser()?.uid === ''
const cookieAlreadySet = () => {
return document.cookie
.split(';')
.some(cookie => {
return cookie.trim().startsWith('guestUser=')
})
}

return noCurrentUser && !cookieAlreadySet()
return noCurrentUser && noGuestCookie
}

export {
getGuestNameCookie,
setGuestName,
shouldAskForGuestName,
}

0 comments on commit b44cb56

Please sign in to comment.