Skip to content

Commit

Permalink
fix: webclient still showing DM messages that had already been delete…
Browse files Browse the repository at this point in the history
…d from the server (#31537)
  • Loading branch information
pierre-lehnen-rc authored Jan 25, 2024
1 parent c8ec364 commit 4e138ea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-shirts-sell.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions apps/meteor/client/providers/UserProvider/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,7 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
createFontStyleElement(user?.settings?.preferences?.fontSize);

useEmailVerificationWarning(user ?? undefined);
useClearRemovedRoomsHistory(userId);

useDeleteUser();
useUpdateAvatar();
Expand Down
Original file line number Diff line number Diff line change
@@ -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]);
};

0 comments on commit 4e138ea

Please sign in to comment.