2121
2222/* eslint-disable jsdoc/require-jsdoc */
2323
24- import { getRootUrl , generateFilePath as _generateFilePath } from '@desktop-modules--@nextcloud/router'
24+ import {
25+ getRootUrl as _getRootUrl ,
26+ getAppRootUrl as _getAppRootUrl ,
27+ generateUrl as _generateUrl ,
28+ linkTo as _linkTo ,
29+ generateRemoteUrl as _generateRemoteUrl ,
30+ generateOcsUrl as _generateOcsUrl ,
31+ generateFilePath as _generateFilePath ,
32+ } from '@desktop-modules--@nextcloud/router'
2533
26- export { linkTo , getRootUrl , generateUrl } from '@desktop-modules--@nextcloud/router'
34+ // Original @nextcloud /router sometimes relies on window.location which is not correct on desktop
35+ // So, some function must be re-defined or patched
2736
28- // getBaseUrl added in v3.0.0
29- // On Talk Desktop same as getRootUrl, because getRootUrl is absolute already
30- export const getBaseUrl = getRootUrl
37+ // Works as expected originally, does not use location
38+ export const getRootUrl = _getRootUrl
3139
32- /**
33- * @param {string } s - String with "{token}" blocks
34- * @param {{[token: string]: string} } [tokens] - Dict with replacements
35- * @return {string }
36- */
37- function formattedString ( s , tokens = { } ) {
38- return Object . entries ( tokens ) . reduce ( ( acc , [ token , replacement ] ) => acc . replaceAll ( `{${ token } }` , replacement ) , s )
39- }
40-
41- export function generateOcsUrl ( url , params = { } , options = { } ) {
42- // Reason to patch: it uses window.location
43- const allOptions = { ...options , ocsVersion : 2 }
44- const version = ( allOptions . ocsVersion === 1 ) ? 1 : 2
45- return `${ getRootUrl ( ) } /ocs/v${ version } .php/${ formattedString ( url , params ) } `
46- }
40+ // Works fine originally with enabled absolute webroot
41+ export const getAppRootUrl = ( ...args ) => window . OCA . Talk . Desktop . runWithAbsoluteWebroot ( _getAppRootUrl , ...args )
42+ export const generateUrl = ( ...args ) => window . OCA . Talk . Desktop . runWithAbsoluteWebroot ( _generateUrl , ...args )
43+ export const linkTo = ( ...args ) => window . OCA . Talk . Desktop . runWithAbsoluteWebroot ( _linkTo , ...args )
4744
48- const linkToRemoteBase = ( service ) => getRootUrl ( ) + '/remote.php/' + service
45+ // Original getBaseUrl relies on window.location, create a new one as an absolute version of getRootUrl
46+ export const getBaseUrl = ( ...args ) => window . OCA . Talk . Desktop . runWithAbsoluteWebroot ( _getRootUrl , ...args )
4947
50- export function generateRemoteUrl ( service ) {
51- // Reason to patch: it uses window.location
52- return linkToRemoteBase ( service )
53- }
48+ // Requires changing the default options.baseUrl from original relative getBaseUrl to new absolute getBaseUrl
49+ export const generateRemoteUrl = ( service , options = { } ) => _generateRemoteUrl ( service , { baseURL : getBaseUrl ( ) , ...options } )
50+ export const generateOcsUrl = ( url , params , options = { } ) => _generateOcsUrl ( url , params , { baseURL : getBaseUrl ( ) , ...options } )
5451
52+ // By default, Talk requests images and sounds as a file from server assets using generateFilePath
53+ // Desktop app should use path to the local file in the bundle
5554export function generateFilePath ( app , type , file ) {
56- /**
57- * By default, Talk requests images and sounds as a file from server assets using generateFilePath
58- * Desktop app should use path to the local file in the build
59- */
60-
6155 const filename = file . substring ( 0 , file . lastIndexOf ( '.' ) )
6256 const ext = file . substring ( file . lastIndexOf ( '.' ) )
6357
@@ -77,14 +71,14 @@ export function generateFilePath(app, type, file) {
7771 return requiresByExt [ ext ] ( )
7872 }
7973 } else if ( app === 'notifications' && ext === '.ogg' ) {
80- // For now notifications sounds are just a copy of the notifications app sounds
74+ // For now, notifications' sounds are just a copy of the Notifications app sounds
8175 return require ( `../../../sounds/${ filename } .ogg` )
8276 }
8377
84- return _generateFilePath ( app , type , file )
78+ return window . OCA . Talk . Desktop . runWithAbsoluteWebroot ( ( ) => _generateFilePath ( app , type , file ) )
8579}
8680
87- // Copy of original function, but using patched generateFilePath
81+ // Copy of original but using patched generateFilePath
8882export function imagePath ( app , file ) {
8983 if ( file . indexOf ( '.' ) === - 1 ) {
9084 return generateFilePath ( app , 'img' , file + '.svg' )
0 commit comments