[Glitch] Use streaming API for standalone timelines on /about and /tag pages
Port 0128b86d3098042cdbc3a1629f74b70f665f8dfb to glitch-soc
This commit is contained in:
		
							parent
							
								
									d959d04133
								
							
						
					
					
						commit
						1fa3586db5
					
				@ -8,6 +8,7 @@ import {
 | 
				
			|||||||
} from 'flavours/glitch/actions/timelines';
 | 
					} from 'flavours/glitch/actions/timelines';
 | 
				
			||||||
import Column from 'flavours/glitch/components/column';
 | 
					import Column from 'flavours/glitch/components/column';
 | 
				
			||||||
import ColumnHeader from 'flavours/glitch/components/column_header';
 | 
					import ColumnHeader from 'flavours/glitch/components/column_header';
 | 
				
			||||||
 | 
					import { connectHashtagStream } from 'flavours/glitch/actions/streaming';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@connect()
 | 
					@connect()
 | 
				
			||||||
export default class HashtagTimeline extends React.PureComponent {
 | 
					export default class HashtagTimeline extends React.PureComponent {
 | 
				
			||||||
@ -29,16 +30,13 @@ export default class HashtagTimeline extends React.PureComponent {
 | 
				
			|||||||
    const { dispatch, hashtag } = this.props;
 | 
					    const { dispatch, hashtag } = this.props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dispatch(refreshHashtagTimeline(hashtag));
 | 
					    dispatch(refreshHashtagTimeline(hashtag));
 | 
				
			||||||
 | 
					    this.disconnect = dispatch(connectHashtagStream(hashtag));
 | 
				
			||||||
    this.polling = setInterval(() => {
 | 
					 | 
				
			||||||
      dispatch(refreshHashtagTimeline(hashtag));
 | 
					 | 
				
			||||||
    }, 10000);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  componentWillUnmount () {
 | 
					  componentWillUnmount () {
 | 
				
			||||||
    if (typeof this.polling !== 'undefined') {
 | 
					    if (this.disconnect) {
 | 
				
			||||||
      clearInterval(this.polling);
 | 
					      this.disconnect();
 | 
				
			||||||
      this.polling = null;
 | 
					      this.disconnect = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,7 @@ import {
 | 
				
			|||||||
import Column from 'flavours/glitch/components/column';
 | 
					import Column from 'flavours/glitch/components/column';
 | 
				
			||||||
import ColumnHeader from 'flavours/glitch/components/column_header';
 | 
					import ColumnHeader from 'flavours/glitch/components/column_header';
 | 
				
			||||||
import { defineMessages, injectIntl } from 'react-intl';
 | 
					import { defineMessages, injectIntl } from 'react-intl';
 | 
				
			||||||
 | 
					import { connectPublicStream } from 'flavours/glitch/actions/streaming';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const messages = defineMessages({
 | 
					const messages = defineMessages({
 | 
				
			||||||
  title: { id: 'standalone.public_title', defaultMessage: 'A look inside...' },
 | 
					  title: { id: 'standalone.public_title', defaultMessage: 'A look inside...' },
 | 
				
			||||||
@ -35,16 +36,13 @@ export default class PublicTimeline extends React.PureComponent {
 | 
				
			|||||||
    const { dispatch } = this.props;
 | 
					    const { dispatch } = this.props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dispatch(refreshPublicTimeline());
 | 
					    dispatch(refreshPublicTimeline());
 | 
				
			||||||
 | 
					    this.disconnect = dispatch(connectPublicStream());
 | 
				
			||||||
    this.polling = setInterval(() => {
 | 
					 | 
				
			||||||
      dispatch(refreshPublicTimeline());
 | 
					 | 
				
			||||||
    }, 3000);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  componentWillUnmount () {
 | 
					  componentWillUnmount () {
 | 
				
			||||||
    if (typeof this.polling !== 'undefined') {
 | 
					    if (this.disconnect) {
 | 
				
			||||||
      clearInterval(this.polling);
 | 
					      this.disconnect();
 | 
				
			||||||
      this.polling = null;
 | 
					      this.disconnect = null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -62,7 +62,13 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function getStream(streamingAPIBaseURL, accessToken, stream, { connected, received, disconnected, reconnected }) {
 | 
					export default function getStream(streamingAPIBaseURL, accessToken, stream, { connected, received, disconnected, reconnected }) {
 | 
				
			||||||
  const ws = new WebSocketClient(`${streamingAPIBaseURL}/api/v1/streaming/?access_token=${accessToken}&stream=${stream}`);
 | 
					  const params = [ `stream=${stream}` ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (accessToken !== null) {
 | 
				
			||||||
 | 
					    params.push(`access_token=${accessToken}`);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const ws = new WebSocketClient(`${streamingAPIBaseURL}/api/v1/streaming/?${params.join('&')}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ws.onopen      = connected;
 | 
					  ws.onopen      = connected;
 | 
				
			||||||
  ws.onmessage   = e => received(JSON.parse(e.data));
 | 
					  ws.onmessage   = e => received(JSON.parse(e.data));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user