Skip to content
Snippets Groups Projects
Commit fd7b9b38 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento Committed by GitHub
Browse files

Iframe change status (#4741)

* Move iframe commands to new file

* Restructure iframeCommands file

* Add option to `set-user-status` from iframe
parent c6a3ead0
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@
},
"core-util-is": {
"version": "1.0.2",
"resolved": "http://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"from": "core-util-is@>=1.0.0 <1.1.0"
},
"css-select": {
......
......@@ -8,47 +8,3 @@ window.fireGlobalEvent = (eventName, params) => {
}, RocketChat.settings.get('Iframe_Integration_send_target_origin'));
}
};
window.addEventListener('message', (e) => {
if (RocketChat.settings.get('Iframe_Integration_receive_enable') !== true) {
return;
}
if (typeof e.data !== 'object' || typeof e.data.externalCommand !== 'string') {
return;
}
let origins = RocketChat.settings.get('Iframe_Integration_receive_origin');
if (origins !== '*' && origins.split(',').indexOf(e.origin) === -1) {
return console.error('Origin not allowed', e.origin);
}
switch (e.data.externalCommand) {
case 'go':
if (typeof e.data.path !== 'string' || e.data.path.trim().length === 0) {
return console.error('`path` not defined');
}
FlowRouter.go(e.data.path);
break;
case 'call-custom-oauth-login':
const customOAuthCallback = (response) => {
e.source.postMessage({
event: 'custom-oauth-callback',
response: response
}, e.origin);
};
if (typeof e.data.service === 'string') {
const customOauth = ServiceConfiguration.configurations.findOne({service: e.data.service});
if (customOauth) {
const customLoginWith = Meteor['loginWith' + _.capitalize(customOauth.service, true)];
const customRedirectUri = window.OAuth._redirectUri(customOauth.service, customOauth);
customLoginWith.call(Meteor, {'redirectUrl': customRedirectUri}, customOAuthCallback);
}
}
break;
}
});
const commands = {
go(data) {
if (typeof data.path !== 'string' || data.path.trim().length === 0) {
return console.error('`path` not defined');
}
FlowRouter.go(data.path);
},
'set-user-status'(data) {
AccountBox.setStatus(data.status);
},
'call-custom-oauth-login'(data, event) {
const customOAuthCallback = (response) => {
event.source.postMessage({
event: 'custom-oauth-callback',
response: response
}, event.origin);
};
if (typeof data.service === 'string') {
const customOauth = ServiceConfiguration.configurations.findOne({service: data.service});
if (customOauth) {
const customLoginWith = Meteor['loginWith' + _.capitalize(customOauth.service, true)];
const customRedirectUri = window.OAuth._redirectUri(customOauth.service, customOauth);
customLoginWith.call(Meteor, {'redirectUrl': customRedirectUri}, customOAuthCallback);
}
}
}
};
window.addEventListener('message', (e) => {
if (RocketChat.settings.get('Iframe_Integration_receive_enable') !== true) {
return;
}
if (typeof e.data !== 'object' || typeof e.data.externalCommand !== 'string') {
return;
}
let origins = RocketChat.settings.get('Iframe_Integration_receive_origin');
if (origins !== '*' && origins.split(',').indexOf(e.origin) === -1) {
return console.error('Origin not allowed', e.origin);
}
const command = commands[e.data.externalCommand];
if (command) {
command(e.data, e);
}
});
......@@ -39,6 +39,7 @@ Package.onUse(function(api) {
api.addFiles('lib/customEventPolyfill.js', 'client');
api.addFiles('lib/fileUpload.coffee', 'client');
api.addFiles('lib/fireEvent.js', 'client');
api.addFiles('lib/iframeCommands.js', 'client');
api.addFiles('lib/jquery.swipebox.min.js', 'client');
api.addFiles('lib/menu.coffee', 'client');
api.addFiles('lib/modal.coffee', 'client');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment