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

feat: Added new setting 'Hide conversation after closing' #30591

Merged
merged 7 commits into from
Oct 18, 2023
Merged
5 changes: 5 additions & 0 deletions .changeset/thick-spoons-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Added new Omnichannel setting 'Hide conversation after closing'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useRouter, useSetting } from '@rocket.chat/ui-contexts';
import { useCallback } from 'react';

export const useOmnichannelCloseRoute = () => {
const hideConversationAfterClosing = useSetting('Omnichannel_hide_conversation_after_closing');
const router = useRouter();

const navigateHome = useCallback(() => {
if (!hideConversationAfterClosing) {
return;
}

const routeName = router.getRouteName();

if (routeName === 'omnichannel-current-chats') {
router.navigate({ name: 'omnichannel-current-chats' });
} else {
router.navigate({ name: 'home' });
}
}, [hideConversationAfterClosing, router]);

return { navigateHome };
};
37 changes: 27 additions & 10 deletions apps/meteor/client/views/room/body/hooks/useGoToHomeOnRemoved.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { isOmnichannelRoom, type IRoom } from '@rocket.chat/core-typings';
import { useRoute, useStream, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';

const IGNORED_ROOMS = ['l', 'v'];
import { useOmnichannelCloseRoute } from '../../../../hooks/omnichannel/useOmnichannelCloseRoute';

export function useGoToHomeOnRemoved(room: IRoom, userId: string | undefined): void {
const homeRouter = useRoute('home');
const queryClient = useQueryClient();
const dispatchToastMessage = useToastMessageDispatch();
const subscribeToNotifyUser = useStream('notify-user');
const t = useTranslation();
const { navigateHome } = useOmnichannelCloseRoute();

useEffect(() => {
if (!userId) {
Expand All @@ -21,19 +22,35 @@ export function useGoToHomeOnRemoved(room: IRoom, userId: string | undefined): v
if (event === 'removed' && subscription.rid === room._id) {
queryClient.invalidateQueries(['rooms', room._id]);

if (!IGNORED_ROOMS.includes(room.t)) {
dispatchToastMessage({
type: 'info',
message: t('You_have_been_removed_from__roomName_', {
roomName: room?.fname || room?.name || '',
}),
});
if (isOmnichannelRoom(room)) {
navigateHome();
return;
}

dispatchToastMessage({
type: 'info',
message: t('You_have_been_removed_from__roomName_', {
roomName: room?.fname || room?.name || '',
}),
});

homeRouter.push({});
}
});

return unSubscribeFromNotifyUser;
}, [userId, homeRouter, subscribeToNotifyUser, room._id, room?.fname, room?.name, t, dispatchToastMessage, queryClient, room.t]);
}, [
userId,
homeRouter,
subscribeToNotifyUser,
room._id,
room?.fname,
room?.name,
t,
dispatchToastMessage,
queryClient,
room.t,
room,
navigateHome,
]);
}
1 change: 1 addition & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,7 @@
"Omnichannel_sorting_disclaimer": "Omnichannel conversations are sorted by {{sortingMechanism}}, edit a room to apply.",
"Livechat_online": "Omnichannel on-line",
"Omnichannel_placed_chat_on_hold": "Chat On Hold: {{comment}}",
"Omnichannel_hide_conversation_after_closing": "Hide conversation after closing",
"Livechat_Queue": "Omnichannel Queue",
"Livechat_registration_form": "Registration Form",
"Livechat_registration_form_message": "Registration Form Message",
Expand Down
Loading