Skip to content

Commit

Permalink
Merge branch 'develop' into fix/user-info-alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit-Khairmode authored Nov 28, 2024
2 parents ef4f502 + fd44a8b commit 32b78fd
Show file tree
Hide file tree
Showing 29 changed files with 1,212 additions and 1,199 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-mirrors-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue where premium settings were using the wrong `Tag` variant in Omnichannel Appearance configuration
5 changes: 5 additions & 0 deletions .changeset/strange-countries-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fixed an issue that caused the conference call ringer to fail to accept calls if the user logged out and in again
925 changes: 0 additions & 925 deletions .yarn/releases/yarn-4.5.0.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.3.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-engines.cjs
spec: "https://raw.githubusercontent.com/devoto13/yarn-plugin-engines/main/bundles/%40yarnpkg/plugin-engines.js"

yarnPath: .yarn/releases/yarn-4.5.0.cjs
yarnPath: .yarn/releases/yarn-4.5.3.cjs
95 changes: 95 additions & 0 deletions apps/meteor/client/hooks/useHideRoomAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { RoomType } from '@rocket.chat/core-typings';
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import type { TranslationKey } from '@rocket.chat/ui-contexts';
import { useEndpoint, useSetModal, useToastMessageDispatch, useRouter, useUserId } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';
import React from 'react';
import { useTranslation } from 'react-i18next';

import { useDontAskAgain } from './useDontAskAgain';
import { UiTextContext } from '../../definition/IRoomTypeConfig';
import { GenericModalDoNotAskAgain } from '../components/GenericModal';
import { updateSubscription } from '../lib/mutationEffects/updateSubscription';
import { roomCoordinator } from '../lib/rooms/roomCoordinator';

type HideRoomProps = {
rid: string;
type: RoomType;
name: string;
};

type HideRoomOptions = {
redirect?: boolean;
};

const CLOSE_ENDPOINTS_BY_ROOM_TYPE = {
p: '/v1/groups.close', // private
c: '/v1/channels.close', // channel
d: '/v1/im.close', // direct message
v: '/v1/channels.close', // omnichannel voip
l: '/v1/channels.close', // livechat
} as const;

export const useHideRoomAction = ({ rid: roomId, type, name }: HideRoomProps, { redirect = true }: HideRoomOptions = {}) => {
const { t } = useTranslation();
const setModal = useSetModal();
const closeModal = useEffectEvent(() => setModal());
const dispatchToastMessage = useToastMessageDispatch();
const dontAskHideRoom = useDontAskAgain('hideRoom');
const router = useRouter();
const userId = useUserId();

const hideRoomEndpoint = useEndpoint('POST', CLOSE_ENDPOINTS_BY_ROOM_TYPE[type]);

const hideRoom = useMutation({
mutationFn: () => hideRoomEndpoint({ roomId }),
onMutate: async () => {
closeModal();

if (userId) {
return updateSubscription(roomId, userId, { alert: false, open: false });
}
},
onSuccess: () => {
if (redirect) {
router.navigate('/home');
}
},
onError: async (error, _, rollbackDocument) => {
dispatchToastMessage({ type: 'error', message: error });

if (userId && rollbackDocument) {
const { alert, open } = rollbackDocument;
updateSubscription(roomId, userId, { alert, open });
}
},
});

const handleHide = useEffectEvent(async () => {
const warnText = roomCoordinator.getRoomDirectives(type).getUiText(UiTextContext.HIDE_WARNING);

if (dontAskHideRoom) {
hideRoom.mutate();
return;
}

setModal(
<GenericModalDoNotAskAgain
variant='danger'
confirmText={t('Yes_hide_it')}
cancelText={t('Cancel')}
onClose={closeModal}
onCancel={closeModal}
onConfirm={() => hideRoom.mutate()}
dontAskAgain={{
action: 'hideRoom',
label: t('Hide_room'),
}}
>
{t(warnText as TranslationKey, { postProcess: 'sprintf', sprintf: [name] })}
</GenericModalDoNotAskAgain>,
);
});

return handleHide;
};
1 change: 1 addition & 0 deletions apps/meteor/client/lib/VideoConfManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export const VideoConfManager = new (class VideoConfManager extends Emitter<Vide
clearTimeout(call.acceptTimeout);
}
});
this.userId = undefined;
this.incomingDirectCalls.clear();
this.dismissedCalls.clear();
this.currentCallData = undefined;
Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/client/lib/mutationEffects/updateSubscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ISubscription } from '@rocket.chat/core-typings';

