Chatwoot/app/javascript/widget/helpers/utils.js
Sojan Jose f71980bd95
chore: Enhance contact merge action for identified users (#4886)
- Discard conflicting keys 
- Do not merge if there is already an identified contact

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2022-06-23 15:48:56 +05:30

38 lines
999 B
JavaScript
Executable file

import { WOOT_PREFIX } from './constants';
export const isEmptyObject = obj =>
Object.keys(obj).length === 0 && obj.constructor === Object;
export const arrayToHashById = array =>
array.reduce((map, obj) => {
const newMap = map;
newMap[obj.id] = obj;
return newMap;
}, {});
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';
const isAValidWootEvent =
isDataAString && e.data.indexOf(WOOT_PREFIX) === 0;
return isAValidWootEvent;
},
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 })}`
);
},
};