From b704e9489b21b3bec17f5c8b573a1724781ee6f7 Mon Sep 17 00:00:00 2001
From: JoramWilander <jwawilander@gmail.com>
Date: Fri, 14 Aug 2015 08:43:49 -0400
Subject: added google sign-in functionality to the client, with minor model
 modifications

---
 web/react/stores/user_store.jsx | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

(limited to 'web/react/stores/user_store.jsx')

diff --git a/web/react/stores/user_store.jsx b/web/react/stores/user_store.jsx
index f8616c6ab..248495dac 100644
--- a/web/react/stores/user_store.jsx
+++ b/web/react/stores/user_store.jsx
@@ -4,6 +4,7 @@
 var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
 var EventEmitter = require('events').EventEmitter;
 var assign = require('object-assign');
+var client = require('../utils/client.jsx');
 
 var Constants = require('../utils/constants.jsx');
 var ActionTypes = Constants.ActionTypes;
@@ -72,7 +73,7 @@ var UserStore = assign({}, EventEmitter.prototype, {
             BrowserStore.setGlobalItem('current_user_id', id);
         }
     },
-    getCurrentId: function() {
+    getCurrentId: function(skipFetch) {
         var currentId = this.gCurrentId;
 
         if (currentId == null) {
@@ -80,6 +81,17 @@ var UserStore = assign({}, EventEmitter.prototype, {
             this.gCurrentId = currentId;
         }
 
+        // this is a special case to force fetch the
+        // current user if it's missing
+        // it's synchronous to block rendering
+        if (currentId == null && !skipFetch) {
+            var me = client.getMeSynchronous();
+            if (me != null) {
+                this.setCurrentUser(me);
+                currentId = me.id;
+            }
+        }
+
         return currentId;
     },
     getCurrentUser: function() {
-- 
cgit v1.2.3-1-g7c22

