logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

mention_link.js (4089B)


  1. import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
  2. import { mapGetters, mapState } from 'vuex'
  3. import { highlightClass, highlightStyle } from '../../services/user_highlighter/user_highlighter.js'
  4. import UserAvatar from '../user_avatar/user_avatar.vue'
  5. import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
  6. import { defineAsyncComponent } from 'vue'
  7. import { library } from '@fortawesome/fontawesome-svg-core'
  8. import {
  9. faAt
  10. } from '@fortawesome/free-solid-svg-icons'
  11. library.add(
  12. faAt
  13. )
  14. const MentionLink = {
  15. name: 'MentionLink',
  16. components: {
  17. UserAvatar,
  18. UnicodeDomainIndicator,
  19. UserPopover: defineAsyncComponent(() => import('../user_popover/user_popover.vue'))
  20. },
  21. props: {
  22. url: {
  23. required: true,
  24. type: String
  25. },
  26. content: {
  27. required: true,
  28. type: String
  29. },
  30. userId: {
  31. required: false,
  32. type: String
  33. },
  34. userScreenName: {
  35. required: false,
  36. type: String
  37. }
  38. },
  39. data () {
  40. return {
  41. hasSelection: false
  42. }
  43. },
  44. methods: {
  45. onClick () {
  46. if (this.shouldShowTooltip) return
  47. const link = generateProfileLink(
  48. this.userId || this.user.id,
  49. this.userScreenName || this.user.screen_name
  50. )
  51. this.$router.push(link)
  52. },
  53. handleSelection () {
  54. this.hasSelection = document.getSelection().containsNode(this.$refs.full, true)
  55. }
  56. },
  57. mounted () {
  58. document.addEventListener('selectionchange', this.handleSelection)
  59. },
  60. unmounted () {
  61. document.removeEventListener('selectionchange', this.handleSelection)
  62. },
  63. computed: {
  64. user () {
  65. return this.url && this.$store && this.$store.getters.findUserByUrl(this.url)
  66. },
  67. isYou () {
  68. // FIXME why user !== currentUser???
  69. return this.user && this.user.id === this.currentUser.id
  70. },
  71. userName () {
  72. return this.user && this.userNameFullUi.split('@')[0]
  73. },
  74. serverName () {
  75. // XXX assumed that domain does not contain @
  76. return this.user && (this.userNameFullUi.split('@')[1] || this.$store.getters.instanceDomain)
  77. },
  78. userNameFull () {
  79. return this.user && this.user.screen_name
  80. },
  81. userNameFullUi () {
  82. return this.user && this.user.screen_name_ui
  83. },
  84. highlight () {
  85. return this.user && this.mergedConfig.highlight[this.user.screen_name]
  86. },
  87. highlightType () {
  88. return this.highlight && ('-' + this.highlight.type)
  89. },
  90. highlightClass () {
  91. if (this.highlight) return highlightClass(this.user)
  92. },
  93. style () {
  94. if (this.highlight) {
  95. const {
  96. backgroundColor,
  97. backgroundPosition,
  98. backgroundImage,
  99. ...rest
  100. } = highlightStyle(this.highlight)
  101. return rest
  102. }
  103. },
  104. classnames () {
  105. return [
  106. {
  107. '-you': this.isYou && this.shouldBoldenYou,
  108. '-highlighted': this.highlight,
  109. '-has-selection': this.hasSelection
  110. },
  111. this.highlightType
  112. ]
  113. },
  114. useAtIcon () {
  115. return this.mergedConfig.useAtIcon
  116. },
  117. isRemote () {
  118. return this.userName !== this.userNameFull
  119. },
  120. shouldShowFullUserName () {
  121. const conf = this.mergedConfig.mentionLinkDisplay
  122. if (conf === 'short') {
  123. return false
  124. } else if (conf === 'full') {
  125. return true
  126. } else { // full_for_remote
  127. return this.isRemote
  128. }
  129. },
  130. shouldShowTooltip () {
  131. return this.mergedConfig.mentionLinkShowTooltip
  132. },
  133. shouldShowAvatar () {
  134. return this.mergedConfig.mentionLinkShowAvatar
  135. },
  136. shouldShowYous () {
  137. return this.mergedConfig.mentionLinkShowYous
  138. },
  139. shouldBoldenYou () {
  140. return this.mergedConfig.mentionLinkBoldenYou
  141. },
  142. shouldFadeDomain () {
  143. return this.mergedConfig.mentionLinkFadeDomain
  144. },
  145. ...mapGetters(['mergedConfig']),
  146. ...mapState({
  147. currentUser: state => state.users.currentUser
  148. })
  149. }
  150. }
  151. export default MentionLink