logo

pleroma-fe

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

poll.service.js (824B)


  1. import * as DateUtils from 'src/services/date_utils/date_utils.js'
  2. import { uniq } from 'lodash'
  3. const pollFallbackValues = {
  4. pollType: 'single',
  5. options: ['', ''],
  6. expiryAmount: 10,
  7. expiryUnit: 'minutes'
  8. }
  9. const pollFallback = (object, attr) => {
  10. return object[attr] !== undefined ? object[attr] : pollFallbackValues[attr]
  11. }
  12. const pollFormToMasto = (poll) => {
  13. const expiresIn = DateUtils.unitToSeconds(
  14. pollFallback(poll, 'expiryUnit'),
  15. pollFallback(poll, 'expiryAmount')
  16. )
  17. const options = uniq(pollFallback(poll, 'options').filter(option => option !== ''))
  18. if (options.length < 2) {
  19. return { errorKey: 'polls.not_enough_options' }
  20. }
  21. return {
  22. options,
  23. multiple: pollFallback(poll, 'pollType') === 'multiple',
  24. expiresIn
  25. }
  26. }
  27. export {
  28. pollFallback,
  29. pollFormToMasto
  30. }