mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-01 03:27:52 +00:00 
			
		
		
		
	 42f6621afb
			
		
	
	42f6621afb
	
	
	
		
			
			Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
		
			
				
	
	
		
			39 lines
		
	
	
		
			995 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			995 B
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
| 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;
 | |
|   }, {});
 | |
| };
 |