Revert "New Chat: Create supergroups instead of legacy ones (#1704)"
This reverts commit b60b3ae719d76192575598235fd5685d2c727bb5.
This commit is contained in:
parent
0bcb12d006
commit
a76275f355
@ -508,15 +508,14 @@ export async function updateChatMutedState({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createChannel({
|
export async function createChannel({
|
||||||
title, about = '', users, type = 'channel',
|
title, about = '', users,
|
||||||
}: {
|
}: {
|
||||||
title: string; about?: string; users?: ApiUser[]; type?: 'channel' | 'group';
|
title: string; about?: string; users?: ApiUser[];
|
||||||
}, noErrorUpdate = false): Promise<ApiChat | undefined> {
|
}, noErrorUpdate = false): Promise<ApiChat | undefined> {
|
||||||
const result = await invokeRequest(new GramJs.channels.CreateChannel({
|
const result = await invokeRequest(new GramJs.channels.CreateChannel({
|
||||||
|
broadcast: true,
|
||||||
title,
|
title,
|
||||||
about,
|
about,
|
||||||
...(type === 'channel' && { broadcast: true }),
|
|
||||||
...(type === 'group' && { megagroup: true }),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// `createChannel` can return a lot of different update types according to docs,
|
// `createChannel` can return a lot of different update types according to docs,
|
||||||
@ -607,6 +606,39 @@ export function deleteChannel({
|
|||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createGroupChat({
|
||||||
|
title, users,
|
||||||
|
}: {
|
||||||
|
title: string; users: ApiUser[];
|
||||||
|
}): Promise<ApiChat | undefined> {
|
||||||
|
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({
|
export async function editChatPhoto({
|
||||||
chatId, accessHash, photo,
|
chatId, accessHash, photo,
|
||||||
}: {
|
}: {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export {
|
|||||||
export {
|
export {
|
||||||
fetchChats, fetchFullChat, searchChats, requestChatUpdate,
|
fetchChats, fetchFullChat, searchChats, requestChatUpdate,
|
||||||
saveDraft, clearDraft, fetchChat, updateChatMutedState,
|
saveDraft, clearDraft, fetchChat, updateChatMutedState,
|
||||||
createChannel, joinChannel, deleteChatUser, deleteChat, leaveChannel, deleteChannel, editChatPhoto,
|
createChannel, joinChannel, deleteChatUser, deleteChat, leaveChannel, deleteChannel, createGroupChat, editChatPhoto,
|
||||||
toggleChatPinned, toggleChatArchived, toggleDialogUnread, setChatEnabledReactions,
|
toggleChatPinned, toggleChatArchived, toggleDialogUnread, setChatEnabledReactions,
|
||||||
fetchChatFolders, editChatFolder, deleteChatFolder, fetchRecommendedChatFolders,
|
fetchChatFolders, editChatFolder, deleteChatFolder, fetchRecommendedChatFolders,
|
||||||
getChatByUsername, togglePreHistoryHidden, updateChatDefaultBannedRights, updateChatMemberBannedRights,
|
getChatByUsername, togglePreHistoryHidden, updateChatDefaultBannedRights, updateChatMemberBannedRights,
|
||||||
|
|||||||
@ -1152,10 +1152,9 @@ async function createGroupChat(title: string, users: ApiUser[], photo?: File) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const createdChat = await callApi('createChannel', {
|
const createdChat = await callApi('createGroupChat', {
|
||||||
title,
|
title,
|
||||||
users,
|
users,
|
||||||
type: 'group',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!createdChat) {
|
if (!createdChat) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user