pull/1225/head
Vincent 5 years ago
parent 3bc7d95d47
commit 3a3d412542

@ -7,7 +7,6 @@ import {
} from './session/settings/SessionSettings';
export const MainViewController = {
joinChannelStateManager,
createClosedGroup,
renderMessageView,
renderSettingsView,
@ -40,71 +39,6 @@ export class MessageView extends React.Component {
// //////////// Management /////////////
// /////////////////////////////////////
function joinChannelStateManager(
thisRef: any,
serverURL: string,
onSuccess?: any
) {
// Any component that uses this function MUST have the keys [loading, connectSuccess]
// in their State
// TODO: Make this not hard coded
const channelId = 1;
thisRef.setState({ loading: true });
const connectionResult = window.attemptConnection(serverURL, channelId);
// Give 5s maximum for promise to revole. Else, throw error.
const connectionTimeout = setTimeout(() => {
if (!thisRef.state.connectSuccess) {
thisRef.setState({ loading: false });
window.pushToast({
title: window.i18n('connectToServerFail'),
type: 'error',
id: 'connectToServerFail',
});
return;
}
}, window.CONSTANTS.MAX_CONNECTION_DURATION);
connectionResult
.then(() => {
clearTimeout(connectionTimeout);
if (thisRef.state.loading) {
thisRef.setState({
connectSuccess: true,
loading: false,
});
window.pushToast({
title: window.i18n('connectToServerSuccess'),
id: 'connectToServerSuccess',
type: 'success',
});
if (onSuccess) {
onSuccess();
}
}
})
.catch((connectionError: string) => {
clearTimeout(connectionTimeout);
thisRef.setState({
connectSuccess: true,
loading: false,
});
window.pushToast({
title: connectionError,
id: 'connectToServerFail',
type: 'error',
});
return false;
});
return true;
}
async function createClosedGroup(
groupName: string,
groupMembers: Array<ContactType>,

@ -483,26 +483,28 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
type: 'success',
});
this.setState({loading: true});
this.setState({ loading: true });
}
});
successPromise.then(() => {
this.handleToggleOverlay(undefined);
this.setState({
loading: false,
});
}).catch(() => {
this.setState({
loading: false,
});
successPromise
.then(() => {
this.handleToggleOverlay(undefined);
this.setState({
loading: false,
});
})
.catch(() => {
this.setState({
loading: false,
});
window.pushToast({
title: window.i18n('connectToServerFail'),
id: 'connectToServerFail',
type: 'error',
window.pushToast({
title: window.i18n('connectToServerFail'),
id: 'connectToServerFail',
type: 'error',
});
});
});
}
private async onCreateClosedGroup(

@ -70,7 +70,10 @@ export class OpenGroup {
return new OpenGroup(openGroupParams);
}
public static async join(server: string, onLoading?: any): 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);
@ -122,7 +125,9 @@ export class OpenGroup {
}
const prefixedServer = this.prefixify(server);
const serverInfo = await window.lokiPublicChatAPI.findOrCreateServer(prefixedServer) as any;
const serverInfo = (await window.lokiPublicChatAPI.findOrCreateServer(
prefixedServer
)) as any;
if (!serverInfo?.channels?.length) {
return;
@ -137,7 +142,9 @@ export class OpenGroup {
}
const prefixedServer = this.prefixify(server);
return Boolean(await window.lokiPublicChatAPI.findOrCreateServer(prefixedServer));
return Boolean(
await window.lokiPublicChatAPI.findOrCreateServer(prefixedServer)
);
}
public static getConversationByCID(conversationId: string): any {
@ -145,7 +152,10 @@ export class OpenGroup {
return ConversationController.get(conversationId);
}
private static getServer(groupId: string, hasSSL: boolean): string | undefined {
private static getServer(
groupId: string,
hasSSL: boolean
): string | undefined {
const isValid = this.groupIdRegex.test(groupId);
const strippedServer = isValid ? groupId.split('@')[1] : undefined;
@ -174,7 +184,7 @@ export class OpenGroup {
private static prefixify(server: string, hasSSL: boolean = true): string {
// Prefix server with https:// if it's not already prefixed with http or https.
const hasPrefix = server.match('^https?:\/\/');
const hasPrefix = server.match('^https?://');
if (hasPrefix) {
return server;
}

@ -121,7 +121,10 @@ export const _getLeftPaneLists = (
}
// Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
if (
conversation.isPublic &&
(!conversation.name || conversation.name === 'Unknown group')
) {
continue;
}

Loading…
Cancel
Save