ActivityMessage.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. /* eslint-disable vue/no-v-html */
  4. import { computed } from 'vue'
  5. import { userDisplayName } from '#shared/entities/user/utils/getUserDisplayName.ts'
  6. import type { ActivityMessageMetaObject } from '#shared/graphql/types.ts'
  7. import log from '#shared/utils/log.ts'
  8. import { markup } from '#shared/utils/markup.ts'
  9. import CommonAvatar from '../CommonAvatar/CommonAvatar.vue'
  10. import CommonUserAvatar from '../CommonUserAvatar/CommonUserAvatar.vue'
  11. import { activityMessageBuilder } from './builders/index.ts'
  12. import type { AvatarUser } from '../CommonUserAvatar/types.ts'
  13. export interface Props {
  14. typeName: string
  15. objectName: string
  16. metaObject?: Maybe<ActivityMessageMetaObject>
  17. createdAt: string
  18. createdBy?: Maybe<AvatarUser>
  19. }
  20. const props = defineProps<Props>()
  21. const builder = computed(() => activityMessageBuilder[props.objectName])
  22. if (!builder.value) {
  23. log.error(`Object missing ${props.objectName}.`)
  24. }
  25. const message = builder.value?.messageText(
  26. props.typeName,
  27. props.createdBy ? userDisplayName(props.createdBy) : '',
  28. props.metaObject,
  29. )
  30. const link = props.metaObject
  31. ? builder.value?.path(props.metaObject)
  32. : undefined
  33. if (builder.value && !message) {
  34. log.error(
  35. `Unknow action for (${props.objectName}/${props.typeName}), extend activityMessages() of model.`,
  36. )
  37. }
  38. defineEmits<{
  39. seen: []
  40. }>()
  41. </script>
  42. <template>
  43. <component
  44. :is="link ? 'CommonLink' : 'div'"
  45. v-if="builder"
  46. class="flex flex-1 border-b border-white/10 py-4"
  47. :link="link"
  48. @click="!link ? $emit('seen') : undefined"
  49. >
  50. <div class="flex items-center ltr:mr-4 rtl:ml-4">
  51. <CommonUserAvatar v-if="createdBy" :entity="createdBy" no-indicator />
  52. <CommonAvatar v-else class="bg-red-bright text-white" icon="lock" />
  53. </div>
  54. <div class="flex flex-col">
  55. <div class="text-lg leading-5" v-html="markup(message)" />
  56. <div class="text-gray mt-1 flex">
  57. <CommonDateTime :date-time="createdAt" type="relative" />
  58. </div>
  59. </div>
  60. </component>
  61. </template>