Forums: Various fixes 6 (#2273)
This commit is contained in:
parent
fd227480e1
commit
709a35cb02
@ -879,6 +879,7 @@ function buildAction(
|
|||||||
let photo: ApiPhoto | undefined;
|
let photo: ApiPhoto | undefined;
|
||||||
let score: number | undefined;
|
let score: number | undefined;
|
||||||
let months: number | undefined;
|
let months: number | undefined;
|
||||||
|
let topicEmojiIconId: string | undefined;
|
||||||
|
|
||||||
const targetUserIds = 'users' in action
|
const targetUserIds = 'users' in action
|
||||||
? action.users && action.users.map((id) => buildApiPeerId(id, 'user'))
|
? action.users && action.users.map((id) => buildApiPeerId(id, 'user'))
|
||||||
@ -1036,8 +1037,11 @@ function buildAction(
|
|||||||
} else if (action.title) {
|
} else if (action.title) {
|
||||||
text = 'TopicRenamedTo';
|
text = 'TopicRenamedTo';
|
||||||
translationValues.push('%action_origin%', action.title);
|
translationValues.push('%action_origin%', action.title);
|
||||||
|
} else if (action.iconEmojiId) {
|
||||||
|
text = 'TopicWasIconChangedToAction';
|
||||||
|
translationValues.push('%action_origin%', '%action_topic_icon%');
|
||||||
|
topicEmojiIconId = action.iconEmojiId.toString();
|
||||||
} else {
|
} else {
|
||||||
// TODO[forums] Support icon changed action
|
|
||||||
text = 'ChatList.UnsupportedMessage';
|
text = 'ChatList.UnsupportedMessage';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1062,6 +1066,7 @@ function buildAction(
|
|||||||
phoneCall,
|
phoneCall,
|
||||||
score,
|
score,
|
||||||
months,
|
months,
|
||||||
|
topicEmojiIconId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import {
|
|||||||
ALL_FOLDER_ID,
|
ALL_FOLDER_ID,
|
||||||
MAX_INT_32,
|
MAX_INT_32,
|
||||||
TOPICS_SLICE,
|
TOPICS_SLICE,
|
||||||
|
GENERAL_TOPIC_ID,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { invokeRequest, uploadFile } from './client';
|
import { invokeRequest, uploadFile } from './client';
|
||||||
import {
|
import {
|
||||||
@ -1516,7 +1517,7 @@ export function editTopic({
|
|||||||
channel: buildInputPeer(id, accessHash),
|
channel: buildInputPeer(id, accessHash),
|
||||||
topicId,
|
topicId,
|
||||||
title,
|
title,
|
||||||
iconEmojiId: BigInt(iconEmojiId || '0'),
|
iconEmojiId: topicId !== GENERAL_TOPIC_ID && iconEmojiId ? BigInt(iconEmojiId) : undefined,
|
||||||
closed: isClosed,
|
closed: isClosed,
|
||||||
hidden: isHidden,
|
hidden: isHidden,
|
||||||
}), true);
|
}), true);
|
||||||
|
|||||||
@ -268,6 +268,7 @@ export interface ApiAction {
|
|||||||
phoneCall?: PhoneCallAction;
|
phoneCall?: PhoneCallAction;
|
||||||
score?: number;
|
score?: number;
|
||||||
months?: number;
|
months?: number;
|
||||||
|
topicEmojiIconId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiWebPage {
|
export interface ApiWebPage {
|
||||||
|
|||||||
@ -21,6 +21,8 @@ import MessageLink from '../MessageLink';
|
|||||||
import ChatLink from '../ChatLink';
|
import ChatLink from '../ChatLink';
|
||||||
import GroupCallLink from '../GroupCallLink';
|
import GroupCallLink from '../GroupCallLink';
|
||||||
import MessageSummary from '../MessageSummary';
|
import MessageSummary from '../MessageSummary';
|
||||||
|
import CustomEmoji from '../CustomEmoji';
|
||||||
|
import TopicDefaultIcon from '../TopicDefaultIcon';
|
||||||
|
|
||||||
interface RenderOptions {
|
interface RenderOptions {
|
||||||
asPlainText?: boolean;
|
asPlainText?: boolean;
|
||||||
@ -48,7 +50,7 @@ export function renderActionMessageText(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
text, translationValues, amount, currency, call, score,
|
text, translationValues, amount, currency, call, score, topicEmojiIconId,
|
||||||
} = message.content.action;
|
} = message.content.action;
|
||||||
const content: TextPart[] = [];
|
const content: TextPart[] = [];
|
||||||
const noLinks = options.asPlainText || options.isEmbedded;
|
const noLinks = options.asPlainText || options.isEmbedded;
|
||||||
@ -95,10 +97,26 @@ export function renderActionMessageText(
|
|||||||
content.push(...processed);
|
content.push(...processed);
|
||||||
|
|
||||||
if (unprocessed.includes('%action_topic%')) {
|
if (unprocessed.includes('%action_topic%')) {
|
||||||
|
const topicEmoji = topic?.iconEmojiId ? <CustomEmoji documentId={topic.iconEmojiId} /> : '';
|
||||||
|
const topicString = topic ? `${topic.title}` : 'a topic';
|
||||||
processed = processPlaceholder(
|
processed = processPlaceholder(
|
||||||
unprocessed,
|
unprocessed,
|
||||||
'%action_topic%',
|
'%action_topic%',
|
||||||
topic ? topic.title : 'a topic',
|
[topicEmoji, topicString],
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
unprocessed = processed.pop() as string;
|
||||||
|
content.push(...processed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unprocessed.includes('%action_topic_icon%')) {
|
||||||
|
const topicIcon = topicEmojiIconId || topic?.iconEmojiId;
|
||||||
|
const hasIcon = topicIcon && topicIcon !== '0';
|
||||||
|
processed = processPlaceholder(
|
||||||
|
unprocessed,
|
||||||
|
'%action_topic_icon%',
|
||||||
|
hasIcon ? <CustomEmoji documentId={topicIcon!} />
|
||||||
|
: topic ? <TopicDefaultIcon topicId={topic!.id} title={topic!.title} /> : '...',
|
||||||
);
|
);
|
||||||
unprocessed = processed.pop() as string;
|
unprocessed = processed.pop() as string;
|
||||||
content.push(...processed);
|
content.push(...processed);
|
||||||
@ -256,7 +274,9 @@ function renderMigratedContent(chatId: string, noLinks?: boolean): string | Text
|
|||||||
return <ChatLink className="action-link underlined-link" chatId={chatId}>{text}</ChatLink>;
|
return <ChatLink className="action-link underlined-link" chatId={chatId}>{text}</ChatLink>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processPlaceholder(text: string, placeholder: string, replaceValue?: TextPart | TextPart[]): TextPart[] {
|
function processPlaceholder(
|
||||||
|
text: string, placeholder: string, replaceValue?: TextPart | TextPart[], separator = ',',
|
||||||
|
): TextPart[] {
|
||||||
const placeholderPosition = text.indexOf(placeholder);
|
const placeholderPosition = text.indexOf(placeholder);
|
||||||
if (placeholderPosition < 0 || !replaceValue) {
|
if (placeholderPosition < 0 || !replaceValue) {
|
||||||
return [text];
|
return [text];
|
||||||
@ -268,7 +288,7 @@ function processPlaceholder(text: string, placeholder: string, replaceValue?: Te
|
|||||||
replaceValue.forEach((value, index) => {
|
replaceValue.forEach((value, index) => {
|
||||||
content.push(value);
|
content.push(value);
|
||||||
if (index + 1 < replaceValue.length) {
|
if (index + 1 < replaceValue.length) {
|
||||||
content.push(', ');
|
content.push(`${separator} `);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { getActions } from '../../../../global';
|
|||||||
import type { ApiChat, ApiTopic } from '../../../../api/types';
|
import type { ApiChat, ApiTopic } from '../../../../api/types';
|
||||||
|
|
||||||
import { compact } from '../../../../util/iteratees';
|
import { compact } from '../../../../util/iteratees';
|
||||||
import { getHasAdminRight } from '../../../../global/helpers';
|
import { getCanManageTopic, getHasAdminRight } from '../../../../global/helpers';
|
||||||
|
|
||||||
import useLang from '../../../../hooks/useLang';
|
import useLang from '../../../../hooks/useLang';
|
||||||
import { useMemo } from '../../../../lib/teact/teact';
|
import { useMemo } from '../../../../lib/teact/teact';
|
||||||
@ -19,7 +19,7 @@ export default function useTopicContextActions(
|
|||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const {
|
const {
|
||||||
isPinned, isMuted, isClosed, isOwner, id: topicId,
|
isPinned, isMuted, isClosed, id: topicId,
|
||||||
} = topic;
|
} = topic;
|
||||||
|
|
||||||
const chatId = chat.id;
|
const chatId = chat.id;
|
||||||
@ -31,7 +31,7 @@ export default function useTopicContextActions(
|
|||||||
updateTopicMutedState,
|
updateTopicMutedState,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const canToggleClosed = isOwner || chat.isCreator || getHasAdminRight(chat, 'manageTopics');
|
const canToggleClosed = getCanManageTopic(chat, topic);
|
||||||
const canTogglePinned = chat.isCreator || getHasAdminRight(chat, 'manageTopics');
|
const canTogglePinned = chat.isCreator || getHasAdminRight(chat, 'manageTopics');
|
||||||
|
|
||||||
const actionUnreadMark = topic.unreadCount || !wasOpened
|
const actionUnreadMark = topic.unreadCount || !wasOpened
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import Transition from '../ui/Transition';
|
|||||||
import styles from './ManageTopic.module.scss';
|
import styles from './ManageTopic.module.scss';
|
||||||
|
|
||||||
const ICON_SIZE = 5 * REM;
|
const ICON_SIZE = 5 * REM;
|
||||||
|
const RESET_ICON_ID = '0';
|
||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
@ -92,7 +93,7 @@ const EditTopic: FC<OwnProps & StateProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (emoji.id === DEFAULT_TOPIC_ICON_STICKER_ID) {
|
if (emoji.id === DEFAULT_TOPIC_ICON_STICKER_ID) {
|
||||||
setIconEmojiId(undefined);
|
setIconEmojiId(RESET_ICON_ID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1427,13 +1427,15 @@ addActionHandler('createTopic', async (global, actions, payload) => {
|
|||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
if (!chat) return;
|
if (!chat) return;
|
||||||
|
|
||||||
setGlobal({
|
if (global.createTopicPanel) {
|
||||||
...global,
|
setGlobal({
|
||||||
createTopicPanel: {
|
...global,
|
||||||
chatId,
|
createTopicPanel: {
|
||||||
isLoading: true,
|
chatId,
|
||||||
},
|
isLoading: true,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const topicId = await callApi('createTopic', {
|
const topicId = await callApi('createTopic', {
|
||||||
chat, title, iconColor, iconEmojiId,
|
chat, title, iconColor, iconEmojiId,
|
||||||
@ -1464,14 +1466,16 @@ addActionHandler('editTopic', async (global, actions, payload) => {
|
|||||||
const topic = chat?.topics?.[topicId];
|
const topic = chat?.topics?.[topicId];
|
||||||
if (!chat || !topic) return;
|
if (!chat || !topic) return;
|
||||||
|
|
||||||
setGlobal({
|
if (global.editTopicPanel) {
|
||||||
...global,
|
setGlobal({
|
||||||
editTopicPanel: {
|
...global,
|
||||||
chatId,
|
editTopicPanel: {
|
||||||
topicId,
|
chatId,
|
||||||
isLoading: true,
|
topicId,
|
||||||
},
|
isLoading: true,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const result = await callApi('editTopic', { chat, topicId, ...rest });
|
const result = await callApi('editTopic', { chat, topicId, ...rest });
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user