New Chat: Fix freezing when users disable adding them to groups (#1552)

This commit is contained in:
Alexander Zinchuk 2021-11-19 03:22:30 +03:00
parent 5d3ceb9e64
commit 7ea9dd116f
3 changed files with 45 additions and 20 deletions

View File

@ -567,7 +567,7 @@ export async function createGroupChat({
const result = await invokeRequest(new GramJs.messages.CreateChat({ const result = await invokeRequest(new GramJs.messages.CreateChat({
title, title,
users: users.map(({ id, accessHash }) => buildInputEntity(id, accessHash)) as GramJs.InputUser[], users: users.map(({ id, accessHash }) => buildInputEntity(id, accessHash)) as GramJs.InputUser[],
}), true); }), true, true);
// `createChat` can return a lot of different update types according to docs, // `createChat` can return a lot of different update types according to docs,
// but currently chat creation returns only `Updates` type. // but currently chat creation returns only `Updates` type.

View File

@ -113,7 +113,7 @@ const NewChatStep2: FC<OwnProps & StateProps & DispatchProps> = ({
} }
}, [creationProgress, onReset]); }, [creationProgress, onReset]);
const renderedError = creationError || ( const renderedError = (creationError && lang(creationError)) || (
error !== chatTitleEmptyError && error !== channelTitleEmptyError error !== chatTitleEmptyError && error !== channelTitleEmptyError
? error ? error
: undefined : undefined

View File

@ -1088,7 +1088,12 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) {
}, },
}); });
const createdChat = await callApi('createGroupChat', { title, users }); try {
const createdChat = await callApi('createGroupChat', {
title,
users,
});
if (!createdChat) { if (!createdChat) {
return; return;
} }
@ -1105,10 +1110,30 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) {
}, },
}; };
setGlobal(global); setGlobal(global);
getDispatch().openChat({ id: chatId, shouldReplaceHistory: true }); getDispatch()
.openChat({
id: chatId,
shouldReplaceHistory: true,
});
if (chatId && photo) { if (chatId && photo) {
await callApi('editChatPhoto', { chatId, photo }); await callApi('editChatPhoto', {
chatId,
photo,
});
}
} catch (e) {
if (e.message === 'USERS_TOO_FEW') {
const global = getGlobal();
setGlobal({
...global,
chatCreation: {
...global.chatCreation,
progress: ChatCreationProgress.Error,
error: 'CreateGroupError',
},
});
}
} }
} }