[Pkg-mozext-commits] [gcontactsync] 04/09: Issue #78: Find All Groups button does not work

David Prévot taffit at moszumanska.debian.org
Sun Apr 12 03:15:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository gcontactsync.

commit 1e1f0c619134e474760e332cca187a9f5ef4f461
Author: Josh Geenen <joshgeenen at gmail.com>
Date:   Sat Apr 4 21:12:19 2015 -0500

    Issue #78: Find All Groups button does not work
---
 src/content/Accounts.js | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/content/Accounts.js b/src/content/Accounts.js
index c77f07b..8355488 100644
--- a/src/content/Accounts.js
+++ b/src/content/Accounts.js
@@ -359,26 +359,59 @@ com.gContactSync.Accounts = {
    */
   getAllGroups: function Accounts_getAllGroups(aUsername) {
     this.restoreGroups();
-    if (!aUsername || aUsername === "none")
+    if (!aUsername || aUsername === "none") {
       return false;
+    }
     var token = com.gContactSync.LoginManager.getAuthTokens()[aUsername];
     if (!token) {
       com.gContactSync.LOGGER.LOG_WARNING("Unable to find the token for username " + aUsername);
       return false;
     }
+    this.getAccessToken(token, aUsername);
+    return true;
+  },
+  /**
+   * Exchanges the refresh token for an access token.  On success, continues synchronization.
+   *
+   * @param aRefreshToken {string} A refresh token.
+   */
+  getAccessToken: function Accounts_getAccessToken(aRefreshToken, aUsername) {
+    com.gContactSync.LOGGER.VERBOSE_LOG("Requesting access token");
+    // Fetch an access token from the refresh token
+    var request = new com.gContactSync.GHttpRequest("REFRESH_REQUEST", aRefreshToken);
+    request.mOnSuccess = function getAccessTokenSuccess(aHttpRequest) {
+      var response = JSON.parse(aHttpRequest.responseText);
+      var accessToken = response.token_type + " " + response.access_token;
+      com.gContactSync.Accounts.sendGetGroupsRequest(accessToken, aUsername);
+    };
+    request.mOnError = function getAccessTokenError(httpReq) {
+      com.gContactSync.LOGGER.LOG_WARNING(httpReq.responseText);
+    };
+    request.mOnOffline = null;
+    request.send();
+  },
+  /**
+   * Sends the request to get the groups for a given username.
+   *
+   * @param aAccessToken {string} The access token.
+   * @param aUsername {string The username.
+   */
+  sendGetGroupsRequest: function Accounts_finishGetAllGroups(aAccessToken, aUsername) {
     com.gContactSync.LOGGER.VERBOSE_LOG("Fetching groups for username: " + aUsername);
-    var httpReq = new com.gContactSync.GHttpRequest("getGroups", token, null,
-                                   null, aUsername);
+    var httpReq = new com.gContactSync.GHttpRequest("getGroups",
+                                                    aAccessToken,
+                                                    null,
+                                                    null,
+                                                    aUsername);
     httpReq.mOnSuccess = function getAllGroupsSuccess(httpReq) {
       com.gContactSync.LOGGER.VERBOSE_LOG(com.gContactSync.serializeFromText(httpReq.responseText));
       com.gContactSync.Accounts.addGroups(httpReq.responseXML, aUsername);
     };
     httpReq.mOnError   = function getAllGroupsError(httpReq) {
-      com.gContactSync.LOGGER.LOG_ERROR(httpReq.responseText);
+      com.gContactSync.LOGGER.LOG_WARNING(httpReq.responseText);
     };
     httpReq.mOnOffline = null;
     httpReq.send();
-    return true;
   },
   /**
    * Adds groups in the given atom feed to the Groups menulist provided the

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/gcontactsync.git



More information about the Pkg-mozext-commits mailing list