Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: E2EE DM setup header toolbox items #32712

Merged
merged 14 commits into from
Jul 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import { useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';

import { roomActionHooksForE2EESetup } from '../../../../ui';
import { useRoom } from '../../contexts/RoomContext';
import type { RoomToolboxActionConfig } from '../../contexts/RoomToolboxContext';
import { useRoomToolbox } from '../../contexts/RoomToolboxContext';
import { getRoomGroup } from '../../lib/getRoomGroup';

const RoomToolboxE2EESetup = () => {
const t = useTranslation();
const toolbox = useRoomToolbox();
const room = useRoom();

const { tab } = toolbox;

const actions = useStableArray(
roomActionHooksForE2EESetup
.map((roomActionHook) => roomActionHook())
.filter((roomAction): roomAction is RoomToolboxActionConfig => !!roomAction),
.filter(
(roomAction): roomAction is RoomToolboxActionConfig =>
!!roomAction && (!roomAction.groups || roomAction.groups.includes(getRoomGroup(room))),
),
);
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved

return (
Expand Down
23 changes: 23 additions & 0 deletions apps/meteor/client/views/room/lib/getRoomGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { RoomType, IRoom } from '@rocket.chat/core-typings';

import type { RoomToolboxActionConfig } from '../contexts/RoomToolboxContext';

const groupsDict = {
l: 'live',
v: 'voip',
d: 'direct',
p: 'group',
c: 'channel',
} as const satisfies Record<RoomType, RoomToolboxActionConfig['groups'][number]>;

export const getRoomGroup = (room: IRoom) => {
if (room.teamMain) {
return 'team';
}

if (room.t === 'd' && (room.uids?.length ?? 0) > 2) {
return 'direct_multiple';
}

return groupsDict[room.t];
};
26 changes: 3 additions & 23 deletions apps/meteor/client/views/room/providers/RoomToolboxProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import type { RoomType, IRoom } from '@rocket.chat/core-typings';
import { useMutableCallback, useStableArray } from '@rocket.chat/fuselage-hooks';
import { useUserId, useSetting, useRouter, useRouteParameter, useLayoutHiddenActions } from '@rocket.chat/ui-contexts';
import type { ReactNode } from 'react';
import React, { useMemo } from 'react';

import { useRoom } from '../contexts/RoomContext';
import { RoomToolboxContext } from '../contexts/RoomToolboxContext';
import type { RoomToolboxContextValue, RoomToolboxActionConfig } from '../contexts/RoomToolboxContext';
import type { RoomToolboxContextValue } from '../contexts/RoomToolboxContext';
import { getRoomGroup } from '../lib/getRoomGroup';
import { useAppsRoomActions } from './hooks/useAppsRoomActions';
import { useCoreRoomActions } from './hooks/useCoreRoomActions';

const groupsDict = {
l: 'live',
v: 'voip',
d: 'direct',
p: 'group',
c: 'channel',
} as const satisfies Record<RoomType, RoomToolboxActionConfig['groups'][number]>;

const getGroup = (room: IRoom) => {
if (room.teamMain) {
return 'team';
}

if (room.t === 'd' && (room.uids?.length ?? 0) > 2) {
return 'direct_multiple';
}

return groupsDict[room.t];
};

type RoomToolboxProviderProps = { children: ReactNode };

const RoomToolboxProvider = ({ children }: RoomToolboxProviderProps) => {
Expand Down Expand Up @@ -92,7 +72,7 @@ const RoomToolboxProvider = ({ children }: RoomToolboxProviderProps) => {
const actions = useStableArray(
[...coreRoomActions, ...appsRoomActions]
.filter((action) => uid || (allowAnonymousRead && 'anonymous' in action && action.anonymous))
.filter((action) => !action.groups || action.groups.includes(getGroup(room)))
.filter((action) => !action.groups || action.groups.includes(getRoomGroup(room)))
.filter((action) => !hiddenActions.includes(action.id))
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)),
);
Expand Down
25 changes: 25 additions & 0 deletions apps/meteor/tests/unit/client/lib/getRoomGroup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { getRoomGroup } from '../../../../client/views/room/lib/getRoomGroup';

describe('getRoomGroup', () => {
it('should return "direct" for direct message rooms', () => {
const result = getRoomGroup({ t: 'd' } as IRoom);

expect(result).to.be.equal('direct');
});

it('should return "team" for team rooms', () => {
const result = getRoomGroup({ teamMain: true } as IRoom);

expect(result).to.be.equal('team');
});

it('should return "direct_multiple" for direct message room with many users', () => {
const result = getRoomGroup({ uids: ['id1', 'id2', 'id3'], t: 'd' } as IRoom);

expect(result).to.be.equal('direct_multiple');
});
});
Loading