From ced5f54500b2688a942c5c1afbb4fca3882b4f51 Mon Sep 17 00:00:00 2001
From: Christopher Speller <crspeller@gmail.com>
Date: Fri, 11 Nov 2016 14:55:05 -0500
Subject: Fixing new messages indicator (#4531)

---
 webapp/utils/async_client.jsx | 82 ++++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 36 deletions(-)

(limited to 'webapp/utils/async_client.jsx')

diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx
index 1149c565f..efa9eeb2b 100644
--- a/webapp/utils/async_client.jsx
+++ b/webapp/utils/async_client.jsx
@@ -111,26 +111,31 @@ export function getChannel(id) {
 }
 
 export function getMyChannelMembers() {
-    if (isCallInProgress('getMyChannelMembers')) {
-        return;
-    }
+    return new Promise((resolve, reject) => {
+        if (isCallInProgress('getMyChannelMembers')) {
+            resolve();
+            return;
+        }
 
-    callTracker.getMyChannelMembers = utils.getTimestamp();
+        callTracker.getMyChannelMembers = utils.getTimestamp();
 
-    Client.getMyChannelMembers(
-        (data) => {
-            callTracker.getMyChannelMembers = 0;
+        Client.getMyChannelMembers(
+            (data) => {
+                callTracker.getMyChannelMembers = 0;
 
-            AppDispatcher.handleServerAction({
-                type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
-                members: data
-            });
-        },
-        (err) => {
-            callTracker.getChannelsUnread = 0;
-            dispatchError(err, 'getMyChannelMembers');
-        }
-    );
+                AppDispatcher.handleServerAction({
+                    type: ActionTypes.RECEIVED_MY_CHANNEL_MEMBERS,
+                    members: data
+                });
+                resolve();
+            },
+            (err) => {
+                callTracker.getChannelsUnread = 0;
+                dispatchError(err, 'getMyChannelMembers');
+                reject();
+            }
+        );
+    });
 }
 
 export function updateLastViewedAt(id, active) {
@@ -263,28 +268,33 @@ export function getChannelStats(channelId = ChannelStore.getCurrentId(), doVersi
 }
 
 export function getChannelMember(channelId, userId) {
-    if (isCallInProgress(`getChannelMember${channelId}${userId}`)) {
-        return;
-    }
+    return new Promise((resolve, reject) => {
+        if (isCallInProgress(`getChannelMember${channelId}${userId}`)) {
+            resolve();
+            return;
+        }
 
-    callTracker[`getChannelMember${channelId}${userId}`] = utils.getTimestamp();
+        callTracker[`getChannelMember${channelId}${userId}`] = utils.getTimestamp();
 
-    Client.getChannelMember(
-        channelId,
-        userId,
-        (data) => {
-            callTracker[`getChannelMember${channelId}${userId}`] = 0;
+        Client.getChannelMember(
+            channelId,
+            userId,
+            (data) => {
+                callTracker[`getChannelMember${channelId}${userId}`] = 0;
 
-            AppDispatcher.handleServerAction({
-                type: ActionTypes.RECEIVED_CHANNEL_MEMBER,
-                member: data
-            });
-        },
-        (err) => {
-            callTracker[`getChannelMember${channelId}${userId}`] = 0;
-            dispatchError(err, 'getChannelMember');
-        }
-    );
+                AppDispatcher.handleServerAction({
+                    type: ActionTypes.RECEIVED_CHANNEL_MEMBER,
+                    member: data
+                });
+                resolve();
+            },
+            (err) => {
+                callTracker[`getChannelMember${channelId}${userId}`] = 0;
+                dispatchError(err, 'getChannelMember');
+                reject();
+            }
+        );
+    });
 }
 
 export function getUser(userId) {
-- 
cgit v1.2.3-1-g7c22

