From 043a6da42640c5bc70e6695c8d0df056e9770d15 Mon Sep 17 00:00:00 2001 From: juliajforesti Date: Tue, 22 Apr 2025 14:16:40 -0300 Subject: [PATCH] refactor: remove Meteor from `toggleFavoriteRoom` --- apps/meteor/client/lib/mutationEffects/room.ts | 8 ++++---- .../client/views/room/hooks/useToggleFavoriteMutation.ts | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/meteor/client/lib/mutationEffects/room.ts b/apps/meteor/client/lib/mutationEffects/room.ts index cba7005cf7375..f1acd86bdfec1 100644 --- a/apps/meteor/client/lib/mutationEffects/room.ts +++ b/apps/meteor/client/lib/mutationEffects/room.ts @@ -1,9 +1,9 @@ -import { Meteor } from 'meteor/meteor'; - import { Subscriptions } from '../../../app/models/client'; -export const toggleFavoriteRoom = (roomId: string, favorite: boolean) => { - const userId = Meteor.userId()!; +export const toggleFavoriteRoom = (roomId: string, favorite: boolean, userId: string | null) => { + if (!userId) { + return; + } Subscriptions.update( { diff --git a/apps/meteor/client/views/room/hooks/useToggleFavoriteMutation.ts b/apps/meteor/client/views/room/hooks/useToggleFavoriteMutation.ts index c59cbb8627f4d..6c605468411f8 100644 --- a/apps/meteor/client/views/room/hooks/useToggleFavoriteMutation.ts +++ b/apps/meteor/client/views/room/hooks/useToggleFavoriteMutation.ts @@ -1,5 +1,5 @@ import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts'; -import { useEndpoint, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; +import { useEndpoint, useToastMessageDispatch, useUserId } from '@rocket.chat/ui-contexts'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; @@ -9,6 +9,7 @@ import { subscriptionsQueryKeys } from '../../../lib/queryKeys'; export const useToggleFavoriteMutation = () => { const { t } = useTranslation(); const dispatchToastMessage = useToastMessageDispatch(); + const uid = useUserId(); const toggleFavorite = useEndpoint('POST', '/v1/rooms.favorite'); const queryClient = useQueryClient(); @@ -28,7 +29,7 @@ export const useToggleFavoriteMutation = () => { ); }, onSuccess: (_data, { roomId, favorite, roomName }) => { - toggleFavoriteRoom(roomId, favorite); + toggleFavoriteRoom(roomId, favorite, uid); dispatchToastMessage({ type: 'success', message: favorite