logo

pleroma-fe

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

status_poster.service.js (2326B)


  1. import { map } from 'lodash'
  2. import apiService from '../api/api.service.js'
  3. const postStatus = ({
  4. store,
  5. status,
  6. spoilerText,
  7. visibility,
  8. sensitive,
  9. poll,
  10. media = [],
  11. inReplyToStatusId = undefined,
  12. quoteId = undefined,
  13. contentType = 'text/plain',
  14. preview = false,
  15. idempotencyKey = ''
  16. }) => {
  17. const mediaIds = map(media, 'id')
  18. return apiService.postStatus({
  19. credentials: store.state.users.currentUser.credentials,
  20. status,
  21. spoilerText,
  22. visibility,
  23. sensitive,
  24. mediaIds,
  25. inReplyToStatusId,
  26. quoteId,
  27. contentType,
  28. poll,
  29. preview,
  30. idempotencyKey
  31. })
  32. .then((data) => {
  33. if (!data.error && !preview) {
  34. store.dispatch('addNewStatuses', {
  35. statuses: [data],
  36. timeline: 'friends',
  37. showImmediately: true,
  38. noIdUpdate: true // To prevent missing notices on next pull.
  39. })
  40. }
  41. return data
  42. })
  43. .catch((err) => {
  44. return {
  45. error: err.message
  46. }
  47. })
  48. }
  49. const editStatus = ({
  50. store,
  51. statusId,
  52. status,
  53. spoilerText,
  54. sensitive,
  55. poll,
  56. media = [],
  57. contentType = 'text/plain'
  58. }) => {
  59. const mediaIds = map(media, 'id')
  60. return apiService.editStatus({
  61. id: statusId,
  62. credentials: store.state.users.currentUser.credentials,
  63. status,
  64. spoilerText,
  65. sensitive,
  66. poll,
  67. mediaIds,
  68. contentType
  69. })
  70. .then((data) => {
  71. if (!data.error) {
  72. store.dispatch('addNewStatuses', {
  73. statuses: [data],
  74. timeline: 'friends',
  75. showImmediately: true,
  76. noIdUpdate: true // To prevent missing notices on next pull.
  77. })
  78. }
  79. return data
  80. })
  81. .catch((err) => {
  82. console.error('Error editing status', err)
  83. return {
  84. error: err.message
  85. }
  86. })
  87. }
  88. const uploadMedia = ({ store, formData }) => {
  89. const credentials = store.state.users.currentUser.credentials
  90. return apiService.uploadMedia({ credentials, formData })
  91. }
  92. const setMediaDescription = ({ store, id, description }) => {
  93. const credentials = store.state.users.currentUser.credentials
  94. return apiService.setMediaDescription({ credentials, id, description })
  95. }
  96. const statusPosterService = {
  97. postStatus,
  98. editStatus,
  99. uploadMedia,
  100. setMediaDescription
  101. }
  102. export default statusPosterService