diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index a1811bb09..2e5c5a283 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -1221,7 +1221,14 @@ export async function migrateChat(chat: ApiChat) { updateLocalDb(result); - return buildApiChatFromPreview(result.chats[1]); + const newChannelId = result.updates + .find((update): update is GramJs.UpdateChannel => update instanceof GramJs.UpdateChannel)!.channelId; + + const newChannel = result.chats.find((c) => ( + c instanceof GramJs.Channel && c.id.toString() === newChannelId.toString() + ))!; + + return buildApiChatFromPreview(newChannel); } export async function openChatByInvite(hash: string) { diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 3edaebf60..cb7ed04b7 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -1257,7 +1257,7 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload global = getGlobal(); - const updatedFullInfo = selectChatFullInfo(global, chatId); + const updatedFullInfo = selectChatFullInfo(global, chat.id); if (!updatedFullInfo) { return; } @@ -1267,7 +1267,7 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload const isBanned = Boolean(bannedRights.viewMessages); const isUnblocked = !Object.keys(bannedRights).length; - global = updateChatFullInfo(global, chatId, { + global = updateChatFullInfo(global, chat.id, { ...(members && isBanned && { members: members.filter((m) => m.userId !== userId), }), @@ -1330,7 +1330,7 @@ addActionHandler('updateChatAdmin', async (global, actions, payload): Promise return; } - global = getGlobal(); - - const prevIsForum = chat.isForum; - global = updateChat(global, chatId, { isForum: isEnabled }); - setGlobal(global); - let result: true | undefined; try { result = await callApi('toggleForum', { chat, isEnabled }); @@ -1823,10 +1817,16 @@ addActionHandler('toggleForum', async (global, actions, payload): Promise } } - if (!result) { + if (result) { global = getGlobal(); - global = updateChat(global, chatId, { isForum: prevIsForum }); + global = updateChat(global, chat.id, { isForum: isEnabled }); setGlobal(global); + + if (!isEnabled) { + actions.closeForumPanel({ tabId }); + } else { + actions.openForumPanel({ chatId: chat.id, tabId }); + } } }); diff --git a/src/global/actions/api/management.ts b/src/global/actions/api/management.ts index 367f3e2e4..e7c65b185 100644 --- a/src/global/actions/api/management.ts +++ b/src/global/actions/api/management.ts @@ -74,7 +74,7 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise