logo

mastofe

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

index.js (2020B)


  1. import { autoPlayGif } from '../../initial_state';
  2. import { putAccounts, putStatuses } from '../../storage/modifier';
  3. import { normalizeAccount, normalizeStatus } from './normalizer';
  4. export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT';
  5. export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT';
  6. export const STATUS_IMPORT = 'STATUS_IMPORT';
  7. export const STATUSES_IMPORT = 'STATUSES_IMPORT';
  8. function pushUnique(array, object) {
  9. if (array.every(element => element.id !== object.id)) {
  10. array.push(object);
  11. }
  12. }
  13. export function importAccount(account) {
  14. return { type: ACCOUNT_IMPORT, account };
  15. }
  16. export function importAccounts(accounts) {
  17. return { type: ACCOUNTS_IMPORT, accounts };
  18. }
  19. export function importStatus(status) {
  20. return { type: STATUS_IMPORT, status };
  21. }
  22. export function importStatuses(statuses) {
  23. return { type: STATUSES_IMPORT, statuses };
  24. }
  25. export function importFetchedAccount(account) {
  26. return importFetchedAccounts([account]);
  27. }
  28. export function importFetchedAccounts(accounts) {
  29. const normalAccounts = [];
  30. function processAccount(account) {
  31. pushUnique(normalAccounts, normalizeAccount(account));
  32. if (account.moved) {
  33. processAccount(account.moved);
  34. }
  35. }
  36. accounts.forEach(processAccount);
  37. putAccounts(normalAccounts, !autoPlayGif);
  38. return importAccounts(normalAccounts);
  39. }
  40. export function importFetchedStatus(status) {
  41. return importFetchedStatuses([status]);
  42. }
  43. export function importFetchedStatuses(statuses) {
  44. return (dispatch, getState) => {
  45. const accounts = [];
  46. const normalStatuses = [];
  47. function processStatus(status) {
  48. pushUnique(normalStatuses, normalizeStatus(status, getState().getIn(['statuses', status.id])));
  49. pushUnique(accounts, status.account);
  50. if (status.reblog && status.reblog.id) {
  51. processStatus(status.reblog);
  52. }
  53. }
  54. statuses.forEach(processStatus);
  55. putStatuses(normalStatuses);
  56. dispatch(importFetchedAccounts(accounts));
  57. dispatch(importStatuses(normalStatuses));
  58. };
  59. }