闭社主体 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.

90 lines
2.6 KiB

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