ticket-article.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { TicketArticle } from '#shared/graphql/types.ts'
  3. import { i18n } from '#shared/i18n.ts'
  4. import { textCleanup, textTruncate } from '#shared/utils/helpers.ts'
  5. import type { ActivityMessageBuilder } from '../types.ts'
  6. const path = (metaObject: TicketArticle) => {
  7. return `tickets/${metaObject.ticket.internalId}#article-${metaObject.internalId}`
  8. }
  9. const messageText = (
  10. type: string,
  11. authorName: string,
  12. metaObject?: TicketArticle,
  13. ): Maybe<string> => {
  14. if (!metaObject) {
  15. return i18n.t('You can no longer see the ticket.')
  16. }
  17. const ticketTitle = metaObject.ticket?.title || '-'
  18. switch (type) {
  19. case 'create':
  20. return i18n.t('%s created article for |%s|', authorName, ticketTitle)
  21. case 'update':
  22. return i18n.t('%s updated article for |%s|', authorName, ticketTitle)
  23. case 'update.reaction':
  24. return i18n.t(
  25. '%s reacted with a %s to message from %s |%s|',
  26. metaObject.preferences?.whatsapp?.reaction?.author || '-',
  27. metaObject.preferences?.whatsapp?.reaction?.emoji || '-',
  28. authorName,
  29. textTruncate(textCleanup(metaObject.bodyWithUrls)) || '-',
  30. )
  31. default:
  32. return null
  33. }
  34. }
  35. export default <ActivityMessageBuilder>{
  36. messageText,
  37. path,
  38. model: 'Ticket::Article',
  39. }