Chore: Remove `body` template (#28064)
parent
29d369acf2
commit
bcd9da449a
@ -1 +0,0 @@ |
||||
<body class="color-primary-font-color"></body> |
||||
@ -1,108 +0,0 @@ |
||||
import Clipboard from 'clipboard'; |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { Match } from 'meteor/check'; |
||||
import { Session } from 'meteor/session'; |
||||
import { Template } from 'meteor/templating'; |
||||
|
||||
import { APIClient, t } from '../../utils/client'; |
||||
import { settings } from '../../settings'; |
||||
import { ChatSubscription } from '../../models/client'; |
||||
import { imperativeModal } from '../../../client/lib/imperativeModal'; |
||||
import GenericModal from '../../../client/components/GenericModal'; |
||||
import { fireGlobalEvent } from '../../../client/lib/utils/fireGlobalEvent'; |
||||
import { isLayoutEmbedded } from '../../../client/lib/utils/isLayoutEmbedded'; |
||||
import { dispatchToastMessage } from '../../../client/lib/toast'; |
||||
import { rtrim } from '../../../lib/utils/stringUtils'; |
||||
import './body.html'; |
||||
|
||||
Template.body.onRendered(function () { |
||||
new Clipboard('.clipboard'); |
||||
|
||||
$(document.body).on('keydown', function (e) { |
||||
const unread = Session.get('unread'); |
||||
if (e.keyCode === 27 && (e.shiftKey === true || e.ctrlKey === true) && unread != null && unread !== '') { |
||||
e.preventDefault(); |
||||
e.stopPropagation(); |
||||
|
||||
const handleClearUnreadAllMessages = () => { |
||||
const subscriptions = ChatSubscription.find( |
||||
{ |
||||
open: true, |
||||
}, |
||||
{ |
||||
fields: { |
||||
unread: 1, |
||||
alert: 1, |
||||
rid: 1, |
||||
t: 1, |
||||
name: 1, |
||||
ls: 1, |
||||
}, |
||||
}, |
||||
); |
||||
|
||||
subscriptions.forEach((subscription) => { |
||||
if (subscription.alert || subscription.unread > 0) { |
||||
APIClient.post('/v1/subscriptions.read', { rid: subscription.rid, readThreads: true }).catch((err) => { |
||||
dispatchToastMessage({ type: 'error', message: err }); |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
imperativeModal.close(); |
||||
}; |
||||
|
||||
imperativeModal.open({ |
||||
component: GenericModal, |
||||
props: { |
||||
children: t('Are_you_sure_you_want_to_clear_all_unread_messages'), |
||||
variant: 'warning', |
||||
title: t('Clear_all_unreads_question'), |
||||
confirmText: t('Yes_clear_all'), |
||||
onClose: imperativeModal.close, |
||||
onCancel: imperativeModal.close, |
||||
onConfirm: handleClearUnreadAllMessages, |
||||
}, |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
const handleMessageLinkClick = (event) => { |
||||
const link = event.currentTarget; |
||||
if (link.origin === rtrim(Meteor.absoluteUrl(), '/') && /msg=([a-zA-Z0-9]+)/.test(link.search)) { |
||||
fireGlobalEvent('click-message-link', { link: link.pathname + link.search }); |
||||
} |
||||
}; |
||||
|
||||
this.autorun(() => { |
||||
if (isLayoutEmbedded()) { |
||||
$(document.body).on('click', 'a', handleMessageLinkClick); |
||||
} else { |
||||
$(document.body).off('click', 'a', handleMessageLinkClick); |
||||
} |
||||
}); |
||||
|
||||
this.autorun(function (c) { |
||||
const w = window; |
||||
const d = document; |
||||
const script = 'script'; |
||||
const l = 'dataLayer'; |
||||
const i = settings.get('GoogleTagManager_id'); |
||||
if (Match.test(i, String) && i.trim() !== '') { |
||||
c.stop(); |
||||
return (function (w, d, s, l, i) { |
||||
w[l] = w[l] || []; |
||||
w[l].push({ |
||||
'gtm.start': new Date().getTime(), |
||||
'event': 'gtm.js', |
||||
}); |
||||
const f = d.getElementsByTagName(s)[0]; |
||||
const j = d.createElement(s); |
||||
const dl = l !== 'dataLayer' ? `&l=${l}` : ''; |
||||
j.async = true; |
||||
j.src = `//www.googletagmanager.com/gtm.js?id=${i}${dl}`; |
||||
return f.parentNode.insertBefore(j, f); |
||||
})(w, d, script, l, i); |
||||
} |
||||
}); |
||||
}); |
||||
@ -1,2 +1 @@ |
||||
import './body'; |
||||
import './loading'; |
||||
@ -0,0 +1,35 @@ |
||||
import { useEndpoint } from '@rocket.chat/ui-contexts'; |
||||
import type { UseMutationOptions } from '@tanstack/react-query'; |
||||
import { useMutation } from '@tanstack/react-query'; |
||||
|
||||
import { ChatSubscription } from '../../../../app/models/client'; |
||||
|
||||
export const useClearUnreadAllMessagesMutation = (options?: Omit<UseMutationOptions<void, unknown, void, unknown>, 'mutationFn'>) => { |
||||
const readSubscription = useEndpoint('POST', '/v1/subscriptions.read'); |
||||
|
||||
return useMutation(async () => { |
||||
const promises = ChatSubscription.find( |
||||
{ |
||||
open: true, |
||||
}, |
||||
{ |
||||
fields: { |
||||
unread: 1, |
||||
alert: 1, |
||||
rid: 1, |
||||
t: 1, |
||||
name: 1, |
||||
ls: 1, |
||||
}, |
||||
}, |
||||
).map((subscription) => { |
||||
if (subscription.alert || subscription.unread > 0) { |
||||
return readSubscription({ rid: subscription.rid, readThreads: true }); |
||||
} |
||||
|
||||
return Promise.resolve(); |
||||
}); |
||||
|
||||
await Promise.all(promises); |
||||
}, options); |
||||
}; |
||||
@ -0,0 +1,58 @@ |
||||
import { useSession, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect, useRef } from 'react'; |
||||
|
||||
import GenericModal from '../../../components/GenericModal'; |
||||
import { imperativeModal } from '../../../lib/imperativeModal'; |
||||
import { useClearUnreadAllMessagesMutation } from './useClearUnreadAllMessagesMutation'; |
||||
|
||||
export const useEscapeKeyStroke = () => { |
||||
const dispatchToastMessage = useToastMessageDispatch(); |
||||
const t = useTranslation(); |
||||
|
||||
const clearUnreadAllMessagesMutation = useClearUnreadAllMessagesMutation({ |
||||
onError: (error) => { |
||||
dispatchToastMessage({ type: 'error', message: error }); |
||||
}, |
||||
onMutate: () => { |
||||
imperativeModal.close(); |
||||
}, |
||||
}); |
||||
|
||||
const { current: unread } = useRef(useSession('unread')); |
||||
|
||||
useEffect(() => { |
||||
const handleKeyDown = (event: KeyboardEvent) => { |
||||
if ( |
||||
event.code !== 'Escape' || |
||||
!(event.shiftKey === true || event.ctrlKey === true) || |
||||
unread === undefined || |
||||
unread === null || |
||||
unread === '' |
||||
) { |
||||
return; |
||||
} |
||||
|
||||
event.preventDefault(); |
||||
event.stopPropagation(); |
||||
|
||||
imperativeModal.open({ |
||||
component: GenericModal, |
||||
props: { |
||||
children: t('Are_you_sure_you_want_to_clear_all_unread_messages'), |
||||
variant: 'warning', |
||||
title: t('Clear_all_unreads_question'), |
||||
confirmText: t('Yes_clear_all'), |
||||
onClose: imperativeModal.close, |
||||
onCancel: imperativeModal.close, |
||||
onConfirm: clearUnreadAllMessagesMutation.mutate, |
||||
}, |
||||
}); |
||||
}; |
||||
|
||||
document.body.addEventListener('keydown', handleKeyDown); |
||||
|
||||
return () => { |
||||
document.body.removeEventListener('keydown', handleKeyDown); |
||||
}; |
||||
}, [clearUnreadAllMessagesMutation.mutate, dispatchToastMessage, t, unread]); |
||||
}; |
||||
@ -0,0 +1,29 @@ |
||||
import { useSetting } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
export const useGoogleTagManager = () => { |
||||
const i = useSetting<string>('GoogleTagManager_id'); |
||||
|
||||
useEffect(() => { |
||||
if (typeof i !== 'string' || i.trim() === '') { |
||||
return; |
||||
} |
||||
|
||||
const w: Window & { dataLayer?: { 'gtm.start': number; 'event': string }[] } = window; |
||||
|
||||
w.dataLayer = w.dataLayer || []; |
||||
w.dataLayer.push({ |
||||
'gtm.start': new Date().getTime(), |
||||
'event': 'gtm.js', |
||||
}); |
||||
const f = document.getElementsByTagName('script')[0]; |
||||
const j = document.createElement('script'); |
||||
j.async = true; |
||||
j.src = `//www.googletagmanager.com/gtm.js?id=${i}`; |
||||
f.parentNode?.insertBefore(j, f); |
||||
|
||||
return () => { |
||||
f.parentNode?.removeChild(j); |
||||
}; |
||||
}, [i]); |
||||
}; |
||||
@ -0,0 +1,39 @@ |
||||
import { useAbsoluteUrl, useLayout } from '@rocket.chat/ui-contexts'; |
||||
import { useEffect } from 'react'; |
||||
|
||||
import { fireGlobalEvent } from '../../../lib/utils/fireGlobalEvent'; |
||||
|
||||
export const useMessageLinkClicks = () => { |
||||
const absoluteUrl = useAbsoluteUrl(); |
||||
const { isEmbedded: embeddedLayout } = useLayout(); |
||||
|
||||
useEffect(() => { |
||||
if (!embeddedLayout) { |
||||
return; |
||||
} |
||||
|
||||
const handleMessageLinkClick = (event: Event) => { |
||||
const element = event.currentTarget as Element | null; |
||||
|
||||
if (!element || !(element instanceof HTMLElement)) { |
||||
return; |
||||
} |
||||
|
||||
if (!(element instanceof HTMLAnchorElement)) { |
||||
return; |
||||
} |
||||
|
||||
if (element.origin !== absoluteUrl('').replace(/\/+$/, '') || !/msg=([a-zA-Z0-9]+)/.test(element.search)) { |
||||
return; |
||||
} |
||||
|
||||
fireGlobalEvent('click-message-link', { link: element.pathname + element.search }); |
||||
}; |
||||
|
||||
document.body.addEventListener('click', handleMessageLinkClick); |
||||
|
||||
return () => { |
||||
document.body.removeEventListener('click', handleMessageLinkClick); |
||||
}; |
||||
}, [absoluteUrl, embeddedLayout]); |
||||
}; |
||||
Loading…
Reference in new issue