logo

mastofe

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

streaming.js (1768B)


  1. import { connectStream } from '../stream';
  2. import {
  3. updateTimeline,
  4. deleteFromTimelines,
  5. expandHomeTimeline,
  6. disconnectTimeline,
  7. } from './timelines';
  8. import { updateNotifications, expandNotifications } from './notifications';
  9. import { getLocale } from '../locales';
  10. const { messages } = getLocale();
  11. export function connectTimelineStream (timelineId, path, pollingRefresh = null) {
  12. return connectStream (path, pollingRefresh, (dispatch, getState) => {
  13. const locale = getState().getIn(['meta', 'locale']);
  14. return {
  15. onDisconnect() {
  16. dispatch(disconnectTimeline(timelineId));
  17. },
  18. onReceive (data) {
  19. switch(data.event) {
  20. case 'update':
  21. dispatch(updateTimeline(timelineId, JSON.parse(data.payload)));
  22. break;
  23. case 'delete':
  24. dispatch(deleteFromTimelines(data.payload));
  25. break;
  26. case 'notification':
  27. dispatch(updateNotifications(JSON.parse(data.payload), messages, locale));
  28. break;
  29. }
  30. },
  31. };
  32. });
  33. }
  34. function refreshHomeTimelineAndNotification (dispatch) {
  35. dispatch(expandHomeTimeline());
  36. dispatch(expandNotifications());
  37. }
  38. export const connectUserStream = () => connectTimelineStream('home', 'user', refreshHomeTimelineAndNotification);
  39. export const connectCommunityStream = () => connectTimelineStream('community', 'public:local');
  40. export const connectMediaStream = () => connectTimelineStream('community', 'public:local');
  41. export const connectPublicStream = () => connectTimelineStream('public', 'public');
  42. export const connectHashtagStream = (tag) => connectTimelineStream(`hashtag:${tag}`, `hashtag&tag=${tag}`);
  43. export const connectListStream = (id) => connectTimelineStream(`list:${id}`, `list&list=${id}`);