-
Notifications
You must be signed in to change notification settings - Fork 11k
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 unstar-message (#34018)
Co-authored-by: Tasso <[email protected]>
- Loading branch information
1 parent
fe9be01
commit 0d5f794
Showing
8 changed files
with
79 additions
and
45 deletions.
There are no files selected for viewing
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
33 changes: 33 additions & 0 deletions
33
apps/meteor/client/components/message/hooks/useUnstarMessageMutation.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,33 @@ | ||
import type { IMessage } from '@rocket.chat/core-typings'; | ||
import { useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts'; | ||
import { useQueryClient, useMutation } from '@tanstack/react-query'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { toggleStarredMessage } from '../../../lib/mutationEffects/starredMessage'; | ||
import { roomsQueryKeys } from '../../../lib/queryKeys'; | ||
|
||
export const useUnstarMessageMutation = () => { | ||
const { t } = useTranslation(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
const unstarMessage = useEndpoint('POST', '/v1/chat.unStarMessage'); | ||
|
||
return useMutation({ | ||
mutationFn: async (message: IMessage) => { | ||
await unstarMessage({ messageId: message._id }); | ||
}, | ||
onSuccess: (_data, message) => { | ||
toggleStarredMessage(message, false); | ||
dispatchToastMessage({ type: 'success', message: t('Message_has_been_unstarred') }); | ||
}, | ||
onError: (error) => { | ||
dispatchToastMessage({ type: 'error', message: error }); | ||
}, | ||
onSettled: (_data, _error, message) => { | ||
queryClient.invalidateQueries(roomsQueryKeys.starredMessages(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
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
40 changes: 40 additions & 0 deletions
40
apps/meteor/client/components/message/toolbar/useUnstarMessageAction.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,40 @@ | ||
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings'; | ||
import { isOmnichannelRoom } from '@rocket.chat/core-typings'; | ||
import { useSetting } from '@rocket.chat/ui-contexts'; | ||
import { useEffect } from 'react'; | ||
|
||
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; | ||
import { useUnstarMessageMutation } from '../hooks/useUnstarMessageMutation'; | ||
|
||
export const useUnstarMessageAction = (message: IMessage, { room, user }: { room: IRoom; user: IUser | undefined }) => { | ||
const allowStarring = useSetting('Message_AllowStarring'); | ||
|
||
const { mutateAsync: unstarMessage } = useUnstarMessageMutation(); | ||
|
||
useEffect(() => { | ||
if (!allowStarring || isOmnichannelRoom(room)) { | ||
return; | ||
} | ||
|
||
if (!Array.isArray(message.starred) || message.starred.every((star) => star._id !== user?._id)) { | ||
return; | ||
} | ||
|
||
MessageAction.addButton({ | ||
id: 'unstar-message', | ||
icon: 'star', | ||
label: 'Unstar_Message', | ||
type: 'interaction', | ||
context: ['starred', 'message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'], | ||
async action() { | ||
await unstarMessage(message); | ||
}, | ||
order: 3, | ||
group: 'menu', | ||
}); | ||
|
||
return () => { | ||
MessageAction.removeButton('unstar-message'); | ||
}; | ||
}, [allowStarring, message, room, unstarMessage, user?._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
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.