useActivityMessage.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, type Ref } from 'vue'
  3. import { userDisplayName } from '#shared/entities/user/utils/getUserDisplayName.ts'
  4. import type { OnlineNotification } from '#shared/graphql/types.ts'
  5. import log from '#shared/utils/log.ts'
  6. import { activityMessageBuilder } from './activityMessageBuilder/index.ts'
  7. export const useActivityMessage = (
  8. activity: Readonly<Ref<OnlineNotification>>,
  9. ) => {
  10. const builder = computed(
  11. () => activityMessageBuilder[activity.value.objectName],
  12. )
  13. if (!builder.value) {
  14. log.error(`Object missing ${activity.value.objectName}.`)
  15. }
  16. const message = builder.value?.messageText(
  17. activity.value.typeName,
  18. activity.value.createdBy ? userDisplayName(activity.value.createdBy) : '',
  19. activity.value.metaObject,
  20. )
  21. const link = activity.value.metaObject
  22. ? builder.value?.path(activity.value.metaObject)
  23. : undefined
  24. if (builder.value && !message) {
  25. log.error(
  26. `Unknow action for (${activity.value.objectName}/${activity.value.typeName}), extend activityMessages() of model.`,
  27. )
  28. }
  29. return { link, builder, message }
  30. }