2017-05-31 05:32:13 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-01 21:25:48 +00:00
|
|
|
import { toState } from '../redux';
|
|
|
|
|
2017-05-31 05:32:13 +00:00
|
|
|
/**
|
|
|
|
* 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 {
|
2017-09-01 21:25:48 +00:00
|
|
|
const state = toState(stateOrGetState);
|
2017-08-01 00:40:55 +00:00
|
|
|
const locationURL
|
|
|
|
= state instanceof URL
|
|
|
|
? state
|
|
|
|
: state['features/base/connection'].locationURL;
|
2017-05-31 05:32:13 +00:00
|
|
|
|
2017-09-01 21:25:48 +00:00
|
|
|
return locationURL ? getURLWithoutParams(locationURL).href : undefined;
|
2017-05-31 05:32:13 +00:00
|
|
|
}
|
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)) {
|
2017-08-01 00:36:28 +00:00
|
|
|
url = new URL(url.href); // eslint-disable-line no-param-reassign
|
2017-06-01 18:43:57 +00:00
|
|
|
url.hash = '';
|
|
|
|
url.search = '';
|
2017-08-01 00:36:28 +00:00
|
|
|
|
|
|
|
// XXX The implementation of URL at least on React Native appends ? and
|
|
|
|
// # at the end of the href which is not desired.
|
|
|
|
let { href } = url;
|
|
|
|
|
|
|
|
if (href) {
|
|
|
|
href.endsWith('#') && (href = href.substring(0, href.length - 1));
|
|
|
|
href.endsWith('?') && (href = href.substring(0, href.length - 1));
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
url.href === href || (url = new URL(href));
|
|
|
|
}
|
2017-06-01 18:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
2017-09-08 13:36:42 +00:00
|
|
|
|
2018-04-04 09:21:02 +00:00
|
|
|
/**
|
|
|
|
* Gets a URL string 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 {string}
|
|
|
|
*/
|
|
|
|
export function getURLWithoutParamsNormalized(url: URL): string {
|
|
|
|
const urlWithoutParams = getURLWithoutParams(url).href;
|
|
|
|
|
|
|
|
if (urlWithoutParams) {
|
|
|
|
return urlWithoutParams.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:36:42 +00:00
|
|
|
/**
|
2017-09-18 07:09:43 +00:00
|
|
|
* Converts a specific id to jid if it's not jid yet.
|
2017-09-08 13:36:42 +00:00
|
|
|
*
|
|
|
|
* @param {string} id - User id or jid.
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Object} configHosts - The {@code hosts} part of the {@code config}
|
2017-09-18 07:09:43 +00:00
|
|
|
* object.
|
|
|
|
* @returns {string} A string in the form of a JID (i.e.
|
2017-10-01 06:35:19 +00:00
|
|
|
* {@code user@server.com}).
|
2017-09-08 13:36:42 +00:00
|
|
|
*/
|
2017-09-18 07:09:43 +00:00
|
|
|
export function toJid(id: string, { authdomain, domain }: Object): string {
|
|
|
|
return id.indexOf('@') >= 0 ? id : `${id}@${authdomain || domain}`;
|
2017-09-08 13:36:42 +00:00
|
|
|
}
|