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

77 lines
2.0 KiB

8 years ago
8 years ago
  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]);
  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. const getStatusBase = (state, id) => state.getIn(['statuses', id], null);
  16. export const makeGetStatus = () => {
  17. return createSelector([getStatusBase, getStatuses, getAccounts], (base, statuses, accounts) => {
  18. if (base === null) {
  19. return null;
  20. }
  21. return assembleStatus(base.get('id'), statuses, accounts);
  22. });
  23. };
  24. const assembleStatus = (id, statuses, accounts) => {
  25. let status = statuses.get(id, null);
  26. let reblog = null;
  27. if (status === null) {
  28. return null;
  29. }
  30. if (status.get('reblog', null) !== null) {
  31. reblog = statuses.get(status.get('reblog'), null);
  32. if (reblog !== null) {
  33. reblog = reblog.set('account', accounts.get(reblog.get('account')));
  34. } else {
  35. return null;
  36. }
  37. }
  38. return status.set('reblog', reblog).set('account', accounts.get(status.get('account')));
  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. });
  50. });
  51. return arr;
  52. });
  53. export const makeGetNotification = () => {
  54. return createSelector([
  55. (_, base) => base,
  56. (state, _, accountId) => state.getIn(['accounts', accountId])
  57. ], (base, account) => {
  58. return base.set('account', account);
  59. });
  60. };