onLoading join

pull/1225/head
Vincent 5 years ago
parent b05d2e6725
commit a005aa8a2e

@ -462,7 +462,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return;
}
// Already connected?
if (Boolean(await OpenGroup.getConversation(serverUrl))) {
window.pushToast({
@ -474,15 +473,12 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return;
}
const successPromise = OpenGroup.join(serverUrl);
const timeoutPromise = new Promise((_resolve, reject) =>
// tslint:disable-next-line: no-unnecessary-callback-wrapper no-void-expression
setTimeout(() => reject(), window.CONSTANTS.MAX_CONNECTION_DURATION)
);
// Connect to server
const successPromise = OpenGroup.join(serverUrl, () => {
this.setState({ loading: true });
});
// Connect to server with timeout.
this.setState({ loading: true });
await Promise.race([successPromise, timeoutPromise]).then(() => {
successPromise.then(() => {
this.handleToggleOverlay(undefined);
this.setState({
loading: false,
@ -501,8 +497,8 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
});
window.pushToast({
title: window.i18n('attemptedConnectionTimeout'),
id: 'attemptedConnectionTimeout',
title: window.i18n('connectToServerFail'),
id: 'connectToServerFail',
type: 'error',
});
});

@ -70,7 +70,9 @@ export class OpenGroup {
return new OpenGroup(openGroupParams);
}
public static async join(server: string): Promise<OpenGroup | undefined> {
public static async join(server: string, onLoading?: any): Promise<OpenGroup | undefined> {
// onLoading called when the server begins connecting - after passing every guard
const prefixedServer = OpenGroup.prefixify(server);
if (!OpenGroup.validate(server)) {
return;
@ -94,12 +96,16 @@ export class OpenGroup {
}
}
// Try to connect to server
try {
if (onLoading) {
onLoading();
}
conversation = await window.attemptConnection(prefixedServer, channel);
conversationId = conversation?.cid;
} catch (e) {
console.warn(e);
return;
throw new Error(e);
}
// Do we want to add conversation as a property of OpenGroup?

Loading…
Cancel
Save