diff --git a/src/components/left/main/LeftMainHeader.tsx b/src/components/left/main/LeftMainHeader.tsx index b5b6fdb99..3a5aa570a 100644 --- a/src/components/left/main/LeftMainHeader.tsx +++ b/src/components/left/main/LeftMainHeader.tsx @@ -362,9 +362,9 @@ const LeftMainHeader: FC = ({ )} ), [ - animationLevel, archiveSettings.isHidden, archivedUnreadChatsCount, canInstall, handleAnimationLevelChange, - handleBugReportClick, handleChangelogClick, handleDarkModeToggle, handleOpenTipsChat, handleSelectSaved, - handleSwitchToWebK, lang, onSelectArchived, onSelectContacts, onSelectSettings, theme, withOtherVersions, + animationLevel, archivedUnreadChatsCount, canInstall, handleAnimationLevelChange, handleBugReportClick, lang, + handleChangelogClick, handleDarkModeToggle, handleOpenTipsChat, handleSelectSaved, handleSwitchToWebK, + onSelectArchived, onSelectContacts, onSelectSettings, theme, withOtherVersions, archiveSettings, ]); return ( diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index 74f4d61d7..aee72c86f 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -16,7 +16,6 @@ import { getHasAdminRight, isChatBasicGroup, isChatPublic, - isChatSuperGroup, } from '../../../global/helpers'; import useMedia from '../../../hooks/useMedia'; import useLang from '../../../hooks/useLang'; @@ -475,7 +474,7 @@ export default memo(withGlobal( const hasLinkedChannel = Boolean(chat.fullInfo?.linkedChatId); const isBasicGroup = isChatBasicGroup(chat); const { invites } = management.byChatId[chatId] || {}; - const canEditForum = !hasLinkedChannel && isChatSuperGroup(chat) && getHasAdminRight(chat, 'changeInfo'); + const canEditForum = !hasLinkedChannel && (getHasAdminRight(chat, 'changeInfo') || chat.isCreator); return { chat, diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 36c5a69b8..0e3d58086 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -55,7 +55,7 @@ import { selectChatFolder, selectSupportChat, selectChatByUsername, selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification, selectVisibleUsers, selectUserByPhoneNumber, selectDraft, selectThreadTopMessageId, - selectTabState, selectThread, selectThreadOriginChat, + selectTabState, selectThreadOriginChat, selectThread, } from '../../selectors'; import { buildCollectionByKey, omit } from '../../../util/iteratees'; import { debounce, pause, throttle } from '../../../util/schedulers'; @@ -1082,22 +1082,12 @@ addActionHandler('togglePreHistoryHidden', async (global, actions, payload): Pro tabId = getCurrentTabId(), } = payload!; - let chat = selectChat(global, chatId); + const chat = await ensureIsSuperGroup(global, actions, chatId, tabId); if (!chat) { return; } - if (isChatBasicGroup(chat)) { - chat = await migrateChat(global, actions, chat, tabId); - global = getGlobal(); - - if (!chat) { - return; - } - - actions.openChat({ id: chat.id, tabId }); - return; - } + global = getGlobal(); global = updateChat(global, chat.id, { fullInfo: { @@ -1126,22 +1116,16 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload chatId, userId, bannedRights, tabId = getCurrentTabId(), } = payload!; - let chat = selectChat(global, chatId); + const user = selectUser(global, userId); - if (!chat || !user) { + if (!user) { return; } - if (isChatBasicGroup(chat)) { - chat = await migrateChat(global, actions, chat, tabId); + const chat = await ensureIsSuperGroup(global, actions, chatId, tabId); - if (!chat) { - return; - } - - actions.openChat({ id: chat.id, tabId }); - } + if (!chat) return; await callApi('updateChatMemberBannedRights', { chat, user, bannedRights }); @@ -1185,20 +1169,14 @@ addActionHandler('updateChatAdmin', async (global, actions, payload): Promise => { - const { chatId, isEnabled } = payload; - const chat = selectChat(global, chatId); + const { chatId, isEnabled, tabId = getCurrentTabId() } = payload; + + const chat = await ensureIsSuperGroup(global, actions, chatId, tabId); if (!chat) { return; } + global = getGlobal(); + const prevIsForum = chat.isForum; global = updateChat(global, chatId, { isForum: isEnabled }); setGlobal(global); @@ -2198,3 +2172,24 @@ async function openAttachMenuFromLink( tabId, }); } + +export async function ensureIsSuperGroup( + global: T, + actions: RequiredGlobalActions, + chatId: string, + ...[tabId = getCurrentTabId()]: TabArgs +) { + const chat = selectChat(global, chatId); + if (!chat || !isChatBasicGroup(chat)) { + return chat; + } + + const newChat = await migrateChat(global, actions, chat, tabId); + if (!newChat) { + return undefined; + } + + actions.openChat({ id: newChat.id, tabId }); + + return newChat; +} diff --git a/src/global/actions/api/management.ts b/src/global/actions/api/management.ts index 03fceb099..4de5621e3 100644 --- a/src/global/actions/api/management.ts +++ b/src/global/actions/api/management.ts @@ -10,8 +10,8 @@ import { import { selectChat, selectCurrentMessageList, selectTabState, selectUser, } from '../../selectors'; -import { migrateChat } from './chats'; -import { getUserFirstOrLastName, isChatBasicGroup } from '../../helpers'; +import { ensureIsSuperGroup } from './chats'; +import { getUserFirstOrLastName } from '../../helpers'; import { buildCollectionByKey } from '../../../util/iteratees'; import { getCurrentTabId } from '../../../util/establishMultitabRole'; import * as langProvider from '../../../util/langProvider'; @@ -56,24 +56,18 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise