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({
title,
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,
// but currently chat creation returns only `Updates` type.

View File

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

View File

@ -1088,27 +1088,52 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) {
},
});
const createdChat = await callApi('createGroupChat', { title, users });
if (!createdChat) {
return;
}
try {
const createdChat = await callApi('createGroupChat', {
title,
users,
});
const { id: chatId } = createdChat;
if (!createdChat) {
return;
}
let global = getGlobal();
global = updateChat(global, chatId, createdChat);
global = {
...global,
chatCreation: {
...global.chatCreation,
progress: createdChat ? ChatCreationProgress.Complete : ChatCreationProgress.Error,
},
};
setGlobal(global);
getDispatch().openChat({ id: chatId, shouldReplaceHistory: true });
const { id: chatId } = createdChat;
if (chatId && photo) {
await callApi('editChatPhoto', { chatId, photo });
let global = getGlobal();
global = updateChat(global, chatId, createdChat);
global = {
...global,
chatCreation: {
...global.chatCreation,
progress: createdChat ? ChatCreationProgress.Complete : ChatCreationProgress.Error,
},
};
setGlobal(global);
getDispatch()
.openChat({
id: chatId,
shouldReplaceHistory: true,
});
if (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',
},
});
}
}
}