chore: remove meteor.startup from permalink-star (#34022)
Co-authored-by: Tasso <tasso.evangelista@rocket.chat>pull/34050/head
parent
0d5f7943e5
commit
dbdb5215bd
@ -0,0 +1,48 @@ |
||||
import type { IMessage, ISubscription, IUser } from '@rocket.chat/core-typings'; |
||||
import { isE2EEMessage } from '@rocket.chat/core-typings'; |
||||
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
import { useTranslation } from 'react-i18next'; |
||||
|
||||
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; |
||||
import { getPermaLink } from '../../../lib/getPermaLink'; |
||||
|
||||
export const usePermalinkStar = ( |
||||
message: IMessage, |
||||
{ user, subscription }: { user: IUser | undefined; subscription: ISubscription | undefined }, |
||||
) => { |
||||
const { t } = useTranslation(); |
||||
|
||||
const dispatchToastMessage = useToastMessageDispatch(); |
||||
|
||||
const encrypted = isE2EEMessage(message); |
||||
|
||||
useEffect(() => { |
||||
if (!subscription) { |
||||
return; |
||||
} |
||||
|
||||
MessageAction.addButton({ |
||||
id: 'permalink-star', |
||||
icon: 'permalink', |
||||
label: 'Copy_link', |
||||
context: ['starred'], |
||||
async action() { |
||||
try { |
||||
const permalink = await getPermaLink(message._id); |
||||
navigator.clipboard.writeText(permalink); |
||||
dispatchToastMessage({ type: 'success', message: t('Copied') }); |
||||
} catch (e) { |
||||
dispatchToastMessage({ type: 'error', message: e }); |
||||
} |
||||
}, |
||||
order: 10, |
||||
group: 'menu', |
||||
disabled: () => encrypted, |
||||
}); |
||||
|
||||
return () => { |
||||
MessageAction.removeButton('permalink-star'); |
||||
}; |
||||
}, [dispatchToastMessage, encrypted, message._id, message.starred, subscription, t, user?._id]); |
||||
}; |
||||
@ -1,38 +0,0 @@ |
||||
import { isE2EEMessage } from '@rocket.chat/core-typings'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { MessageAction } from '../../../app/ui-utils/client'; |
||||
import { t } from '../../../app/utils/lib/i18n'; |
||||
import { getPermaLink } from '../../lib/getPermaLink'; |
||||
import { dispatchToastMessage } from '../../lib/toast'; |
||||
|
||||
Meteor.startup(() => { |
||||
MessageAction.addButton({ |
||||
id: 'permalink-star', |
||||
icon: 'permalink', |
||||
label: 'Copy_link', |
||||
// classes: 'clipboard',
|
||||
context: ['starred', 'threads', 'videoconf-threads'], |
||||
async action(_, { message }) { |
||||
try { |
||||
const permalink = await getPermaLink(message._id); |
||||
navigator.clipboard.writeText(permalink); |
||||
dispatchToastMessage({ type: 'success', message: t('Copied') }); |
||||
} catch (e) { |
||||
dispatchToastMessage({ type: 'error', message: e }); |
||||
} |
||||
}, |
||||
condition({ message, subscription, user }) { |
||||
if (subscription == null) { |
||||
return false; |
||||
} |
||||
|
||||
return Boolean(message.starred?.find((star) => star._id === user?._id)); |
||||
}, |
||||
order: 10, |
||||
group: 'menu', |
||||
disabled({ message }) { |
||||
return isE2EEMessage(message); |
||||
}, |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue