fix: webclient still showing DM messages that had already been deleted from the server (#31537)

pull/31417/head
Pierre Lehnen 2 years ago committed by GitHub
parent c8ec364733
commit 4e138ea5b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/mighty-shirts-sell.md
  2. 2
      apps/meteor/client/providers/UserProvider/UserProvider.tsx
  3. 20
      apps/meteor/client/providers/UserProvider/hooks/useClearRemovedRoomsHistory.ts

@ -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.

@ -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();

@ -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]);
};
Loading…
Cancel
Save