New Chat: Fix freezing when users disable adding them to groups (#1552)
This commit is contained in:
parent
5d3ceb9e64
commit
7ea9dd116f
@ -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.
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -1088,27 +1088,52 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdChat = await callApi('createGroupChat', { title, users });
|
try {
|
||||||
if (!createdChat) {
|
const createdChat = await callApi('createGroupChat', {
|
||||||
return;
|
title,
|
||||||
}
|
users,
|
||||||
|
});
|
||||||
|
|
||||||
const { id: chatId } = createdChat;
|
if (!createdChat) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let global = getGlobal();
|
const { id: chatId } = createdChat;
|
||||||
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) {
|
let global = getGlobal();
|
||||||
await callApi('editChatPhoto', { chatId, photo });
|
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',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user