diff --git a/.changeset/mighty-shirts-sell.md b/.changeset/mighty-shirts-sell.md new file mode 100644 index 00000000000..7ff8c1fca45 --- /dev/null +++ b/.changeset/mighty-shirts-sell.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed an issue where the webclient didn't properly clear the message caches from memory when a room is deleted. When this happened to basic DMs and the user started a new DM with the same target user, the client would show the old messages in the room history even though they no longer existed in the server. diff --git a/apps/meteor/client/providers/UserProvider/UserProvider.tsx b/apps/meteor/client/providers/UserProvider/UserProvider.tsx index b016251dc25..62ed7070737 100644 --- a/apps/meteor/client/providers/UserProvider/UserProvider.tsx +++ b/apps/meteor/client/providers/UserProvider/UserProvider.tsx @@ -13,6 +13,7 @@ import { afterLogoutCleanUpCallback } from '../../../lib/callbacks/afterLogoutCl import { useReactiveValue } from '../../hooks/useReactiveValue'; import { createReactiveSubscriptionFactory } from '../../lib/createReactiveSubscriptionFactory'; import { useCreateFontStyleElement } from '../../views/account/accessibility/hooks/useCreateFontStyleElement'; +import { useClearRemovedRoomsHistory } from './hooks/useClearRemovedRoomsHistory'; import { useDeleteUser } from './hooks/useDeleteUser'; import { useEmailVerificationWarning } from './hooks/useEmailVerificationWarning'; import { useUpdateAvatar } from './hooks/useUpdateAvatar'; @@ -51,6 +52,7 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => { createFontStyleElement(user?.settings?.preferences?.fontSize); useEmailVerificationWarning(user ?? undefined); + useClearRemovedRoomsHistory(userId); useDeleteUser(); useUpdateAvatar(); diff --git a/apps/meteor/client/providers/UserProvider/hooks/useClearRemovedRoomsHistory.ts b/apps/meteor/client/providers/UserProvider/hooks/useClearRemovedRoomsHistory.ts new file mode 100644 index 00000000000..50d12c3d334 --- /dev/null +++ b/apps/meteor/client/providers/UserProvider/hooks/useClearRemovedRoomsHistory.ts @@ -0,0 +1,20 @@ +import { useStream } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +import { RoomHistoryManager } from '../../../../app/ui-utils/client'; + +export const useClearRemovedRoomsHistory = (userId: string | null) => { + const subscribeToNotifyUser = useStream('notify-user'); + + useEffect(() => { + if (!userId) { + return; + } + + return subscribeToNotifyUser(`${userId}/subscriptions-changed`, (event, data) => { + if (event === 'removed' && data.rid) { + RoomHistoryManager.clear(data.rid); + } + }); + }, [userId, subscribeToNotifyUser]); +};