diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 03cbf97c7..cb7d3b511 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -508,14 +508,15 @@ export async function updateChatMutedState({ } export async function createChannel({ - title, about = '', users, + title, about = '', users, type = 'channel', }: { - title: string; about?: string; users?: ApiUser[]; + title: string; about?: string; users?: ApiUser[]; type?: 'channel' | 'group'; }, noErrorUpdate = false): Promise { const result = await invokeRequest(new GramJs.channels.CreateChannel({ - broadcast: true, title, about, + ...(type === 'channel' && { broadcast: true }), + ...(type === 'group' && { megagroup: true }), })); // `createChannel` can return a lot of different update types according to docs, @@ -606,39 +607,6 @@ export function deleteChannel({ }), true); } -export async function createGroupChat({ - title, users, -}: { - title: string; users: ApiUser[]; -}): Promise { - const result = await invokeRequest(new GramJs.messages.CreateChat({ - title, - users: users.map(({ id, accessHash }) => buildInputEntity(id, accessHash)) as GramJs.InputUser[], - }), undefined, true); - - // `createChat` can return a lot of different update types according to docs, - // but currently chat creation returns only `Updates` type. - // Errors are added to catch unexpected cases in future testing - if (!(result instanceof GramJs.Updates)) { - if (DEBUG) { - // eslint-disable-next-line no-console - console.error('Unexpected chat creation update', result); - } - return undefined; - } - - const newChat = result.chats[0]; - if (!newChat || !(newChat instanceof GramJs.Chat)) { - if (DEBUG) { - // eslint-disable-next-line no-console - console.error('Created chat not found', result); - } - return undefined; - } - - return buildApiChatFromPreview(newChat); -} - export async function editChatPhoto({ chatId, accessHash, photo, }: { diff --git a/src/api/gramjs/methods/index.ts b/src/api/gramjs/methods/index.ts index 1eb173a74..f63324244 100644 --- a/src/api/gramjs/methods/index.ts +++ b/src/api/gramjs/methods/index.ts @@ -9,7 +9,7 @@ export { export { fetchChats, fetchFullChat, searchChats, requestChatUpdate, saveDraft, clearDraft, fetchChat, updateChatMutedState, - createChannel, joinChannel, deleteChatUser, deleteChat, leaveChannel, deleteChannel, createGroupChat, editChatPhoto, + createChannel, joinChannel, deleteChatUser, deleteChat, leaveChannel, deleteChannel, editChatPhoto, toggleChatPinned, toggleChatArchived, toggleDialogUnread, setChatEnabledReactions, fetchChatFolders, editChatFolder, deleteChatFolder, fetchRecommendedChatFolders, getChatByUsername, togglePreHistoryHidden, updateChatDefaultBannedRights, updateChatMemberBannedRights, diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 409d82866..c063de69a 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -1142,9 +1142,10 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) { }); try { - const createdChat = await callApi('createGroupChat', { + const createdChat = await callApi('createChannel', { title, users, + type: 'group', }); if (!createdChat) {