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 (4128B)


  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. const {
  98. backgroundColor,
  99. backgroundPosition,
  100. backgroundImage,
  101. ...rest
  102. } = highlightStyle(this.highlight)
  103. return rest
  104. }
  105. },
  106. classnames () {
  107. return [
  108. {
  109. '-you': this.isYou && this.shouldBoldenYou,
  110. '-highlighted': this.highlight,
  111. '-has-selection': this.hasSelection
  112. },
  113. this.highlightType
  114. ]
  115. },
  116. useAtIcon () {
  117. return this.mergedConfig.useAtIcon
  118. },
  119. isRemote () {
  120. return this.userName !== this.userNameFull
  121. },
  122. shouldShowFullUserName () {
  123. const conf = this.mergedConfig.mentionLinkDisplay
  124. if (conf === 'short') {
  125. return false
  126. } else if (conf === 'full') {
  127. return true
  128. } else { // full_for_remote
  129. return this.isRemote
  130. }
  131. },
  132. shouldShowTooltip () {
  133. return this.mergedConfig.mentionLinkShowTooltip
  134. },
  135. shouldShowAvatar () {
  136. return this.mergedConfig.mentionLinkShowAvatar
  137. },
  138. shouldShowYous () {
  139. return this.mergedConfig.mentionLinkShowYous
  140. },
  141. shouldBoldenYou () {
  142. return this.mergedConfig.mentionLinkBoldenYou
  143. },
  144. shouldFadeDomain () {
  145. return this.mergedConfig.mentionLinkFadeDomain
  146. },
  147. ...mapGetters(['mergedConfig']),
  148. ...mapState({
  149. currentUser: state => state.users.currentUser
  150. })
  151. }
  152. }
  153. export default MentionLink