logo

pleroma-fe

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

user_card.js (7165B)


  1. import { unitToSeconds } from 'src/services/date_utils/date_utils.js'
  2. import UserAvatar from '../user_avatar/user_avatar.vue'
  3. import RemoteFollow from '../remote_follow/remote_follow.vue'
  4. import ProgressButton from '../progress_button/progress_button.vue'
  5. import FollowButton from '../follow_button/follow_button.vue'
  6. import ModerationTools from '../moderation_tools/moderation_tools.vue'
  7. import AccountActions from '../account_actions/account_actions.vue'
  8. import UserNote from '../user_note/user_note.vue'
  9. import Select from '../select/select.vue'
  10. import UserLink from '../user_link/user_link.vue'
  11. import RichContent from 'src/components/rich_content/rich_content.jsx'
  12. import ConfirmModal from '../confirm_modal/confirm_modal.vue'
  13. import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
  14. import { mapGetters } from 'vuex'
  15. import { library } from '@fortawesome/fontawesome-svg-core'
  16. import {
  17. faBell,
  18. faRss,
  19. faSearchPlus,
  20. faExternalLinkAlt,
  21. faEdit,
  22. faTimes,
  23. faExpandAlt
  24. } from '@fortawesome/free-solid-svg-icons'
  25. library.add(
  26. faRss,
  27. faBell,
  28. faSearchPlus,
  29. faExternalLinkAlt,
  30. faEdit,
  31. faTimes,
  32. faExpandAlt
  33. )
  34. export default {
  35. props: [
  36. 'userId',
  37. 'switcher',
  38. 'selected',
  39. 'hideBio',
  40. 'rounded',
  41. 'bordered',
  42. 'avatarAction', // default - open profile, 'zoom' - zoom, function - call function
  43. 'onClose',
  44. 'hasNoteEditor'
  45. ],
  46. data () {
  47. return {
  48. followRequestInProgress: false,
  49. betterShadow: this.$store.state.interface.browserSupport.cssFilter,
  50. showingConfirmMute: false,
  51. muteExpiryAmount: 0,
  52. muteExpiryUnit: 'minutes'
  53. }
  54. },
  55. created () {
  56. this.$store.dispatch('fetchUserRelationship', this.user.id)
  57. },
  58. computed: {
  59. user () {
  60. return this.$store.getters.findUser(this.userId)
  61. },
  62. relationship () {
  63. return this.$store.getters.relationship(this.userId)
  64. },
  65. classes () {
  66. return [{
  67. '-rounded-t': this.rounded === 'top', // set border-top-left-radius and border-top-right-radius
  68. '-rounded': this.rounded === true, // set border-radius for all sides
  69. '-bordered': this.bordered === true, // set border for all sides
  70. '-popover': !!this.onClose // set popover rounding
  71. }]
  72. },
  73. style () {
  74. return {
  75. backgroundImage: [
  76. 'linear-gradient(to bottom, var(--profileTint), var(--profileTint))',
  77. `url(${this.user.cover_photo})`
  78. ].join(', ')
  79. }
  80. },
  81. isOtherUser () {
  82. return this.user.id !== this.$store.state.users.currentUser.id
  83. },
  84. subscribeUrl () {
  85. // eslint-disable-next-line no-undef
  86. const serverUrl = new URL(this.user.statusnet_profile_url)
  87. return `${serverUrl.protocol}//${serverUrl.host}/main/ostatus`
  88. },
  89. loggedIn () {
  90. return this.$store.state.users.currentUser
  91. },
  92. dailyAvg () {
  93. const days = Math.ceil((new Date() - new Date(this.user.created_at)) / (60 * 60 * 24 * 1000))
  94. return Math.round(this.user.statuses_count / days)
  95. },
  96. userHighlightType: {
  97. get () {
  98. const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name]
  99. return (data && data.type) || 'disabled'
  100. },
  101. set (type) {
  102. const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name]
  103. if (type !== 'disabled') {
  104. this.$store.dispatch('setHighlight', { user: this.user.screen_name, color: (data && data.color) || '#FFFFFF', type })
  105. } else {
  106. this.$store.dispatch('setHighlight', { user: this.user.screen_name, color: undefined })
  107. }
  108. },
  109. ...mapGetters(['mergedConfig'])
  110. },
  111. userHighlightColor: {
  112. get () {
  113. const data = this.$store.getters.mergedConfig.highlight[this.user.screen_name]
  114. return data && data.color
  115. },
  116. set (color) {
  117. this.$store.dispatch('setHighlight', { user: this.user.screen_name, color })
  118. }
  119. },
  120. visibleRole () {
  121. const rights = this.user.rights
  122. if (!rights) { return }
  123. const validRole = rights.admin || rights.moderator
  124. const roleTitle = rights.admin ? 'admin' : 'moderator'
  125. return validRole && roleTitle
  126. },
  127. hideFollowsCount () {
  128. return this.isOtherUser && this.user.hide_follows_count
  129. },
  130. hideFollowersCount () {
  131. return this.isOtherUser && this.user.hide_followers_count
  132. },
  133. showModerationMenu () {
  134. const privileges = this.loggedIn.privileges
  135. return this.loggedIn.role === 'admin' || privileges.includes('users_manage_activation_state') || privileges.includes('users_delete') || privileges.includes('users_manage_tags')
  136. },
  137. hasNote () {
  138. return this.relationship.note
  139. },
  140. supportsNote () {
  141. return 'note' in this.relationship
  142. },
  143. shouldConfirmMute () {
  144. return this.mergedConfig.modalOnMute
  145. },
  146. muteExpiryUnits () {
  147. return ['minutes', 'hours', 'days']
  148. },
  149. ...mapGetters(['mergedConfig'])
  150. },
  151. components: {
  152. UserAvatar,
  153. RemoteFollow,
  154. ModerationTools,
  155. AccountActions,
  156. ProgressButton,
  157. FollowButton,
  158. Select,
  159. RichContent,
  160. UserLink,
  161. UserNote,
  162. ConfirmModal
  163. },
  164. methods: {
  165. showConfirmMute () {
  166. this.showingConfirmMute = true
  167. },
  168. hideConfirmMute () {
  169. this.showingConfirmMute = false
  170. },
  171. muteUser () {
  172. if (!this.shouldConfirmMute) {
  173. this.doMuteUser()
  174. } else {
  175. this.showConfirmMute()
  176. }
  177. },
  178. doMuteUser () {
  179. this.$store.dispatch('muteUser', {
  180. id: this.user.id,
  181. expiresIn: this.shouldConfirmMute ? unitToSeconds(this.muteExpiryUnit, this.muteExpiryAmount) : 0
  182. })
  183. this.hideConfirmMute()
  184. },
  185. unmuteUser () {
  186. this.$store.dispatch('unmuteUser', this.user.id)
  187. },
  188. subscribeUser () {
  189. return this.$store.dispatch('subscribeUser', this.user.id)
  190. },
  191. unsubscribeUser () {
  192. return this.$store.dispatch('unsubscribeUser', this.user.id)
  193. },
  194. setProfileView (v) {
  195. if (this.switcher) {
  196. const store = this.$store
  197. store.commit('setProfileView', { v })
  198. }
  199. },
  200. linkClicked ({ target }) {
  201. if (target.tagName === 'SPAN') {
  202. target = target.parentNode
  203. }
  204. if (target.tagName === 'A') {
  205. window.open(target.href, '_blank')
  206. }
  207. },
  208. userProfileLink (user) {
  209. return generateProfileLink(
  210. user.id, user.screen_name,
  211. this.$store.state.instance.restrictedNicknames
  212. )
  213. },
  214. openProfileTab () {
  215. this.$store.dispatch('openSettingsModalTab', 'profile')
  216. },
  217. zoomAvatar () {
  218. const attachment = {
  219. url: this.user.profile_image_url_original,
  220. mimetype: 'image'
  221. }
  222. this.$store.dispatch('setMedia', [attachment])
  223. this.$store.dispatch('setCurrentMedia', attachment)
  224. },
  225. mentionUser () {
  226. this.$store.dispatch('openPostStatusModal', { replyTo: true, repliedUser: this.user })
  227. },
  228. onAvatarClickHandler (e) {
  229. if (this.onAvatarClick) {
  230. e.preventDefault()
  231. this.onAvatarClick()
  232. }
  233. }
  234. }
  235. }