summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-09-02 12:50:15 -0400
committerGitHub <noreply@github.com>2016-09-02 12:50:15 -0400
commitf32eb525f3fa0828a23f589d765c267e3b2aea86 (patch)
treed4b76aecf89143029af080b3e1b4d87398e0adc5 /webapp
parenteb0111f6bbe2b0bf160a674dfe1b4d089f905cb9 (diff)
downloadchat-f32eb525f3fa0828a23f589d765c267e3b2aea86.tar.gz
chat-f32eb525f3fa0828a23f589d765c267e3b2aea86.tar.bz2
chat-f32eb525f3fa0828a23f589d765c267e3b2aea86.zip
Do not send push notifications for channels being actively viewed (#3931)
Diffstat (limited to 'webapp')
-rw-r--r--webapp/actions/post_actions.jsx2
-rw-r--r--webapp/actions/websocket_actions.jsx2
-rw-r--r--webapp/client/client.jsx13
-rw-r--r--webapp/components/needs_team.jsx1
-rw-r--r--webapp/components/post_view/post_view_cache.jsx2
-rw-r--r--webapp/tests/client_channel.test.jsx1
-rw-r--r--webapp/tests/client_user.test.jsx17
-rw-r--r--webapp/utils/async_client.jsx28
8 files changed, 62 insertions, 4 deletions
diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 9e0f90377..896a9030d 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -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);
}
diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx
index 1c4ef9c16..28faf4733 100644
--- a/webapp/actions/websocket_actions.jsx
+++ b/webapp/actions/websocket_actions.jsx
@@ -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);
}
}
}
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index a059bb38a..80e2cfe3e 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -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));
}
diff --git a/webapp/components/needs_team.jsx b/webapp/components/needs_team.jsx
index 6c023d497..cd80f0fc7 100644
--- a/webapp/components/needs_team.jsx
+++ b/webapp/components/needs_team.jsx
@@ -94,6 +94,7 @@ export default class NeedsTeam extends React.Component {
$(window).on('blur', () => {
window.isActive = false;
+ AsyncClient.setActiveChannel('');
});
Utils.applyTheme(this.state.theme);
diff --git a/webapp/components/post_view/post_view_cache.jsx b/webapp/components/post_view/post_view_cache.jsx
index 8876ae461..13ce79d7f 100644
--- a/webapp/components/post_view/post_view_cache.jsx
+++ b/webapp/components/post_view/post_view_cache.jsx
@@ -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);
}
diff --git a/webapp/tests/client_channel.test.jsx b/webapp/tests/client_channel.test.jsx
index 72ba91f9d..ccfcb32a4 100644
--- a/webapp/tests/client_channel.test.jsx
+++ b/webapp/tests/client_channel.test.jsx
@@ -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();
diff --git a/webapp/tests/client_user.test.jsx b/webapp/tests/client_user.test.jsx
index a0bddd08b..116eee4ae 100644
--- a/webapp/tests/client_user.test.jsx
+++ b/webapp/tests/client_user.test.jsx
@@ -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
diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx
index 729160fe4..585e4b1c0 100644
--- a/webapp/utils/async_client.jsx
+++ b/webapp/utils/async_client.jsx
@@ -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;