logo

pleroma-fe

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

mention_link.js (4215B)


  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. if (this.$refs.full) {
  55. this.hasSelection = document.getSelection().containsNode(this.$refs.full, true)
  56. }
  57. }
  58. },
  59. mounted () {
  60. document.addEventListener('selectionchange', this.handleSelection)
  61. },
  62. unmounted () {
  63. document.removeEventListener('selectionchange', this.handleSelection)
  64. },
  65. computed: {
  66. user () {
  67. return this.url && this.$store && this.$store.getters.findUserByUrl(this.url)
  68. },
  69. isYou () {
  70. // FIXME why user !== currentUser???
  71. return this.user && this.user.id === this.currentUser.id
  72. },
  73. userName () {
  74. return this.user && this.userNameFullUi.split('@')[0]
  75. },
  76. serverName () {
  77. // XXX assumed that domain does not contain @
  78. return this.user && (this.userNameFullUi.split('@')[1] || this.$store.getters.instanceDomain)
  79. },
  80. userNameFull () {
  81. return this.user && this.user.screen_name
  82. },
  83. userNameFullUi () {
  84. return this.user && this.user.screen_name_ui
  85. },
  86. highlight () {
  87. return this.user && this.mergedConfig.highlight[this.user.screen_name]
  88. },
  89. highlightType () {
  90. return this.highlight && ('-' + this.highlight.type)
  91. },
  92. highlightClass () {
  93. if (this.highlight) return highlightClass(this.user)
  94. },
  95. style () {
  96. if (this.highlight) {
  97. /* eslint-disable no-unused-vars */
  98. const {
  99. backgroundColor,
  100. backgroundPosition,
  101. backgroundImage,
  102. ...rest
  103. } = highlightStyle(this.highlight)
  104. /* eslint-enable no-unused-vars */
  105. return rest
  106. }
  107. },
  108. classnames () {
  109. return [
  110. {
  111. '-you': this.isYou && this.shouldBoldenYou,
  112. '-highlighted': this.highlight,
  113. '-has-selection': this.hasSelection
  114. },
  115. this.highlightType
  116. ]
  117. },
  118. useAtIcon () {
  119. return this.mergedConfig.useAtIcon
  120. },
  121. isRemote () {
  122. return this.userName !== this.userNameFull
  123. },
  124. shouldShowFullUserName () {
  125. const conf = this.mergedConfig.mentionLinkDisplay
  126. if (conf === 'short') {
  127. return false
  128. } else if (conf === 'full') {
  129. return true
  130. } else { // full_for_remote
  131. return this.isRemote
  132. }
  133. },
  134. shouldShowTooltip () {
  135. return this.mergedConfig.mentionLinkShowTooltip
  136. },
  137. shouldShowAvatar () {
  138. return this.mergedConfig.mentionLinkShowAvatar
  139. },
  140. shouldShowYous () {
  141. return this.mergedConfig.mentionLinkShowYous
  142. },
  143. shouldBoldenYou () {
  144. return this.mergedConfig.mentionLinkBoldenYou
  145. },
  146. shouldFadeDomain () {
  147. return this.mergedConfig.mentionLinkFadeDomain
  148. },
  149. ...mapGetters(['mergedConfig']),
  150. ...mapState({
  151. currentUser: state => state.users.currentUser
  152. })
  153. }
  154. }
  155. export default MentionLink