Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tidy-pillows-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/i18n': patch
'@rocket.chat/meteor': patch
---

Adds error feedback when clicking on a mentioned room you don't have access to
18 changes: 14 additions & 4 deletions apps/meteor/client/components/GazzodownText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useLocalStorage } from '@rocket.chat/fuselage-hooks';
import type { ChannelMention, UserMention } from '@rocket.chat/gazzodown';
import { MarkupInteractionContext } from '@rocket.chat/gazzodown';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { useLayout, useRouter, useUserPreference, useUserId, useUserCard } from '@rocket.chat/ui-contexts';
import { useLayout, useRouter, useUserPreference, useUserId, useUserCard, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import type { UIEvent } from 'react';
import { useCallback, memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { normalizeUsername } from '../../lib/utils/normalizeUsername';
import { detectEmoji } from '../lib/utils/detectEmoji';
Expand All @@ -30,6 +31,8 @@ const GazzodownText = ({ mentions, channels, searchText, children }: GazzodownTe

const highlights = useMessageListHighlights();
const { triggerProps, openUserCard } = useUserCard();
const dispatchToastMessage = useToastMessageDispatch();
const { t } = useTranslation();

const highlightRegex = useMemo(() => {
if (!highlights?.length) {
Expand Down Expand Up @@ -99,7 +102,7 @@ const GazzodownText = ({ mentions, channels, searchText, children }: GazzodownTe

const onChannelMentionClick = useCallback(
({ _id: rid }: ChannelMention) =>
(event: UIEvent): void => {
async (event: UIEvent): Promise<void> => {
if (isEmbedded) {
fireGlobalEvent('click-mention-link', {
path: router.buildRoutePath({
Expand All @@ -111,9 +114,16 @@ const GazzodownText = ({ mentions, channels, searchText, children }: GazzodownTe
}

event.stopPropagation();
goToRoom(rid);
try {
await goToRoom(rid);
} catch (error) {
dispatchToastMessage({
type: 'error',
message: t('No_access_to_room'),
});
}
},
[router, isEmbedded, goToRoom],
[router, isEmbedded, goToRoom, dispatchToastMessage, t],
);

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -7160,5 +7160,6 @@
"message_body": "message body",
"message_attachment": "message attachment",
"system_message_body": "system message body",
"No_changes_to_save": "No changes to save"
"No_changes_to_save": "No changes to save",
"No_access_to_room": "You don't have access to this room"
}
Loading