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

72 lines
2.0 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 getAccountRelationship = (state, id) => state.getIn(['relationships', id], null);
  7. export const makeGetAccount = () => {
  8. return createSelector([getAccountBase, getAccountRelationship], (base, relationship) => {
  9. if (base === null) {
  10. return null;
  11. }
  12. return base.set('relationship', relationship);
  13. });
  14. };
  15. export const makeGetStatus = () => {
  16. return createSelector(
  17. [
  18. (state, id) => state.getIn(['statuses', id]),
  19. (state, id) => state.getIn(['statuses', state.getIn(['statuses', id, 'reblog'])]),
  20. (state, id) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]),
  21. (state, id) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]),
  22. ],
  23. (statusBase, statusReblog, accountBase, accountReblog) => {
  24. if (!statusBase) {
  25. return null;
  26. }
  27. if (statusReblog) {
  28. statusReblog = statusReblog.set('account', accountReblog);
  29. } else {
  30. statusReblog = null;
  31. }
  32. return statusBase.withMutations(map => {
  33. map.set('reblog', statusReblog);
  34. map.set('account', accountBase);
  35. });
  36. }
  37. );
  38. };
  39. const getAlertsBase = state => state.get('alerts');
  40. export const getAlerts = createSelector([getAlertsBase], (base) => {
  41. let arr = [];
  42. base.forEach(item => {
  43. arr.push({
  44. message: item.get('message'),
  45. title: item.get('title'),
  46. key: item.get('key'),
  47. dismissAfter: 5000
  48. });
  49. });
  50. return arr;
  51. });
  52. export const makeGetNotification = () => {
  53. return createSelector([
  54. (_, base) => base,
  55. (state, _, accountId) => state.getIn(['accounts', accountId])
  56. ], (base, account) => {
  57. return base.set('account', account);
  58. });
  59. };