Lyubo Marinov 4bf19d73fd [RN] Fix documentation comments
* Javadoc introduced @code as a replacement of <code> and <tt> which is
  better aligned with other javadoc tags such as @link. Use it in the
  Java source code. If we switch to Kotlin, then we'll definitely use
  Markdown.

* There are more uses of @code in the JavaScript source code than <tt>
  so use @code for the sake of consistency. Eventually, I'd rather we
  switch to Markdown because it's easier on my eyes.

* Xcode is plain confused by @code and @link. The Internet says that
  Xcode supports the backquote character to denote the beginning and end
  of a string of characters which should be formatted for display as
  code but it doesn't work for me. <tt> is not rendered at all. So use
  the backquote which is rendered itself. Hopefully, if we switch to
  Markdown, then it'll be common between JavaScript and Objective-C
  source code.
2017-10-01 01:35:19 -05:00

67 lines
2.1 KiB
JavaScript

/* @flow */
import { toState } from '../redux';
/**
* 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 = toState(stateOrGetState);
const locationURL
= state instanceof URL
? state
: state['features/base/connection'].locationURL;
return locationURL ? getURLWithoutParams(locationURL).href : undefined;
}
/**
* 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)) {
url = new URL(url.href); // eslint-disable-line no-param-reassign
url.hash = '';
url.search = '';
// 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));
}
}
return url;
}
/**
* Converts a specific id to jid if it's not jid yet.
*
* @param {string} id - User id or jid.
* @param {Object} configHosts - The {@code hosts} part of the {@code config}
* object.
* @returns {string} A string in the form of a JID (i.e.
* {@code user@server.com}).
*/
export function toJid(id: string, { authdomain, domain }: Object): string {
return id.indexOf('@') >= 0 ? id : `${id}@${authdomain || domain}`;
}