logo

mastofe

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

index.js (2795B)


  1. import { createSelector } from 'reselect';
  2. import { List as ImmutableList } from 'immutable';
  3. const getAccountBase = (state, id) => state.getIn(['accounts', id], null);
  4. const getAccountCounters = (state, id) => state.getIn(['accounts_counters', id], null);
  5. const getAccountRelationship = (state, id) => state.getIn(['relationships', id], null);
  6. const getAccountMoved = (state, id) => state.getIn(['accounts', state.getIn(['accounts', id, 'moved'])]);
  7. export const makeGetAccount = () => {
  8. return createSelector([getAccountBase, getAccountCounters, getAccountRelationship, getAccountMoved], (base, counters, relationship, moved) => {
  9. if (base === null) {
  10. return null;
  11. }
  12. return base.merge(counters).withMutations(map => {
  13. map.set('relationship', relationship);
  14. map.set('moved', moved);
  15. });
  16. });
  17. };
  18. export const makeGetStatus = () => {
  19. return createSelector(
  20. [
  21. (state, id) => state.getIn(['statuses', id]),
  22. (state, id) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
  23. (state, id) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
  24. (state, id) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
  25. ],
  26. (statusBase, statusReblog, accountBase, accountReblog) => {
  27. if (!statusBase) {
  28. return null;
  29. }
  30. if (statusReblog) {
  31. statusReblog = statusReblog.set('account', accountReblog);
  32. } else {
  33. statusReblog = null;
  34. }
  35. return statusBase.withMutations(map => {
  36. map.set('reblog', statusReblog);
  37. map.set('account', accountBase);
  38. });
  39. }
  40. );
  41. };
  42. const getAlertsBase = state => state.get('alerts');
  43. export const getAlerts = createSelector([getAlertsBase], (base) => {
  44. let arr = [];
  45. base.forEach(item => {
  46. arr.push({
  47. message: item.get('message'),
  48. title: item.get('title'),
  49. key: item.get('key'),
  50. dismissAfter: 5000,
  51. barStyle: {
  52. zIndex: 200,
  53. },
  54. });
  55. });
  56. return arr;
  57. });
  58. export const makeGetNotification = () => {
  59. return createSelector([
  60. (_, base) => base,
  61. (state, _, accountId) => state.getIn(['accounts', accountId]),
  62. ], (base, account) => {
  63. return base.set('account', account);
  64. });
  65. };
  66. export const getAccountGallery = createSelector([
  67. (state, id) => state.getIn(['timelines', `account:${id}:media`, 'items'], ImmutableList()),
  68. state => state.get('statuses'),
  69. ], (statusIds, statuses) => {
  70. let medias = ImmutableList();
  71. statusIds.forEach(statusId => {
  72. const status = statuses.get(statusId);
  73. medias = medias.concat(status.get('media_attachments').map(media => media.set('status', status)));
  74. });
  75. return medias;
  76. });