Skip to content

Commit 1523510

Browse files
authored
Merge pull request #88 from Cognigy/91476/bug-unread-messages-indicator
Fix "Unread Messages" Indicator
2 parents a3f10e8 + 0cf8185 commit 1523510

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/webchat/store/ui/ui-middleware.ts

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ShowChatScreenAction,
88
SetPageVisibleAction,
99
SetHasAcceptedTermsAction,
10+
SetOpenAction,
1011
} from "./ui-reducer";
1112
import { getStorage } from "../../helper/storage";
1213
import { setHasAcceptedTermsInStorage } from "../../helper/privacyPolicy";
@@ -17,6 +18,7 @@ export const uiMiddleware: Middleware<object, StoreState> =
1718
(
1819
action:
1920
| ToggleOpenAction
21+
| SetOpenAction
2022
| ShowChatScreenAction
2123
| SetPageVisibleAction
2224
| SetHasAcceptedTermsAction,
@@ -34,6 +36,23 @@ export const uiMiddleware: Middleware<object, StoreState> =
3436
break;
3537
}
3638

39+
case "SET_OPEN": {
40+
const { open } = action;
41+
42+
// We determine if the chat history is visible by other screens visibility.
43+
const { showHomeScreen, showPrevConversations, showChatOptionsScreen } =
44+
store.getState().ui;
45+
46+
const isChatHistoryVisible =
47+
!showPrevConversations && !showChatOptionsScreen && !showHomeScreen;
48+
49+
if (open && isChatHistoryVisible) {
50+
store.dispatch(clearUnseenMessages());
51+
}
52+
53+
break;
54+
}
55+
3756
// if the chat screen is opened while the page is active, reset unread messages
3857
case "SHOW_CHAT_SCREEN": {
3958
if (store.getState().ui.isPageVisible) {

0 commit comments

Comments
 (0)