import { Subscriptions } from '../../../app/models/client';

export const updateSubscription = (roomId: string, userId: string, data: Partial<ISubscription>) => {
const oldDocument = Subscriptions.findOne({ 'rid': roomId, 'u._id': userId });

Subscriptions.update({ 'rid': roomId, 'u._id': userId }, { $set: data });

return oldDocument;
};
25 changes: 0 additions & 25 deletions apps/meteor/client/methods/hideRoom.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/client/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './hideRoom';
import './openRoom';
import './pinMessage';
import './unpinMessage';
Expand Down
51 changes: 3 additions & 48 deletions apps/meteor/client/sidebar/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import React, { memo, useMemo } from 'react';

import { LegacyRoomManager } from '../../app/ui-utils/client';
import { UiTextContext } from '../../definition/IRoomTypeConfig';
import { GenericModalDoNotAskAgain } from '../components/GenericModal';
import WarningModal from '../components/WarningModal';
import { useDontAskAgain } from '../hooks/useDontAskAgain';
import { useHideRoomAction } from '../hooks/useHideRoomAction';
import { roomCoordinator } from '../lib/rooms/roomCoordinator';
import { useOmnichannelPrioritiesMenu } from '../omnichannel/hooks/useOmnichannelPrioritiesMenu';

Expand All @@ -43,15 +42,6 @@ type RoomMenuProps = {
hideDefaultOptions: boolean;
};

const closeEndpoints = {
p: '/v1/groups.close',
c: '/v1/channels.close',
d: '/v1/im.close',

v: '/v1/channels.close',
l: '/v1/groups.close',
} as const;

