Skip to content
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

Connect to chat only after call is connected #4716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rzdor
Copy link
Contributor

@rzdor rzdor commented Jun 7, 2024

What

Fix bug when user joined chat before call and message about join appears first.
I've added call to join chat only after call is connected.
Updated ChatAdapter to wait when user joined thread for operations.

Why

How Tested

Process & policy checklist

  • I have updated the project documentation to reflect my changes if necessary.
  • I have read the CONTRIBUTING documentation.

Is this a breaking change?

  • This change causes current functionality to break.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Calling bundle size is not changed.

  • Current size: 5014620
  • Base size: 5014620
  • Diff size: 0

Copy link
Contributor

github-actions bot commented Jun 7, 2024

CallWithChat bundle size is increased❗.

  • Current size: 6343217
  • Base size: 6342524
  • Diff size: 693

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Chat bundle size is increased❗.

  • Current size: 2067255
  • Base size: 2066796
  • Diff size: 459

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Failed to pass the Static HTML UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Failed to pass the UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

Failed to pass the UI Test. If this PR is for UI change and the error is snapshot mismatch, please add "update_snapshots" label to the PR for updating the snapshot.

Copy link
Member

@JamesBurnside JamesBurnside left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the callWithChatAdapter to automatically join the chat thread once the call goes into the connected state? I see that its Contoso's call to the server we need to time calling the function appropriately.
I like your fix - perhaps we can remove the polling however?
We should probably have a feature in the backlog where we callback to Contoso to tell them when they should be triggering their join, but that can be a future feature

if (threads.value.filter((thread: ChatThreadItem) => thread.id === this.chatThreadClient.threadId).length > 0) {
this.hasAcceccToThread = true;
} else {
setTimeout(check, 500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use polling. Instead just error if we try to run functions without access yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything break if we don't poll?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove the polling, we would have to have the CallWithChatComposite have some form of "retry" if the chat is opened before the user has connected.
Potentially this could be automatic (so in essence the same as polling).
Or we could have a retry button.
Or a combination of both.

E.g., a potential solution could look like:

  • User joins call.
  • User clicks chat button, sees error "You are not part of this chat thread" and a "Retry" button.
  • Clicking retry shows a spinner, then shows the error again.
  • At some point Contoso then adds the user to the chat thread in the backend.
    • Ideally this would be done as early as possible to prevent the user ever seeing an error.
  • Now if the user hits the retry button, or closes and reopens the chat it will load the chat successfully.

However, better would be if the CallWithChatComposite could subscribe to some heartbeat to automatically reload the chat when the user is added to the thread. This would need discussed with the Chat team.


/* send add participant request to chat only after call is connected */
const joinThreadWhenCallConnected = async (): Promise<void> => {
if (adapter.getState().call?.state === 'Connected' && locator && 'chatThreadId' in locator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we join in the "connecting" state? Just as an optimization that it's joined once the user lands in the call

private async asyncTeeErrorToEventEmitter<T>(f: () => Promise<T>): Promise<T> {
try {
return await f();
return await this.executeWithThreadAccess(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is more for event emitter - it does not align with function name to add this function here, maybe we can do this in a separated function?

Copy link
Member

@PorterNan PorterNan Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure we can wrap the function for another time - but maybe extract what we have and make function for this


private checkIsUserJoinedThread(): void {
const check = (): void => {
const threads = this.chatClient.listChatThreads({ maxPageSize: 100 }).byPage().next();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is getThread or getChatThreadClient(id) function in the chatClient, let's not use iterator to make it slow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants