闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.5 KiB

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