2017-05-31 05:32:13 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a simplified version of the conference/location URL stripped of URL
|
|
|
|
* params (i.e. query/search and hash) which should be used for sending invites.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateOrGetState - The redux state or redux's
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string|undefined}
|
|
|
|
*/
|
|
|
|
export function getInviteURL(stateOrGetState: Function | Object): ?string {
|
|
|
|
const state
|
|
|
|
= typeof stateOrGetState === 'function'
|
|
|
|
? stateOrGetState()
|
|
|
|
: stateOrGetState;
|
|
|
|
const { locationURL } = state['features/base/connection'];
|
|
|
|
let inviteURL;
|
|
|
|
|
|
|
|
if (locationURL) {
|
2017-06-01 18:43:57 +00:00
|
|
|
inviteURL = getURLWithoutParams(locationURL).href;
|
2017-05-31 05:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return inviteURL;
|
|
|
|
}
|
2017-06-01 18:43:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a {@link URL} without hash and query/search params from a specific
|
|
|
|
* {@code URL}.
|
|
|
|
*
|
|
|
|
* @param {URL} url - The {@code URL} which may have hash and query/search
|
|
|
|
* params.
|
|
|
|
* @returns {URL}
|
|
|
|
*/
|
|
|
|
export function getURLWithoutParams(url: URL): URL {
|
|
|
|
const { hash, search } = url;
|
|
|
|
|
|
|
|
if ((hash && hash.length > 1) || (search && search.length > 1)) {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
url = new URL(url.href);
|
|
|
|
url.hash = '';
|
|
|
|
url.search = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|