Restructure omni services and add Chatwoot research snapshot
This commit is contained in:
38
research/chatwoot/app/javascript/widget/helpers/utils.js
Executable file
38
research/chatwoot/app/javascript/widget/helpers/utils.js
Executable file
@@ -0,0 +1,38 @@
|
||||
import { WOOT_PREFIX } from './constants';
|
||||
|
||||
export const isEmptyObject = obj => {
|
||||
if (!obj) return true;
|
||||
return Object.keys(obj).length === 0 && obj.constructor === Object;
|
||||
};
|
||||
|
||||
export const sendMessage = msg => {
|
||||
window.parent.postMessage(
|
||||
`chatwoot-widget:${JSON.stringify({ ...msg })}`,
|
||||
'*'
|
||||
);
|
||||
};
|
||||
|
||||
export const IFrameHelper = {
|
||||
isIFrame: () => window.self !== window.top,
|
||||
sendMessage,
|
||||
isAValidEvent: e => {
|
||||
const isDataAString = typeof e.data === 'string';
|
||||
return isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
|
||||
},
|
||||
getMessage: e => JSON.parse(e.data.replace(WOOT_PREFIX, '')),
|
||||
};
|
||||
export const RNHelper = {
|
||||
isRNWebView: () => window.ReactNativeWebView,
|
||||
sendMessage: msg => {
|
||||
window.ReactNativeWebView.postMessage(
|
||||
`chatwoot-widget:${JSON.stringify({ ...msg })}`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const groupBy = (array, predicate) => {
|
||||
return array.reduce((acc, value) => {
|
||||
(acc[predicate(value)] ||= []).push(value);
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
Reference in New Issue
Block a user