Forum: Fix wrong channel opening when enabled (#3849)

This commit is contained in:
Alexander Zinchuk 2023-09-13 12:21:54 +02:00
parent e26250071d
commit a132f88878
3 changed files with 20 additions and 13 deletions

View File

@ -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) {

View File

@ -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<vo
if (newAdminMembersById) {
global = getGlobal();
global = updateChatFullInfo(global, chatId, { adminMembersById: newAdminMembersById });
global = updateChatFullInfo(global, chat.id, { adminMembersById: newAdminMembersById });
setGlobal(global);
}
});
@ -1806,12 +1806,6 @@ addActionHandler('toggleForum', async (global, actions, payload): Promise<void>
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<void>
}
}
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 });
}
}
});

View File

@ -74,7 +74,7 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise<v
global = getGlobal();
global = updateManagementProgress(global, result ? ManagementProgress.Complete : ManagementProgress.Error, tabId);
global = updateManagement(global, chatId, {
global = updateManagement(global, chat.id, {
isUsernameAvailable: undefined,
checkedUsername: undefined,
error: undefined,