Forums: Allow to create forum from basic group (#2700)

This commit is contained in:
Alexander Zinchuk 2023-02-28 18:44:07 +01:00
parent 2fff3a6bd2
commit 12810e8200
5 changed files with 52 additions and 64 deletions

View File

@ -362,9 +362,9 @@ const LeftMainHeader: FC<OwnProps & StateProps> = ({
)} )}
</> </>
), [ ), [
animationLevel, archiveSettings.isHidden, archivedUnreadChatsCount, canInstall, handleAnimationLevelChange, animationLevel, archivedUnreadChatsCount, canInstall, handleAnimationLevelChange, handleBugReportClick, lang,
handleBugReportClick, handleChangelogClick, handleDarkModeToggle, handleOpenTipsChat, handleSelectSaved, handleChangelogClick, handleDarkModeToggle, handleOpenTipsChat, handleSelectSaved, handleSwitchToWebK,
handleSwitchToWebK, lang, onSelectArchived, onSelectContacts, onSelectSettings, theme, withOtherVersions, onSelectArchived, onSelectContacts, onSelectSettings, theme, withOtherVersions, archiveSettings,
]); ]);
return ( return (

View File

@ -16,7 +16,6 @@ import {
getHasAdminRight, getHasAdminRight,
isChatBasicGroup, isChatBasicGroup,
isChatPublic, isChatPublic,
isChatSuperGroup,
} from '../../../global/helpers'; } from '../../../global/helpers';
import useMedia from '../../../hooks/useMedia'; import useMedia from '../../../hooks/useMedia';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
@ -475,7 +474,7 @@ export default memo(withGlobal<OwnProps>(
const hasLinkedChannel = Boolean(chat.fullInfo?.linkedChatId); const hasLinkedChannel = Boolean(chat.fullInfo?.linkedChatId);
const isBasicGroup = isChatBasicGroup(chat); const isBasicGroup = isChatBasicGroup(chat);
const { invites } = management.byChatId[chatId] || {}; const { invites } = management.byChatId[chatId] || {};
const canEditForum = !hasLinkedChannel && isChatSuperGroup(chat) && getHasAdminRight(chat, 'changeInfo'); const canEditForum = !hasLinkedChannel && (getHasAdminRight(chat, 'changeInfo') || chat.isCreator);
return { return {
chat, chat,

View File

@ -55,7 +55,7 @@ import {
selectChatFolder, selectSupportChat, selectChatByUsername, selectChatFolder, selectSupportChat, selectChatByUsername,
selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification, selectCurrentMessageList, selectThreadInfo, selectCurrentChat, selectLastServiceNotification,
selectVisibleUsers, selectUserByPhoneNumber, selectDraft, selectThreadTopMessageId, selectVisibleUsers, selectUserByPhoneNumber, selectDraft, selectThreadTopMessageId,
selectTabState, selectThread, selectThreadOriginChat, selectTabState, selectThreadOriginChat, selectThread,
} from '../../selectors'; } from '../../selectors';
import { buildCollectionByKey, omit } from '../../../util/iteratees'; import { buildCollectionByKey, omit } from '../../../util/iteratees';
import { debounce, pause, throttle } from '../../../util/schedulers'; import { debounce, pause, throttle } from '../../../util/schedulers';
@ -1082,22 +1082,12 @@ addActionHandler('togglePreHistoryHidden', async (global, actions, payload): Pro
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload!; } = payload!;
let chat = selectChat(global, chatId); const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
if (!chat) { if (!chat) {
return; return;
} }
if (isChatBasicGroup(chat)) { global = getGlobal();
chat = await migrateChat(global, actions, chat, tabId);
global = getGlobal();
if (!chat) {
return;
}
actions.openChat({ id: chat.id, tabId });
return;
}
global = updateChat(global, chat.id, { global = updateChat(global, chat.id, {
fullInfo: { fullInfo: {
@ -1126,22 +1116,16 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload
chatId, userId, bannedRights, chatId, userId, bannedRights,
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload!; } = payload!;
let chat = selectChat(global, chatId);
const user = selectUser(global, userId); const user = selectUser(global, userId);
if (!chat || !user) { if (!user) {
return; return;
} }
if (isChatBasicGroup(chat)) { const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
chat = await migrateChat(global, actions, chat, tabId);
if (!chat) { if (!chat) return;
return;
}
actions.openChat({ id: chat.id, tabId });
}
await callApi('updateChatMemberBannedRights', { chat, user, bannedRights }); await callApi('updateChatMemberBannedRights', { chat, user, bannedRights });
@ -1185,20 +1169,14 @@ addActionHandler('updateChatAdmin', async (global, actions, payload): Promise<vo
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload!; } = payload!;
let chat = selectChat(global, chatId);
const user = selectUser(global, userId); const user = selectUser(global, userId);
if (!chat || !user) { if (!user) {
return; return;
} }
if (isChatBasicGroup(chat)) { const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
chat = await migrateChat(global, actions, chat, tabId);
if (!chat) {
return;
}
actions.openChat({ id: chat.id, tabId }); if (!chat) return;
}
await callApi('updateChatAdmin', { await callApi('updateChatAdmin', {
chat, user, adminRights, customTitle, chat, user, adminRights, customTitle,
@ -1368,20 +1346,13 @@ addActionHandler('linkDiscussionGroup', async (global, actions, payload): Promis
const { channelId, chatId, tabId = getCurrentTabId() } = payload || {}; const { channelId, chatId, tabId = getCurrentTabId() } = payload || {};
const channel = selectChat(global, channelId); const channel = selectChat(global, channelId);
let chat = selectChat(global, chatId); if (!channel) {
if (!channel || !chat) {
return; return;
} }
if (isChatBasicGroup(chat)) { const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
chat = await migrateChat(global, actions, chat, tabId);
if (!chat) { if (!chat) return;
return;
}
actions.openChat({ id: chat.id, tabId });
}
let { fullInfo } = chat; let { fullInfo } = chat;
if (!fullInfo) { if (!fullInfo) {
@ -1692,12 +1663,15 @@ addActionHandler('loadTopicById', async (global, actions, payload): Promise<void
}); });
addActionHandler('toggleForum', async (global, actions, payload): Promise<void> => { addActionHandler('toggleForum', async (global, actions, payload): Promise<void> => {
const { chatId, isEnabled } = payload; const { chatId, isEnabled, tabId = getCurrentTabId() } = payload;
const chat = selectChat(global, chatId);
const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
if (!chat) { if (!chat) {
return; return;
} }
global = getGlobal();
const prevIsForum = chat.isForum; const prevIsForum = chat.isForum;
global = updateChat(global, chatId, { isForum: isEnabled }); global = updateChat(global, chatId, { isForum: isEnabled });
setGlobal(global); setGlobal(global);
@ -2198,3 +2172,24 @@ async function openAttachMenuFromLink<T extends GlobalState>(
tabId, tabId,
}); });
} }
export async function ensureIsSuperGroup<T extends GlobalState>(
global: T,
actions: RequiredGlobalActions,
chatId: string,
...[tabId = getCurrentTabId()]: TabArgs<T>
) {
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;
}

View File

@ -10,8 +10,8 @@ import {
import { import {
selectChat, selectCurrentMessageList, selectTabState, selectUser, selectChat, selectCurrentMessageList, selectTabState, selectUser,
} from '../../selectors'; } from '../../selectors';
import { migrateChat } from './chats'; import { ensureIsSuperGroup } from './chats';
import { getUserFirstOrLastName, isChatBasicGroup } from '../../helpers'; import { getUserFirstOrLastName } from '../../helpers';
import { buildCollectionByKey } from '../../../util/iteratees'; import { buildCollectionByKey } from '../../../util/iteratees';
import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { getCurrentTabId } from '../../../util/establishMultitabRole';
import * as langProvider from '../../../util/langProvider'; import * as langProvider from '../../../util/langProvider';
@ -56,24 +56,18 @@ addActionHandler('updatePublicLink', async (global, actions, payload): Promise<v
const { username, tabId = getCurrentTabId() } = payload; const { username, tabId = getCurrentTabId() } = payload;
const { chatId } = selectCurrentMessageList(global, tabId) || {}; const { chatId } = selectCurrentMessageList(global, tabId) || {};
let chat = chatId && selectChat(global, chatId); if (!chatId) {
if (!chatId || !chat) {
return; return;
} }
const chat = await ensureIsSuperGroup(global, actions, chatId, tabId);
if (!chat) return;
global = getGlobal();
global = updateManagementProgress(global, ManagementProgress.InProgress, tabId); global = updateManagementProgress(global, ManagementProgress.InProgress, tabId);
setGlobal(global); setGlobal(global);
if (isChatBasicGroup(chat)) {
chat = await migrateChat(global, actions, chat, tabId);
if (!chat) {
return;
}
actions.openChat({ id: chat.id, tabId });
}
const result = await callApi('setChatUsername', { chat, username }); const result = await callApi('setChatUsername', { chat, username });
global = getGlobal(); global = getGlobal();

View File

@ -2310,7 +2310,7 @@ export interface ActionPayloads {
toggleForum: { toggleForum: {
chatId: string; chatId: string;
isEnabled: boolean; isEnabled: boolean;
}; } & WithTabId;
createTopic: { createTopic: {
chatId: string; chatId: string;
title: string; title: string;