2017-10-03 19:24:00 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-06-14 18:41:22 +00:00
|
|
|
declare var $: Function;
|
2017-10-03 16:30:42 +00:00
|
|
|
declare var interfaceConfig: Object;
|
2017-06-14 18:41:22 +00:00
|
|
|
|
|
|
|
/**
|
2017-10-03 19:24:00 +00:00
|
|
|
* Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
|
|
|
|
* list.
|
2017-06-14 18:41:22 +00:00
|
|
|
*
|
2017-10-03 19:24:00 +00:00
|
|
|
* @param {string} name - The invite option name.
|
|
|
|
* @private
|
|
|
|
* @returns {number} - The position of the option in the list.
|
2017-06-14 18:41:22 +00:00
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function getInviteOptionPosition(name: string): number {
|
|
|
|
return interfaceConfig.INVITE_OPTIONS.indexOf(name);
|
2017-06-14 18:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a post request to an invite service.
|
|
|
|
*
|
|
|
|
* @param {string} inviteServiceUrl - The invite service that generates the
|
|
|
|
* invitation.
|
|
|
|
* @param {string} inviteUrl - The url to the conference.
|
|
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
2017-11-21 22:45:14 +00:00
|
|
|
* @param {Immutable.List} inviteItems - The list of the "user" or "room"
|
|
|
|
* type items to invite.
|
2017-06-14 18:41:22 +00:00
|
|
|
* @returns {Promise} - The promise created by the request.
|
|
|
|
*/
|
2017-11-21 22:45:14 +00:00
|
|
|
export function invitePeopleAndChatRooms( // eslint-disable-line max-params
|
2017-10-03 19:24:00 +00:00
|
|
|
inviteServiceUrl: string,
|
|
|
|
inviteUrl: string,
|
|
|
|
jwt: string,
|
2017-12-01 21:07:58 +00:00
|
|
|
inviteItems: Object): Promise<void> {
|
2017-11-21 22:45:14 +00:00
|
|
|
if (!inviteItems || inviteItems.length === 0) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2017-06-14 18:41:22 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-10-03 19:24:00 +00:00
|
|
|
$.post(
|
|
|
|
`${inviteServiceUrl}?token=${jwt}`,
|
|
|
|
JSON.stringify({
|
2017-11-21 22:45:14 +00:00
|
|
|
'invited': inviteItems,
|
2017-10-03 19:24:00 +00:00
|
|
|
'url': inviteUrl
|
|
|
|
}),
|
|
|
|
resolve,
|
|
|
|
'json')
|
|
|
|
.fail((jqxhr, textStatus, error) => reject(error));
|
2017-06-14 18:41:22 +00:00
|
|
|
});
|
|
|
|
}
|
2017-09-21 20:24:56 +00:00
|
|
|
|
2017-10-03 16:30:42 +00:00
|
|
|
/**
|
|
|
|
* Indicates if an invite option is enabled in the configuration.
|
|
|
|
*
|
|
|
|
* @param {string} name - The name of the option defined in
|
|
|
|
* interfaceConfig.INVITE_OPTIONS.
|
|
|
|
* @returns {boolean} - True to indicate that the given invite option is
|
|
|
|
* enabled, false - otherwise.
|
|
|
|
*/
|
2017-10-03 19:24:00 +00:00
|
|
|
export function isInviteOptionEnabled(name: string) {
|
|
|
|
return getInviteOptionPosition(name) !== -1;
|
2017-10-03 16:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-03 19:24:00 +00:00
|
|
|
* Sends an ajax request to a directory service.
|
2017-10-03 16:30:42 +00:00
|
|
|
*
|
2017-10-03 19:24:00 +00:00
|
|
|
* @param {string} serviceUrl - The service to query.
|
|
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
|
|
|
* @param {string} text - Text to search.
|
|
|
|
* @param {Array<string>} queryTypes - Array with the query types that will be
|
|
|
|
* executed - "conferenceRooms" | "user" | "room".
|
|
|
|
* @returns {Promise} - The promise created by the request.
|
2017-10-03 16:30:42 +00:00
|
|
|
*/
|
2017-11-21 22:45:14 +00:00
|
|
|
export function searchDirectory( // eslint-disable-line max-params
|
2017-10-03 19:24:00 +00:00
|
|
|
serviceUrl: string,
|
|
|
|
jwt: string,
|
|
|
|
text: string,
|
2017-12-01 21:07:58 +00:00
|
|
|
queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
|
|
|
|
): Promise<void> {
|
2017-10-03 19:24:00 +00:00
|
|
|
const queryTypesString = JSON.stringify(queryTypes);
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
$.getJSON(
|
|
|
|
`${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
|
|
|
|
queryTypesString}&jwt=${jwt}`,
|
|
|
|
resolve)
|
|
|
|
.fail((jqxhr, textStatus, error) => reject(error));
|
|
|
|
});
|
2017-10-03 16:30:42 +00:00
|
|
|
}
|