ActivityMessage.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 log from '#shared/utils/log.ts'
  6. import type { ActivityMessageMetaObject } from '#shared/graphql/types.ts'
  7. import { userDisplayName } from '#shared/entities/user/utils/getUserDisplayName.ts'
  8. import { markup } from '#shared/utils/markup.ts'
  9. import CommonUserAvatar from '../CommonUserAvatar/CommonUserAvatar.vue'
  10. import CommonAvatar from '../CommonAvatar/CommonAvatar.vue'
  11. import type { AvatarUser } from '../CommonUserAvatar/types.ts'
  12. import { activityMessageBuilder } from './builders/index.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. (e: 'seen'): void
  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" />
  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="mt-1 flex text-gray">
  57. <CommonDateTime :date-time="createdAt" type="relative" />
  58. </div>
  59. </div>
  60. </component>
  61. </template>