const leaveEndpoints = {
p: '/v1/groups.leave',
c: '/v1/channels.leave',
Expand Down Expand Up @@ -84,9 +74,6 @@ const RoomMenu = ({
const canFavorite = useSetting('Favorite_Rooms');
const isFavorite = Boolean(subscription?.f);

const dontAskHideRoom = useDontAskAgain('hideRoom');

const hideRoom = useEndpoint('POST', closeEndpoints[type]);
const readMessages = useEndpoint('POST', '/v1/subscriptions.read');
const toggleFavorite = useEndpoint('POST', '/v1/rooms.favorite');
const leaveRoom = useEndpoint('POST', leaveEndpoints[type]);
Expand All @@ -103,6 +90,8 @@ const RoomMenu = ({

const queryClient = useQueryClient();

const handleHide = useHideRoomAction({ rid, type, name }, { redirect: false });

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -140,40 +129,6 @@ const RoomMenu = ({
);
});

const handleHide = useMutableCallback(async () => {
const hide = async (): Promise<void> => {
try {
await hideRoom({ roomId: rid });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
closeModal();
};

const warnText = roomCoordinator.getRoomDirectives(type).getUiText(UiTextContext.HIDE_WARNING);

if (dontAskHideRoom) {
return hide();
}

setModal(
<GenericModalDoNotAskAgain
variant='danger'
confirmText={t('Yes_hide_it')}
cancelText={t('Cancel')}
onClose={closeModal}
onCancel={closeModal}
onConfirm={hide}
dontAskAgain={{
action: 'hideRoom',
label: t('Hide_room'),
}}
>
{t(warnText as TranslationKey, name)}
</GenericModalDoNotAskAgain>,
);
});

const handleToggleRead = useMutableCallback(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);
Expand Down
51 changes: 3 additions & 48 deletions apps/meteor/client/sidebarv2/RoomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import React, { memo, useMemo } from 'react';

import { LegacyRoomManager } from '../../app/ui-utils/client';
import { UiTextContext } from '../../definition/IRoomTypeConfig';
import { GenericModalDoNotAskAgain } from '../components/GenericModal';
import WarningModal from '../components/WarningModal';
import { useDontAskAgain } from '../hooks/useDontAskAgain';
import { useHideRoomAction } from '../hooks/useHideRoomAction';
import { roomCoordinator } from '../lib/rooms/roomCoordinator';
import { useOmnichannelPrioritiesMenu } from '../omnichannel/hooks/useOmnichannelPrioritiesMenu';

Expand All @@ -43,15 +42,6 @@ type RoomMenuProps = {
hideDefaultOptions: boolean;
};

const closeEndpoints = {
p: '/v1/groups.close',
c: '/v1/channels.close',
d: '/v1/im.close',

v: '/v1/channels.close',
l: '/v1/groups.close',
} as const;

const leaveEndpoints = {
p: '/v1/groups.leave',
c: '/v1/channels.leave',
Expand Down Expand Up @@ -84,9 +74,6 @@ const RoomMenu = ({
const canFavorite = useSetting('Favorite_Rooms');
const isFavorite = Boolean(subscription?.f);

const dontAskHideRoom = useDontAskAgain('hideRoom');

const hideRoom = useEndpoint('POST', closeEndpoints[type]);
const readMessages = useEndpoint('POST', '/v1/subscriptions.read');
const toggleFavorite = useEndpoint('POST', '/v1/rooms.favorite');
const leaveRoom = useEndpoint('POST', leaveEndpoints[type]);
Expand All @@ -103,6 +90,8 @@ const RoomMenu = ({

const queryClient = useQueryClient();

const handleHide = useHideRoomAction({ rid, type, name }, { redirect: false });

const canLeave = ((): boolean => {
if (type === 'c' && !canLeaveChannel) {
return false;
Expand Down Expand Up @@ -140,40 +129,6 @@ const RoomMenu = ({
);
});

const handleHide = useEffectEvent(async () => {
const hide = async (): Promise<void> => {
try {
await hideRoom({ roomId: rid });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
closeModal();
};

const warnText = roomCoordinator.getRoomDirectives(type).getUiText(UiTextContext.HIDE_WARNING);

if (dontAskHideRoom) {
return hide();
}

setModal(
<GenericModalDoNotAskAgain
variant='danger'
confirmText={t('Yes_hide_it')}
cancelText={t('Cancel')}
onClose={closeModal}
onCancel={closeModal}
onConfirm={hide}
dontAskAgain={{
action: 'hideRoom',
label: t('Hide_room'),
}}
>
{t(warnText as TranslationKey, name)}
</GenericModalDoNotAskAgain>,
);
});

const handleToggleRead = useEffectEvent(async () => {
try {
queryClient.invalidateQueries(['sidebar/search/spotlight']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { FieldLabel as BaseFieldLabel, Box, Tag } from '@rocket.chat/fuselage';
import { FieldLabel, Box, Tag } from '@rocket.chat/fuselage';
import type { ComponentProps } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import { useHasLicenseModule } from '../../../hooks/useHasLicenseModule';

type FieldLabelProps = ComponentProps<typeof BaseFieldLabel> & {
type AppearanceFieldLabelProps = ComponentProps<typeof FieldLabel> & {
premium?: boolean;
children: string;
};

const FieldLabel = ({ children: label, premium = false }: FieldLabelProps) => {
const AppearanceFieldLabel = ({ children, premium = false }: AppearanceFieldLabelProps) => {
const { t } = useTranslation();
const hasLicense = useHasLicenseModule('livechat-enterprise');
const shouldDisableEnterprise = premium && !hasLicense;

if (!shouldDisableEnterprise) {
return <BaseFieldLabel>{label}</BaseFieldLabel>;
return <FieldLabel>{children}</FieldLabel>;
}

return (
<BaseFieldLabel>
<FieldLabel>
<Box is='span' mie={4}>
{label}
{children}
</Box>
<Tag variant='primary'>{t('Premium')}</Tag>
</BaseFieldLabel>
<Tag variant='featured'>{t('Premium')}</Tag>
</FieldLabel>
);
};

export default FieldLabel;
export default AppearanceFieldLabel;
Loading

0 comments on commit 32b78fd

Please sign in to comment.