Hashtag: Support click on hashtag with username (#5160)

This commit is contained in:
Alexander Zinchuk 2024-11-27 20:33:17 +04:00
parent 5b3c783e25
commit e62e78f968
3 changed files with 32 additions and 7 deletions

View File

@ -473,10 +473,11 @@ function processEntity({
{renderNestedMessagePart()} {renderNestedMessagePart()}
</a> </a>
); );
case ApiMessageEntityTypes.Hashtag: case ApiMessageEntityTypes.Hashtag: {
const [tag, username] = entityContent.split('@');
return ( return (
<a <a
onClick={handleHashtagClick} onClick={() => handleHashtagClick(tag, username)}
className="text-entity-link" className="text-entity-link"
dir="auto" dir="auto"
data-entity-type={entity.type} data-entity-type={entity.type}
@ -484,10 +485,12 @@ function processEntity({
{renderNestedMessagePart()} {renderNestedMessagePart()}
</a> </a>
); );
case ApiMessageEntityTypes.Cashtag: }
case ApiMessageEntityTypes.Cashtag: {
const [tag, username] = entityContent.split('@');
return ( return (
<a <a
onClick={handleHashtagClick} onClick={() => handleHashtagClick(tag, username)}
className="text-entity-link" className="text-entity-link"
dir="auto" dir="auto"
data-entity-type={entity.type} data-entity-type={entity.type}
@ -495,6 +498,7 @@ function processEntity({
{renderNestedMessagePart()} {renderNestedMessagePart()}
</a> </a>
); );
}
case ApiMessageEntityTypes.Code: case ApiMessageEntityTypes.Code:
return ( return (
<code <code
@ -658,8 +662,19 @@ function handleBotCommandClick(e: React.MouseEvent<HTMLAnchorElement>) {
getActions().sendBotCommand({ command: e.currentTarget.innerText }); getActions().sendBotCommand({ command: e.currentTarget.innerText });
} }
function handleHashtagClick(e: React.MouseEvent<HTMLAnchorElement>) { function handleHashtagClick(hashtag?: string, username?: string) {
getActions().searchHashtag({ hashtag: e.currentTarget.innerText }); if (!hashtag) return;
if (username) {
getActions().openChatByUsername({
username,
onChatChanged: {
action: 'searchHashtag',
payload: { hashtag },
},
});
return;
}
getActions().searchHashtag({ hashtag });
} }
function handleCodeClick(e: React.MouseEvent<HTMLElement>) { function handleCodeClick(e: React.MouseEvent<HTMLElement>) {

View File

@ -1500,7 +1500,8 @@ addActionHandler('acceptChatInvite', async (global, actions, payload): Promise<v
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => { addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
const { const {
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp, text, username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp,
text, onChatChanged,
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload; } = payload;
@ -1542,6 +1543,10 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
text, text,
}, tabId, }, tabId,
); );
if (onChatChanged) {
// @ts-ignore
actions[onChatChanged.action](onChatChanged.payload);
}
return; return;
} }
} }
@ -1586,6 +1591,10 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
tabId, tabId,
focusMessageId: commentId, focusMessageId: commentId,
}); });
if (onChatChanged) {
// @ts-ignore
actions[onChatChanged.action](onChatChanged.payload);
}
}); });
addActionHandler('togglePreHistoryHidden', async (global, actions, payload): Promise<void> => { addActionHandler('togglePreHistoryHidden', async (global, actions, payload): Promise<void> => {

View File

@ -1828,6 +1828,7 @@ export interface ActionPayloads {
startApp?: string; startApp?: string;
text?: string; text?: string;
originalParts?: (string | undefined)[]; originalParts?: (string | undefined)[];
onChatChanged?: CallbackAction;
} & WithTabId; } & WithTabId;
processBoostParameters: { processBoostParameters: {
usernameOrId: string; usernameOrId: string;