Do not send push notifications for channels being actively viewed (#3931)

Этот коммит содержится в:
Joram Wilander
2016-09-02 12:50:15 -04:00
коммит произвёл GitHub
родитель eb0111f6bb
Коммит f32eb525f3
20 изменённых файлов: 213 добавлений и 47 удалений

Просмотреть файл

@@ -19,7 +19,7 @@ const Preferences = Constants.Preferences;
export function handleNewPost(post, msg) {
if (ChannelStore.getCurrentId() === post.channel_id) {
if (window.isActive) {
AsyncClient.updateLastViewedAt();
AsyncClient.updateLastViewedAt(null, false);
} else {
AsyncClient.getChannel(post.channel_id);
}

Просмотреть файл

@@ -174,7 +174,7 @@ function handlePostEditEvent(msg) {
// Update channel state
if (ChannelStore.getCurrentId() === msg.channel_id) {
if (window.isActive) {
AsyncClient.updateLastViewedAt();
AsyncClient.updateLastViewedAt(null, false);
}
}
}

Просмотреть файл

@@ -1003,6 +1003,16 @@ export default class Client {
end(this.handleResponse.bind(this, 'getStatuses', success, error));
}
setActiveChannel(id, success, error) {
request.
post(`${this.getUsersRoute()}/status/set_active_channel`).
set(this.defaultHeaders).
type('application/json').
accept('application/json').
send({channel_id: id}).
end(this.handleResponse.bind(this, 'setActiveChannel', success, error));
}
verifyEmail(uid, hid, success, error) {
request.
post(`${this.getUsersRoute()}/verify_email`).
@@ -1172,12 +1182,13 @@ export default class Client {
this.track('api', 'api_channels_delete');
}
updateLastViewedAt(channelId, success, error) {
updateLastViewedAt(channelId, active, success, error) {
request.
post(`${this.getChannelNeededRoute(channelId)}/update_last_viewed_at`).
set(this.defaultHeaders).
type('application/json').
accept('application/json').
send({active}).
end(this.handleResponse.bind(this, 'updateLastViewedAt', success, error));
}

Просмотреть файл

@@ -94,6 +94,7 @@ export default class NeedsTeam extends React.Component {
$(window).on('blur', () => {
window.isActive = false;
AsyncClient.setActiveChannel('');
});
Utils.applyTheme(this.state.theme);

Просмотреть файл

@@ -4,6 +4,7 @@
import PostViewController from './post_view_controller.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import React from 'react';
@@ -28,6 +29,7 @@ export default class PostViewCache extends React.Component {
}
componentWillUnmount() {
AsyncClient.setActiveChannel('');
ChannelStore.removeChangeListener(this.onChannelChange);
}

Просмотреть файл

@@ -216,6 +216,7 @@ describe('Client.Channels', function() {
var channel = TestHelper.basicChannel();
TestHelper.basicClient().updateLastViewedAt(
channel.id,
true,
function(data) {
assert.equal(data.id, channel.id);
done();

Просмотреть файл

@@ -509,6 +509,23 @@ describe('Client.User', function() {
});
*/
it('setActiveChannel', function(done) {
TestHelper.initBasic(() => {
var ids = [];
ids.push(TestHelper.basicUser().id);
TestHelper.basicClient().setActiveChannel(
TestHelper.basicChannel().id,
function() {
done();
},
function(err) {
done(new Error(err.message));
}
);
});
});
it('verifyEmail', function(done) {
TestHelper.initBasic(() => {
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error

Просмотреть файл

@@ -113,7 +113,7 @@ export function getChannel(id) {
);
}
export function updateLastViewedAt(id) {
export function updateLastViewedAt(id, active) {
let channelId;
if (id) {
channelId = id;
@@ -129,9 +129,17 @@ export function updateLastViewedAt(id) {
return;
}
let isActive;
if (active == null) {
isActive = true;
} else {
isActive = active;
}
callTracker[`updateLastViewed${channelId}`] = utils.getTimestamp();
Client.updateLastViewedAt(
channelId,
isActive,
() => {
callTracker[`updateLastViewed${channelId}`] = 0;
ErrorStore.clearLastError();
@@ -753,6 +761,24 @@ export function getStatuses() {
);
}
export function setActiveChannel(channelId) {
if (isCallInProgress(`setActiveChannel${channelId}`)) {
return;
}
callTracker[`setActiveChannel${channelId}`] = utils.getTimestamp();
Client.setActiveChannel(
channelId,
() => {
callTracker[`setActiveChannel${channelId}`] = 0;
},
(err) => {
callTracker[`setActiveChannel${channelId}`] = 0;
dispatchError(err, 'setActiveChannel');
}
);
}
export function getMyTeam() {
if (isCallInProgress('getMyTeam')) {
return null;