Skip to content

Commit

Permalink
regression: DMs not working properly in embedded layout (#34848)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh authored Dec 31, 2024
1 parent 3bc51d9 commit 9d0c1bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const computation = Tracker.autorun(() => {
}
Tracker.nonreactive(() =>
Object.entries(openedRooms).forEach(([typeName, record]) => {
if (record.active !== true || record.ready === true) {
if (record.active !== true || (record.ready === true && record.streamActive === true)) {
return;
}

Expand Down
26 changes: 23 additions & 3 deletions apps/meteor/client/views/room/RoomOpenerEmbedded.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { ISubscription, RoomType } from '@rocket.chat/core-typings';
import { Box, States, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage';
import { FeaturePreviewOff, FeaturePreviewOn } from '@rocket.chat/ui-client';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useEndpoint, useStream, useUserId } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ReactElement } from 'react';
import React, { lazy, Suspense } from 'react';
import React, { lazy, Suspense, useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import RoomSkeleton from './RoomSkeleton';
import RoomSidepanel from './Sidepanel/RoomSidepanel';
import { useOpenRoom } from './hooks/useOpenRoom';
import { CachedChatSubscription } from '../../../app/models/client';
import { LegacyRoomManager } from '../../../app/ui-utils/client';
import { FeaturePreviewSidePanelNavigation } from '../../components/FeaturePreviewSidePanelNavigation';
import { Header } from '../../components/Header';
import { getErrorMessage } from '../../lib/errorHandling';
Expand All @@ -33,11 +34,14 @@ const isDirectOrOmnichannelRoom = (type: RoomType) => type === 'd' || type === '

const RoomOpenerEmbedded = ({ type, reference }: RoomOpenerProps): ReactElement => {
const { data, error, isSuccess, isError, isLoading } = useOpenRoom({ type, reference });
const uid = useUserId();

const getSubscription = useEndpoint('GET', '/v1/subscriptions.getOne');

const subscribeToNotifyUser = useStream('notify-user');

const rid = data?.rid;
useQuery(
const { refetch } = useQuery(
['subscriptions', rid],
() => {
if (!rid) {
Expand All @@ -53,10 +57,26 @@ const RoomOpenerEmbedded = ({ type, reference }: RoomOpenerProps): ReactElement
throw new Error('Room not found');
}
CachedChatSubscription.upsertSubscription(subscription as unknown as ISubscription);
LegacyRoomManager.computation.invalidate();
},
},
);

useEffect(() => {
if (!uid) {
return;
}
return subscribeToNotifyUser(`${uid}/subscriptions-changed`, (event, sub) => {
if (event !== 'inserted') {
return;
}

if (sub.rid === rid) {
refetch();
}
});
}, [refetch, rid, subscribeToNotifyUser, uid]);

const { t } = useTranslation();

return (
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/client/views/room/hooks/useOpenRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export function useOpenRoom({ type, reference }: { type: RoomType; reference: st

try {
const { rid } = await createDirectMessage(...reference.split(', '));
const { Subscriptions } = await import('../../../../app/models/client');
const { waitUntilFind } = await import('../../../lib/utils/waitUntilFind');
await waitUntilFind(() => Subscriptions.findOne({ rid }));

directRoute.push({ rid }, (prev) => prev);
} catch (error) {
throw new RoomNotFoundError(undefined, { type, reference });
Expand Down

0 comments on commit 9d0c1bc

Please sign in to comment.