Pass URL to check.

pull/21833/head
Richard Lewis 2017-11-02 17:27:59 +00:00
parent 17c0405862
commit a52bb9d603
1 changed files with 12 additions and 4 deletions

View File

@ -82,15 +82,23 @@ export default React.createClass({
return this._getNewUrlState(this.props);
},
// Returns true if props.url is a scalar URL, typically https://scalar.vector.im/api
isScalarUrl() {
/**
* Returns true if specified url is a scalar URL, typically https://scalar.vector.im/api
* @param {[type]} url URL to check
* @return {Boolean} True if specified URL is a scalar URL
*/
isScalarUrl(url) {
if (!url) {
return false;
}
let scalarUrls = SdkConfig.get().integrations_widgets_urls;
if (!scalarUrls || scalarUrls.length == 0) {
scalarUrls = [SdkConfig.get().integrations_rest_url];
}
for (let i = 0; i < scalarUrls.length; i++) {
if (this.props.url.startsWith(scalarUrls[i])) {
if (url.startsWith(scalarUrls[i])) {
return true;
}
}
@ -122,7 +130,7 @@ export default React.createClass({
// Adds a scalar token to the widget URL, if required
setScalarToken() {
if (!this.isScalarUrl()) {
if (!this.isScalarUrl(this.props.url)) {
return;
}
// Fetch the token before loading the iframe as we need to mangle the URL