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()}
</a>
);
case ApiMessageEntityTypes.Hashtag:
case ApiMessageEntityTypes.Hashtag: {
const [tag, username] = entityContent.split('@');
return (
<a
onClick={handleHashtagClick}
onClick={() => handleHashtagClick(tag, username)}
className="text-entity-link"
dir="auto"
data-entity-type={entity.type}
@ -484,10 +485,12 @@ function processEntity({
{renderNestedMessagePart()}
</a>
);
case ApiMessageEntityTypes.Cashtag:
}
case ApiMessageEntityTypes.Cashtag: {
const [tag, username] = entityContent.split('@');
return (
<a
onClick={handleHashtagClick}
onClick={() => handleHashtagClick(tag, username)}
className="text-entity-link"
dir="auto"
data-entity-type={entity.type}
@ -495,6 +498,7 @@ function processEntity({
{renderNestedMessagePart()}
</a>
);
}
case ApiMessageEntityTypes.Code:
return (
<code
@ -658,8 +662,19 @@ function handleBotCommandClick(e: React.MouseEvent<HTMLAnchorElement>) {
getActions().sendBotCommand({ command: e.currentTarget.innerText });
}
function handleHashtagClick(e: React.MouseEvent<HTMLAnchorElement>) {
getActions().searchHashtag({ hashtag: e.currentTarget.innerText });
function handleHashtagClick(hashtag?: string, username?: string) {
if (!hashtag) return;
if (username) {
getActions().openChatByUsername({
username,
onChatChanged: {
action: 'searchHashtag',
payload: { hashtag },
},
});
return;
}
getActions().searchHashtag({ hashtag });
}
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> => {
const {
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp, text,
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts, startApp,
text, onChatChanged,
tabId = getCurrentTabId(),
} = payload;
@ -1542,6 +1543,10 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
text,
}, tabId,
);
if (onChatChanged) {
// @ts-ignore
actions[onChatChanged.action](onChatChanged.payload);
}
return;
}
}
@ -1586,6 +1591,10 @@ addActionHandler('openChatByUsername', async (global, actions, payload): Promise
tabId,
focusMessageId: commentId,
});
if (onChatChanged) {
// @ts-ignore
actions[onChatChanged.action](onChatChanged.payload);
}
});
addActionHandler('togglePreHistoryHidden', async (global, actions, payload): Promise<void> => {

View File

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