-
Notifications
You must be signed in to change notification settings - Fork 78
Fix unread chat messages badge on the CallWithChatComposite being cleared when the call goes on hold #3332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JamesBurnside
merged 5 commits into
main
from
jaburnsi/maintain-unread-messages-when-on-hold
Jul 17, 2023
Merged
Fix unread chat messages badge on the CallWithChatComposite being cleared when the call goes on hold #3332
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba6c0e7
Move unread messages tracking in callwithchatcomposite to the composi…
JamesBurnside 8e38eb6
Change files
JamesBurnside 4ddaec5
Duplicate change files for beta release
JamesBurnside 1edb77d
do not show badge count on hold
JamesBurnside 615fe62
Merge branch 'main' into jaburnsi/maintain-unread-messages-when-on-hold
JamesBurnside File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change-beta/@azure-communication-react-ff67bea7-5ec4-4ff7-851c-b829cebc71cc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Fix unread chat messages badge on the CallWithChatComposite being cleared when the call goes on hold", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@azure-communication-react-ff67bea7-5ec4-4ff7-851c-b829cebc71cc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "Fix unread chat messages badge on the CallWithChatComposite being cleared when the call goes on hold", | ||
| "packageName": "@azure/communication-react", | ||
| "email": "2684369+JamesBurnside@users.noreply.github.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ct-composites/src/composites/CallWithChatComposite/ChatButton/useUnreadMessagesTracker.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { useEffect, useState } from 'react'; | ||
| import { ChatAdapter } from '../../ChatComposite/adapter/ChatAdapter'; | ||
| import { ChatMessage } from '@azure/communication-chat'; | ||
|
|
||
| /** | ||
| * Used by the CallWithChatComposite to track unread messages for showing as a badge on the Chat Button. | ||
| * @private | ||
| */ | ||
| export const useUnreadMessagesTracker = (chatAdapter: ChatAdapter, isChatPaneVisible: boolean): number => { | ||
| const [unreadChatMessagesCount, setUnreadChatMessagesCount] = useState<number>(0); | ||
|
|
||
| useEffect(() => { | ||
| if (isChatPaneVisible) { | ||
| setUnreadChatMessagesCount(0); | ||
| return; | ||
| } | ||
| const incrementUnreadChatMessagesCount = (event: { message: ChatMessage }): void => { | ||
| if (!isChatPaneVisible && validNewChatMessage(event.message)) { | ||
| setUnreadChatMessagesCount(unreadChatMessagesCount + 1); | ||
| } | ||
| }; | ||
| chatAdapter.on('messageReceived', incrementUnreadChatMessagesCount); | ||
|
|
||
| return () => { | ||
| chatAdapter.off('messageReceived', incrementUnreadChatMessagesCount); | ||
| }; | ||
| }, [chatAdapter, setUnreadChatMessagesCount, isChatPaneVisible, unreadChatMessagesCount]); | ||
|
|
||
| return unreadChatMessagesCount; | ||
| }; | ||
|
|
||
| /** | ||
| * Helper function to determine if the message in the event is a valid one from a user. | ||
| * Display name is used since system messages will not have one. | ||
| */ | ||
| const validNewChatMessage = (message): boolean => | ||
| !!message.senderDisplayName && (message.type === 'text' || message.type === 'html'); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Would this break with CTE users that have unnamed participant? (Due to cte bug and no graph integration with calling sdk yet).
cc @PorterNan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great spot! I won't change in this PR as this function was just moved but I think you're right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed a bug https://skype.visualstudio.com/SPOOL/_workitems/edit/3342861