logo

pleroma-fe

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

buttons_definitions.js (5968B)


  1. import { useEditStatusStore } from 'src/stores/editStatus.js'
  2. const PRIVATE_SCOPES = new Set(['private', 'direct'])
  3. const PUBLIC_SCOPES = new Set(['public', 'unlisted'])
  4. export const BUTTONS = [{
  5. // =========
  6. // REPLY
  7. // =========
  8. name: 'reply',
  9. label: 'tool_tip.reply',
  10. icon: 'reply',
  11. active: ({ replying }) => replying,
  12. counter: ({ status }) => status.replies_count,
  13. anon: true,
  14. anonLink: true,
  15. toggleable: true,
  16. closeIndicator: 'times',
  17. activeIndicator: 'none',
  18. action ({ emit }) {
  19. emit('toggleReplying')
  20. return Promise.resolve()
  21. }
  22. }, {
  23. // =========
  24. // REPEAT
  25. // =========
  26. name: 'retweet',
  27. label: ({ status }) => status.repeated
  28. ? 'tool_tip.unrepeat'
  29. : 'tool_tip.repeat',
  30. icon ({ status }) {
  31. if (PRIVATE_SCOPES.has(status.visibility)) {
  32. return 'lock'
  33. }
  34. return 'retweet'
  35. },
  36. animated: true,
  37. active: ({ status }) => status.repeated,
  38. counter: ({ status }) => status.repeat_num,
  39. anonLink: true,
  40. interactive: ({ status, loggedIn }) => loggedIn && !PRIVATE_SCOPES.has(status.visibility),
  41. toggleable: true,
  42. confirm: ({ status, getters }) => !status.repeated && getters.mergedConfig.modalOnRepeat,
  43. confirmStrings: {
  44. title: 'status.repeat_confirm_title',
  45. body: 'status.repeat_confirm',
  46. confirm: 'status.repeat_confirm_accept_button',
  47. cancel: 'status.repeat_confirm_cancel_button'
  48. },
  49. action ({ status, dispatch }) {
  50. if (!status.repeated) {
  51. return dispatch('retweet', { id: status.id })
  52. } else {
  53. return dispatch('unretweet', { id: status.id })
  54. }
  55. }
  56. }, {
  57. // =========
  58. // FAVORITE
  59. // =========
  60. name: 'favorite',
  61. label: ({ status }) => status.favorited
  62. ? 'tool_tip.unfavorite'
  63. : 'tool_tip.favorite',
  64. icon: ({ status }) => status.favorited
  65. ? ['fas', 'star']
  66. : ['far', 'star'],
  67. animated: true,
  68. active: ({ status }) => status.favorited,
  69. counter: ({ status }) => status.fave_num,
  70. anonLink: true,
  71. toggleable: true,
  72. action ({ status, dispatch }) {
  73. if (!status.favorited) {
  74. return dispatch('favorite', { id: status.id })
  75. } else {
  76. return dispatch('unfavorite', { id: status.id })
  77. }
  78. }
  79. }, {
  80. // =========
  81. // EMOJI REACTIONS
  82. // =========
  83. name: 'emoji',
  84. label: 'tool_tip.add_reaction',
  85. icon: ['far', 'smile-beam'],
  86. anonLink: true
  87. }, {
  88. // =========
  89. // MUTE
  90. // =========
  91. name: 'mute',
  92. icon: 'eye-slash',
  93. label: 'status.mute_ellipsis',
  94. if: ({ loggedIn }) => loggedIn,
  95. toggleable: true,
  96. dropdown: true
  97. // action ({ status, dispatch, emit }) {
  98. // }
  99. }, {
  100. // =========
  101. // PIN STATUS
  102. // =========
  103. name: 'pin',
  104. icon: 'thumbtack',
  105. label: ({ status }) => status.pinned
  106. ? 'status.unpin'
  107. : 'status.pin',
  108. if ({ status, loggedIn, currentUser }) {
  109. return loggedIn &&
  110. status.user.id === currentUser.id &&
  111. PUBLIC_SCOPES.has(status.visibility)
  112. },
  113. action ({ status, dispatch }) {
  114. if (status.pinned) {
  115. return dispatch('unpinStatus', status.id)
  116. } else {
  117. return dispatch('pinStatus', status.id)
  118. }
  119. }
  120. }, {
  121. // =========
  122. // BOOKMARK
  123. // =========
  124. name: 'bookmark',
  125. icon: ({ status }) => status.bookmarked
  126. ? ['fas', 'bookmark']
  127. : ['far', 'bookmark'],
  128. toggleable: true,
  129. active: ({ status }) => status.bookmarked,
  130. label: ({ status }) => status.bookmarked
  131. ? 'status.unbookmark'
  132. : 'status.bookmark',
  133. if: ({ loggedIn }) => loggedIn,
  134. action ({ status, dispatch }) {
  135. if (status.bookmarked) {
  136. return dispatch('unbookmark', { id: status.id })
  137. } else {
  138. return dispatch('bookmark', { id: status.id })
  139. }
  140. }
  141. }, {
  142. // =========
  143. // EDIT
  144. // =========
  145. name: 'edit',
  146. icon: 'pen',
  147. label: 'status.edit',
  148. if ({ status, loggedIn, currentUser, state }) {
  149. return loggedIn &&
  150. state.instance.editingAvailable &&
  151. status.user.id === currentUser.id
  152. },
  153. action ({ dispatch, status }) {
  154. return dispatch('fetchStatusSource', { id: status.id })
  155. .then(data => useEditStatusStore().openEditStatusModal({
  156. statusId: status.id,
  157. subject: data.spoiler_text,
  158. statusText: data.text,
  159. statusIsSensitive: status.nsfw,
  160. statusPoll: status.poll,
  161. statusFiles: [...status.attachments],
  162. visibility: status.visibility,
  163. statusContentType: data.content_type
  164. }))
  165. }
  166. }, {
  167. // =========
  168. // DELETE
  169. // =========
  170. name: 'delete',
  171. icon: 'times',
  172. label: 'status.delete',
  173. if ({ status, loggedIn, currentUser }) {
  174. return loggedIn && (
  175. status.user.id === currentUser.id ||
  176. currentUser.privileges.includes('messages_delete')
  177. )
  178. },
  179. confirm: ({ getters }) => getters.mergedConfig.modalOnDelete,
  180. confirmStrings: {
  181. title: 'status.delete_confirm_title',
  182. body: 'status.delete_confirm',
  183. confirm: 'status.delete_confirm_accept_button',
  184. cancel: 'status.delete_confirm_cancel_button'
  185. },
  186. action ({ dispatch, status }) {
  187. return dispatch('deleteStatus', { id: status.id })
  188. }
  189. }, {
  190. // =========
  191. // SHARE/COPY
  192. // =========
  193. name: 'share',
  194. icon: 'share-alt',
  195. label: 'status.copy_link',
  196. action ({ state, status, router }) {
  197. navigator.clipboard.writeText([
  198. state.instance.server,
  199. router.resolve({ name: 'conversation', params: { id: status.id } }).href
  200. ].join(''))
  201. return Promise.resolve()
  202. }
  203. }, {
  204. // =========
  205. // EXTERNAL
  206. // =========
  207. name: 'external',
  208. icon: 'external-link-alt',
  209. label: 'status.external_source',
  210. link: ({ status }) => status.external_url
  211. }, {
  212. // =========
  213. // REPORT
  214. // =========
  215. name: 'report',
  216. icon: 'flag',
  217. label: 'user_card.report',
  218. if: ({ loggedIn }) => loggedIn,
  219. action ({ dispatch, status }) {
  220. dispatch('openUserReportingModal', { userId: status.user.id, statusIds: [status.id] })
  221. }
  222. }].map(button => {
  223. return Object.fromEntries(
  224. Object.entries(button).map(([k, v]) => [
  225. k,
  226. (typeof v === 'function' || k === 'name') ? v : () => v
  227. ])
  228. )
  229. })