summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-12-21 16:35:01 -0500
committerChristopher Speller <crspeller@gmail.com>2016-12-21 16:35:01 -0500
commitba6e370ca71abacaa30234cb164427d27c86df13 (patch)
tree2379b6dab897deef1226f66772b8f05e0bb08f9c /webapp/utils
parent139cb52c99ac525f44a280803447bbbd88369f23 (diff)
downloadchat-ba6e370ca71abacaa30234cb164427d27c86df13.tar.gz
chat-ba6e370ca71abacaa30234cb164427d27c86df13.tar.bz2
chat-ba6e370ca71abacaa30234cb164427d27c86df13.zip
PLT-5012 Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API (#4840)
* Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API * Remove preference DB writes
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/async_client.jsx94
1 files changed, 9 insertions, 85 deletions
diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx
index 2d8e76fc2..66f13f04d 100644
--- a/webapp/utils/async_client.jsx
+++ b/webapp/utils/async_client.jsx
@@ -138,33 +138,20 @@ export function getMyChannelMembers() {
});
}
-export function updateLastViewedAt(id, active) {
- let channelId;
- if (id) {
- channelId = id;
- } else {
- channelId = ChannelStore.getCurrentId();
- }
-
+export function viewChannel(channelId = ChannelStore.getCurrentId(), prevChannelId = '', time = 0) {
if (channelId == null) {
return;
}
- if (isCallInProgress(`updateLastViewed${channelId}`)) {
+ if (isCallInProgress(`viewChannel${channelId}`)) {
return;
}
- let isActive;
- if (active == null) {
- isActive = true;
- } else {
- isActive = active;
- }
-
- callTracker[`updateLastViewed${channelId}`] = utils.getTimestamp();
- Client.updateLastViewedAt(
+ callTracker[`viewChannel${channelId}`] = utils.getTimestamp();
+ Client.viewChannel(
channelId,
- isActive,
+ prevChannelId,
+ time,
() => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_PREFERENCE,
@@ -175,59 +162,14 @@ export function updateLastViewedAt(id, active) {
}
});
- callTracker[`updateLastViewed${channelId}`] = 0;
+ callTracker[`viewChannel${channelId}`] = 0;
ErrorStore.clearLastError();
},
(err) => {
- callTracker[`updateLastViewed${channelId}`] = 0;
+ callTracker[`viewChannel${channelId}`] = 0;
const count = ErrorStore.getConnectionErrorCount();
ErrorStore.setConnectionErrorCount(count + 1);
- dispatchError(err, 'updateLastViewedAt');
- }
- );
-}
-
-export function setLastViewedAt(lastViewedAt, id) {
- let channelId;
- if (id) {
- channelId = id;
- } else {
- channelId = ChannelStore.getCurrentId();
- }
-
- if (channelId == null) {
- return;
- }
-
- if (lastViewedAt == null) {
- return;
- }
-
- if (isCallInProgress(`setLastViewedAt${channelId}${lastViewedAt}`)) {
- return;
- }
-
- callTracker[`setLastViewedAt${channelId}${lastViewedAt}`] = utils.getTimestamp();
- Client.setLastViewedAt(
- channelId,
- lastViewedAt,
- () => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_PREFERENCE,
- preference: {
- category: 'last',
- name: TeamStore.getCurrentId(),
- value: channelId
- }
- });
- callTracker[`setLastViewedAt${channelId}${lastViewedAt}`] = 0;
- ErrorStore.clearLastError();
- },
- (err) => {
- callTracker[`setLastViewedAt${channelId}${lastViewedAt}`] = 0;
- var count = ErrorStore.getConnectionErrorCount();
- ErrorStore.setConnectionErrorCount(count + 1);
- dispatchError(err, 'setLastViewedAt');
+ dispatchError(err, 'viewChannel');
}
);
}
@@ -795,24 +737,6 @@ 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;