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

[BUGFIX] Getting presence on login no longer causes sign-out #89

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mgt-chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const Chat = ({ chatId }: IMgtChatProps) => {
<Error message="No chat id has been provided." subheading={RequireValidChatId}></Error>
)}
{chatState.status === 'error' && (
<Error message="We're sorry—we've run into an issue.." subheading={OpenTeamsLinkError}></Error>
<Error message="We're sorry—we've run into an issue." subheading={OpenTeamsLinkError}></Error>
)}
<div className={styles.chatInput}>
<SendBox disabled={disabled} onSendMessage={chatState.onSendMessage} strings={{ placeholderText }} />
Expand Down
3 changes: 3 additions & 0 deletions packages/mgt-chat/src/components/ChatList/ChatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ export const ChatList = ({
{chatListState?.status === 'server connection lost' && (
<Error message="We ran into a problem. Reconnecting..." subheading={OpenTeamsLinkError}></Error>
)}
{chatListState?.status === 'fatal error' && (
<Error message="We're sorry—we've run into an issue." subheading={OpenTeamsLinkError}></Error>
)}
</div>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ class StatefulGraphChatClient extends BaseStatefulClient<GraphChatClient> {

/**
* Attempts to create the graph and client objects. This can succeed during construction if the
* Provider has already logged in. If not, it will be tried again when the Provider logs in.
* Provider has already logged in. If not, it will be tried again when the Provider logs in. Only
* calling tryCreateGraphNotificationClient() from onLoginStateChanged() only works if the Chat
* component is on the page at the time there is a sign-in - not always a guarantee.
*/
private tryCreateGraphNotificationClient() {
try {
Expand Down
36 changes: 26 additions & 10 deletions packages/mgt-chat/src/statefulClient/StatefulGraphChatListClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,26 @@ class StatefulGraphChatListClient implements StatefulClient<GraphChatListClient>
return;
}

// log
log('loading more chat threads...');

// set promise; load and append
this._loadMorePromise = this.loadAndAppendChatThreads('', [], state.chatThreads.length + this.chatThreadsPerPage);
await this._loadMorePromise;
try {
this._loadMorePromise = this.loadAndAppendChatThreads(
'',
[],
state.chatThreads.length + this.chatThreadsPerPage
);
await this._loadMorePromise;
} catch (e) {
error('Failed to load more chat threads; aborting...', e);
}
} finally {
this._loadMorePromise = undefined;
}

// log
log('successfully loaded more chat threads.');
}

/**
Expand All @@ -275,6 +289,9 @@ class StatefulGraphChatListClient implements StatefulClient<GraphChatListClient>
draft.chatThreads = [];
});

// log
log('loading chat threads...');

// try several times to load more chats
try {
let loaded = false;
Expand All @@ -297,6 +314,9 @@ class StatefulGraphChatListClient implements StatefulClient<GraphChatListClient>
} finally {
this._loadPromise = undefined;
}

// log
log('successfully loaded chat threads.');
}

private async handleChatThreadsResponse(
Expand Down Expand Up @@ -334,14 +354,10 @@ class StatefulGraphChatListClient implements StatefulClient<GraphChatListClient>
return;
}

try {
const response = !nextLink
? await loadChatThreads(this._graph, maxItems > 50 ? 50 : maxItems) // max page count cannot exceed 50 per documentation
: await loadChatThreadsByPage(this._graph, nextLink.split('?')[1]);
await this.handleChatThreadsResponse(response, items, maxItems);
} catch (err) {
error(err);
}
const response = !nextLink
? await loadChatThreads(this._graph, maxItems > 50 ? 50 : maxItems) // max page count cannot exceed 50 per documentation
: await loadChatThreadsByPage(this._graph, nextLink.split('?')[1]);
await this.handleChatThreadsResponse(response, items, maxItems);
}

public clearSelectedChat = () => {
Expand Down
11 changes: 9 additions & 2 deletions packages/providers/mgt-msal2-provider/src/Msal2Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
InteractionRequiredAuthError,
SsoSilentRequest,
EventMessage,
AuthenticationResult
BrowserAuthError,
EventType
} from '@azure/msal-browser';
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client';

Expand Down Expand Up @@ -424,7 +425,7 @@ export class Msal2Provider extends IProvider {
}

private readonly handleMsalEvent = (message: EventMessage): void => {
if (message.eventType === 'msal:acquireTokenSuccess' && 'scopes' in message.payload) {
if (message.eventType === EventType.ACQUIRE_TOKEN_SUCCESS && 'scopes' in message.payload) {
this.approvedScopes = message.payload.scopes;
}
};
Expand Down Expand Up @@ -761,6 +762,12 @@ export class Msal2Provider extends IProvider {
throw popUpErr;
}
}
} else if (e instanceof BrowserAuthError && e.message.indexOf('no_network_connectivity') > -1) {
MattBillFred marked this conversation as resolved.
Show resolved Hide resolved
// don't force a signout; this can maybe be recovered from
throw e;
} else if (e instanceof BrowserAuthError && e.message.indexOf('post_request_failed') > -1) {
// don't force a signout; this can happen if there is a break in network during a call
throw e;
} else {
// if we don't know what the error is, just ask the user to sign in again
this.setState(ProviderState.SignedOut);
Expand Down
Loading