Skip to content

Commit

Permalink
refactor: useOpenRoomMutation to use rooms.open endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Dec 6, 2024
1 parent f5302f9 commit 9c0e3b5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/client/views/room/hooks/useOpenRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function useOpenRoom({ type, reference }: { type: RoomType; reference: st
const getRoomByTypeAndName = useMethod('getRoomByTypeAndName');
const createDirectMessage = useMethod('createDirectMessage');
const directRoute = useRoute('direct');
const openRoom = useOpenRoomMutation({ type });
const openRoom = useOpenRoomMutation();

const unsubscribeFromRoomOpenedEvent = useRef<() => void>(() => undefined);

Expand Down
13 changes: 2 additions & 11 deletions apps/meteor/client/views/room/hooks/useOpenRoomMutation.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import type { RoomType } from '@rocket.chat/core-typings';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';

import { updateSubscription } from '../../../lib/mutationEffects/updateSubscription';

const openEndpoints = {
p: '/v1/groups.open',
d: '/v1/im.open',
c: '/v1/channels.open',
v: '/v1/channels.open',
l: '/v1/channels.open',
} as const;

type OpenRoomParams = {
roomId: string;
userId: string;
};

export const useOpenRoomMutation = ({ type }: { type: RoomType }) => {
const openRoom = useEndpoint('POST', openEndpoints[type]);
export const useOpenRoomMutation = () => {
const openRoom = useEndpoint('POST', '/v1/rooms.open');

return useMutation({
mutationFn: async ({ roomId, userId }: OpenRoomParams) => {
Expand Down

0 comments on commit 9c0e3b5

Please sign in to comment.