Commit 7eeb63cb authored by picklesrus's avatar picklesrus

rename SetupMessagePolling to pollForMessages

parent 5de96c37
...@@ -28,7 +28,7 @@ class Navigation extends React.Component { ...@@ -28,7 +28,7 @@ class Navigation extends React.Component {
bindAll(this, [ bindAll(this, [
'getProfileUrl', 'getProfileUrl',
'handleSearchSubmit', 'handleSearchSubmit',
'setupMessagePolling' 'pollForMessages'
]); ]);
this.state = { this.state = {
messageCountIntervalId: -1 // javascript method interval id for getting messsage count. messageCountIntervalId: -1 // javascript method interval id for getting messsage count.
...@@ -37,14 +37,14 @@ class Navigation extends React.Component { ...@@ -37,14 +37,14 @@ class Navigation extends React.Component {
componentDidMount () { componentDidMount () {
if (this.props.user) { if (this.props.user) {
// Setup polling for messages to start in 2 minutes. // Setup polling for messages to start in 2 minutes.
setTimeout(this.setupMessagePolling.bind(this, 2), 2 * 60 * 1000); setTimeout(this.pollForMessages.bind(this, 2), 2 * 60 * 1000);
} }
} }
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
if (prevProps.user !== this.props.user) { if (prevProps.user !== this.props.user) {
this.props.handleCloseAccountNav(); this.props.handleCloseAccountNav();
if (this.props.user) { if (this.props.user) {
setTimeout(this.setupMessagePolling.bind(this, 2), 2 * 60 * 1000); setTimeout(this.pollForMessages.bind(this, 2), 2 * 60 * 1000);
} else { } else {
// clear message count check, and set to default id. // clear message count check, and set to default id.
clearTimeout(this.state.messageCountIntervalId); clearTimeout(this.state.messageCountIntervalId);
...@@ -70,7 +70,7 @@ class Navigation extends React.Component { ...@@ -70,7 +70,7 @@ class Navigation extends React.Component {
return `/users/${this.props.user.username}/`; return `/users/${this.props.user.username}/`;
} }
setupMessagePolling (minutes) { pollForMessages (minutes) {
this.props.getMessageCount(this.props.user.username); this.props.getMessageCount(this.props.user.username);
// We only poll if it has been less than 30 minutes. // We only poll if it has been less than 30 minutes.
// Chances of someone actively using the page for that long without // Chances of someone actively using the page for that long without
...@@ -78,7 +78,7 @@ class Navigation extends React.Component { ...@@ -78,7 +78,7 @@ class Navigation extends React.Component {
if (minutes < 32) { if (minutes < 32) {
const nextFetch = minutes * 2; const nextFetch = minutes * 2;
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
this.setupMessagePolling(nextFetch); this.pollForMessages(nextFetch);
}, nextFetch * 60000); }, nextFetch * 60000);
this.setState({ // eslint-disable-line react/no-did-mount-set-state this.setState({ // eslint-disable-line react/no-did-mount-set-state
messageCountIntervalId: timeoutId messageCountIntervalId: timeoutId
......
...@@ -138,7 +138,7 @@ describe('Navigation', () => { ...@@ -138,7 +138,7 @@ describe('Navigation', () => {
expect(props.getMessageCount).toHaveBeenCalled(); expect(props.getMessageCount).toHaveBeenCalled();
}); });
test('SetupMessagePolling polls for messages 5 times', () => { test('pollForMessages polls for messages 5 times', () => {
store = mockStore({ store = mockStore({
navigation: { navigation: {
registrationOpen: false registrationOpen: false
...@@ -164,11 +164,11 @@ describe('Navigation', () => { ...@@ -164,11 +164,11 @@ describe('Navigation', () => {
const navInstance = intlWrapper.children().find('Navigation') const navInstance = intlWrapper.children().find('Navigation')
.instance(); .instance();
// Clear the timers and mocks because componentDidMount // Clear the timers and mocks because componentDidMount
// has already called setupMessagePolling. // has already called pollForMessages.
jest.clearAllTimers(); jest.clearAllTimers();
jest.clearAllMocks(); jest.clearAllMocks();
navInstance.setupMessagePolling(2); navInstance.pollForMessages(2);
// Check that we set the timeout to backoff exponentially // Check that we set the timeout to backoff exponentially
let minutes = 2 * 60 * 1000; let minutes = 2 * 60 * 1000;
...@@ -185,7 +185,7 @@ describe('Navigation', () => { ...@@ -185,7 +185,7 @@ describe('Navigation', () => {
// and stop after 32 minutes so it should happen 5 times total. // and stop after 32 minutes so it should happen 5 times total.
expect(props.getMessageCount).toHaveBeenCalledTimes(5); expect(props.getMessageCount).toHaveBeenCalledTimes(5);
// setTimeout happens 1 fewer since the original call to // setTimeout happens 1 fewer since the original call to
// setupMessagePolling isn't counted here. // pollForMessages isn't counted here.
expect(setTimeout).toHaveBeenCalledTimes(4); expect(setTimeout).toHaveBeenCalledTimes(4);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment