@microsoft/omnichannel-chat-widget 1.6.2 → 1.6.3-main.e6221d5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -413,4 +413,7 @@ export const formatTemplateString = (templateMessage, values) => {
413
413
  return templateMessage.replace(/{(\d+)}/g, (match, index) => {
414
414
  return typeof values[index] !== "undefined" ? values[index] : match;
415
415
  });
416
+ };
417
+ export const parseLowerCaseString = property => {
418
+ return String(property).toLowerCase();
416
419
  };
@@ -53,6 +53,7 @@ import useChatSDKStore from "../../../hooks/useChatSDKStore";
53
53
  import { defaultAdaptiveCardStyles } from "../../webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles";
54
54
  import StartChatErrorPaneStateful from "../../startchaterrorpanestateful/StartChatErrorPaneStateful";
55
55
  import { StartChatFailureType } from "../../../contexts/common/StartChatFailureType";
56
+ import { executeReducer } from "../../../contexts/createReducer";
56
57
  export const LiveChatWidgetStateful = props => {
57
58
  var _props$webChatContain, _props$styleProps, _props$controlProps, _props$controlProps3, _state$appStates7, _props$webChatContain5, _state$appStates14, _props$webChatContain6, _props$controlProps12, _props$draggableChatW, _props$draggableChatW2, _props$draggableChatW3, _props$draggableChatW4, _props$draggableChatW5, _props$webChatContain7, _props$webChatContain8, _props$webChatContain9, _props$webChatContain10, _livechatProps$webCha, _livechatProps$styleP, _livechatProps$contro, _livechatProps$contro2, _livechatProps$compon, _livechatProps$contro3, _livechatProps$compon2, _livechatProps$contro4, _livechatProps$compon3, _livechatProps$contro5, _livechatProps$compon4, _livechatProps$contro6, _livechatProps$compon5, _livechatProps$contro7, _livechatProps$compon6, _livechatProps$contro8, _livechatProps$compon7, _livechatProps$contro9, _livechatProps$compon8, _livechatProps$contro10, _livechatProps$contro11, _livechatProps$compon9, _livechatProps$contro12, _livechatProps$compon10, _livechatProps$contro13, _livechatProps$compon11, _livechatProps$compon12, _livechatProps$compon13;
58
59
  const [state, dispatch] = useChatContextStore();
@@ -117,8 +118,12 @@ export const LiveChatWidgetStateful = props => {
117
118
  const isReconnectTriggered = async () => {
118
119
  if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
119
120
  const noValidReconnectId = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
121
+ const inMemoryState = executeReducer(state, {
122
+ type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
123
+ payload: null
124
+ });
120
125
  // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
121
- if (!noValidReconnectId && (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat)) {
126
+ if (!noValidReconnectId && (inMemoryState.appStates.conversationState === ConversationState.Active || inMemoryState.appStates.conversationState === ConversationState.ReconnectChat)) {
122
127
  return true;
123
128
  }
124
129
  }
@@ -332,7 +337,7 @@ export const LiveChatWidgetStateful = props => {
332
337
 
333
338
  // Start chat from SDK Event
334
339
  BroadcastService.getMessageByEventName(BroadcastEvent.StartChat).subscribe(msg => {
335
- var _msg$payload4, _msg$payload5, _msg$payload6;
340
+ var _msg$payload4, _msg$payload5, _msg$payload6, _inMemoryState$appSta, _inMemoryState$appSta2, _inMemoryState$appSta3, _inMemoryState$appSta4;
336
341
  // If the startChat event is not initiated by the same tab. Ignore the call
337
342
  if (!isNullOrUndefined(msg === null || msg === void 0 ? void 0 : (_msg$payload4 = msg.payload) === null || _msg$payload4 === void 0 ? void 0 : _msg$payload4.runtimeId) && (msg === null || msg === void 0 ? void 0 : (_msg$payload5 = msg.payload) === null || _msg$payload5 === void 0 ? void 0 : _msg$payload5.runtimeId) !== TelemetryManager.InternalTelemetryData.lcwRuntimeId) {
338
343
  return;
@@ -360,12 +365,13 @@ export const LiveChatWidgetStateful = props => {
360
365
  Event: TelemetryEvent.StartChatEventRecevied,
361
366
  Description: "Start chat event received."
362
367
  });
368
+ const inMemoryState = executeReducer(state, {
369
+ type: LiveChatWidgetActionType.GET_IN_MEMORY_STATE,
370
+ payload: null
371
+ });
363
372
 
364
- // DataStoreManager.clientDataStore?.swtichToSessionStorage(true);
365
- const persistedState = getStateFromCache(getWidgetCacheIdfromProps(props));
366
-
367
- // Chat not found in cache - scenario: explicitly clearing cache and calling startChat SDK method
368
- if (persistedState === undefined) {
373
+ // Only initiate new chat if widget runtime state is one of the followings
374
+ if (((_inMemoryState$appSta = inMemoryState.appStates) === null || _inMemoryState$appSta === void 0 ? void 0 : _inMemoryState$appSta.conversationState) === ConversationState.Closed || ((_inMemoryState$appSta2 = inMemoryState.appStates) === null || _inMemoryState$appSta2 === void 0 ? void 0 : _inMemoryState$appSta2.conversationState) === ConversationState.InActive || ((_inMemoryState$appSta3 = inMemoryState.appStates) === null || _inMemoryState$appSta3 === void 0 ? void 0 : _inMemoryState$appSta3.conversationState) === ConversationState.Postchat) {
369
375
  BroadcastService.postMessage({
370
376
  eventName: BroadcastEvent.ChatInitiated
371
377
  });
@@ -373,33 +379,21 @@ export const LiveChatWidgetStateful = props => {
373
379
  return;
374
380
  }
375
381
 
376
- // Chat exist in cache
377
- if (persistedState) {
378
- var _persistedState$appSt, _persistedState$appSt2, _persistedState$appSt3, _persistedState$appSt4;
379
- // Only initiate new chat if widget state in cache in one of the followings
380
- if (((_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === ConversationState.Closed || ((_persistedState$appSt2 = persistedState.appStates) === null || _persistedState$appSt2 === void 0 ? void 0 : _persistedState$appSt2.conversationState) === ConversationState.InActive || ((_persistedState$appSt3 = persistedState.appStates) === null || _persistedState$appSt3 === void 0 ? void 0 : _persistedState$appSt3.conversationState) === ConversationState.Postchat) {
381
- BroadcastService.postMessage({
382
- eventName: BroadcastEvent.ChatInitiated
383
- });
384
- prepareStartChat(props, chatSDK, stateWithUpdatedContext, dispatch, setAdapter);
385
- return;
386
- }
387
-
388
- // If minimized, maximize the chat
389
- if ((persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt4 = persistedState.appStates) === null || _persistedState$appSt4 === void 0 ? void 0 : _persistedState$appSt4.isMinimized) === true) {
390
- var _persistedState$domai, _persistedState$domai2, _persistedState$domai3, _persistedState$domai4;
391
- dispatch({
392
- type: LiveChatWidgetActionType.SET_MINIMIZED,
393
- payload: false
394
- });
395
- BroadcastService.postMessage({
396
- eventName: BroadcastEvent.MaximizeChat,
397
- payload: {
398
- height: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai = persistedState.domainStates) === null || _persistedState$domai === void 0 ? void 0 : (_persistedState$domai2 = _persistedState$domai.widgetSize) === null || _persistedState$domai2 === void 0 ? void 0 : _persistedState$domai2.height,
399
- width: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai3 = persistedState.domainStates) === null || _persistedState$domai3 === void 0 ? void 0 : (_persistedState$domai4 = _persistedState$domai3.widgetSize) === null || _persistedState$domai4 === void 0 ? void 0 : _persistedState$domai4.width
400
- }
401
- });
402
- }
382
+ // If minimized, maximize the chat
383
+ if ((inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$appSta4 = inMemoryState.appStates) === null || _inMemoryState$appSta4 === void 0 ? void 0 : _inMemoryState$appSta4.isMinimized) === true) {
384
+ var _inMemoryState$domain, _inMemoryState$domain2, _inMemoryState$domain3, _inMemoryState$domain4;
385
+ dispatch({
386
+ type: LiveChatWidgetActionType.SET_MINIMIZED,
387
+ payload: false
388
+ });
389
+ BroadcastService.postMessage({
390
+ eventName: BroadcastEvent.MaximizeChat,
391
+ payload: {
392
+ height: inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$domain = inMemoryState.domainStates) === null || _inMemoryState$domain === void 0 ? void 0 : (_inMemoryState$domain2 = _inMemoryState$domain.widgetSize) === null || _inMemoryState$domain2 === void 0 ? void 0 : _inMemoryState$domain2.height,
393
+ width: inMemoryState === null || inMemoryState === void 0 ? void 0 : (_inMemoryState$domain3 = inMemoryState.domainStates) === null || _inMemoryState$domain3 === void 0 ? void 0 : (_inMemoryState$domain4 = _inMemoryState$domain3.widgetSize) === null || _inMemoryState$domain4 === void 0 ? void 0 : _inMemoryState$domain4.width
394
+ }
395
+ });
396
+ return;
403
397
  }
404
398
  });
405
399
 
@@ -1,3 +1,4 @@
1
+ import { isNullOrUndefined, parseLowerCaseString } from "../../../../common/utils";
1
2
  export const isMaskingforCustomer = maskingInfo => {
2
3
  var _maskingInfo$setting;
3
4
  // If the masking info (containing masking setting and masking rules) is missing or empty, return false.
@@ -8,8 +9,9 @@ export const isMaskingforCustomer = maskingInfo => {
8
9
 
9
10
  // If the masking rules are provided and;
10
11
  // If the masking setting is NOT null and masking for customer is NOT null, return the configuration
11
- if ((_maskingInfo$setting = maskingInfo.setting) !== null && _maskingInfo$setting !== void 0 && _maskingInfo$setting.msdyn_maskforcustomer) {
12
- return maskingInfo.setting.msdyn_maskforcustomer;
12
+ if (!isNullOrUndefined((_maskingInfo$setting = maskingInfo.setting) === null || _maskingInfo$setting === void 0 ? void 0 : _maskingInfo$setting.msdyn_maskforcustomer)) {
13
+ var _maskingInfo$setting2;
14
+ return parseLowerCaseString(maskingInfo === null || maskingInfo === void 0 ? void 0 : (_maskingInfo$setting2 = maskingInfo.setting) === null || _maskingInfo$setting2 === void 0 ? void 0 : _maskingInfo$setting2.msdyn_maskforcustomer) === "true";
13
15
  }
14
16
 
15
17
  // In all other cases, even if masking setting is missing, return true to apply the masking for backward compatibility (i.e. in old versions, OC does not have masking info settings)
@@ -45,4 +45,5 @@ export let LiveChatWidgetActionType;
45
45
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SURVEY_MODE"] = 42] = "SET_SURVEY_MODE";
46
46
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONFIRMATION_STATE"] = 43] = "SET_CONFIRMATION_STATE";
47
47
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_POST_CHAT_PARTICIPANT_TYPE"] = 44] = "SET_POST_CHAT_PARTICIPANT_TYPE";
48
+ LiveChatWidgetActionType[LiveChatWidgetActionType["GET_IN_MEMORY_STATE"] = 45] = "GET_IN_MEMORY_STATE";
48
49
  })(LiveChatWidgetActionType || (LiveChatWidgetActionType = {}));