forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove meteor.startup from pin-message (RocketChat#34019)
- Loading branch information
1 parent
90a2c3c
commit a11f41e
Showing
6 changed files
with
80 additions
and
55 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
apps/meteor/client/components/message/hooks/usePinMessageMutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; | ||
import { useQueryClient, useMutation } from '@tanstack/react-query'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { sdk } from '../../../../app/utils/client/lib/SDKClient'; | ||
import { roomsQueryKeys } from '../../../lib/queryKeys'; | ||
|
||
export const usePinMessageMutation = () => { | ||
const { t } = useTranslation(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: async (message: IMessage) => { | ||
await sdk.call('pinMessage', message); | ||
}, | ||
onSuccess: (_data) => { | ||
dispatchToastMessage({ type: 'success', message: t('Message_has_been_pinned') }); | ||
}, | ||
onError: (error) => { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
}, | ||
onSettled: (_data, _error, message) => { | ||
queryClient.invalidateQueries(roomsQueryKeys.pinnedMessages(message.rid)); | ||
queryClient.invalidateQueries(roomsQueryKeys.messageActions(message.rid, message._id)); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
apps/meteor/client/components/message/toolbar/usePinMessageAction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { IMessage, IRoom, ISubscription } from '@rocket.chat/core-typings'; | ||
import { isOmnichannelRoom } from '@rocket.chat/core-typings'; | ||
import { useSetting, useSetModal, usePermission } from '@rocket.chat/ui-contexts'; | ||
import React, { useEffect } from 'react'; | ||
|
||
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; | ||
import PinMessageModal from '../../../views/room/modals/PinMessageModal'; | ||
import { usePinMessageMutation } from '../hooks/usePinMessageMutation'; | ||
|
||
export const usePinMessageAction = ( | ||
message: IMessage, | ||
{ room, subscription }: { room: IRoom; subscription: ISubscription | undefined }, | ||
) => { | ||
const setModal = useSetModal(); | ||
|
||
const allowPinning = useSetting('Message_AllowPinning'); | ||
const hasPermission = usePermission('pin-message', room._id); | ||
const { mutateAsync: pinMessage } = usePinMessageMutation(); | ||
|
||
useEffect(() => { | ||
if (!allowPinning || isOmnichannelRoom(room) || !hasPermission || message.pinned || !subscription) { | ||
return; | ||
} | ||
|
||
const onConfirm = async () => { | ||
pinMessage(message); | ||
setModal(null); | ||
}; | ||
|
||
MessageAction.addButton({ | ||
id: 'pin-message', | ||
icon: 'pin', | ||
label: 'Pin', | ||
type: 'interaction', | ||
context: ['pinned', 'message', 'message-mobile', 'threads', 'direct', 'videoconf', 'videoconf-threads'], | ||
async action() { | ||
setModal(<PinMessageModal message={message} onConfirm={onConfirm} onCancel={() => setModal(null)} />); | ||
}, | ||
order: 2, | ||
group: 'menu', | ||
}); | ||
|
||
return () => { | ||
MessageAction.removeButton('pin-message'); | ||
}; | ||
}, [allowPinning, hasPermission, message, pinMessage, room, setModal, subscription]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.