Commits

Anonymous committed 090a666

added new token event listener to TokenManager

  • Participants
  • Parent commits a707c8a

Comments (0)

Files changed (3)

File lib/Follower.js

    friends_url: "http://api.twitter.com/1/friends/ids.json",
    lookup_url: "http://api.twitter.com/1/users/lookup.json",
    init: function() {
-      chrome.self.onConnect.addListener(function(port) {
+      chrome.extension.onConnect.addListener(function(port) {
         port.onMessage.addListener(function(data) {
            if (data.over) {
+              console.log("updating menu");
               Follower.updateMenu(data.name);
            }
         });
       TokenManager.getAccounts().forEach(function(name){
             Follower.retrieveFollowingUsers(name);
             });
+      $(TokenManager).bind('new_token', function (event, token) {
+            Follower.retrieveFollowingUsers(token.screen_name);
+            });
    },
    lookupUsers: function(name, ids) {
       if(!ids) {

File lib/TokenManager.js

            token);
    },
    addToken: function(token) {
-     TokenManager.tokens[token.screen_name] = token;
-     TokenManager.save();
+     if (!TokenManager.getToken(token.screen_name)) {
+        TokenManager.tokens[token.screen_name] = token;
+        TokenManager.save();
+        $(TokenManager).trigger('new_token', [token]);
+     }
+     chrome.extension.sendRequest({
+           "add_token": true,
+           "name": token.screen_name,
+           });
    },
    removeToken: function(name) {
      delete TokenManager.tokens[name];
      var token = TokenManager.parseToken(response);
      if (token.oauth_token)
         TokenManager.addToken(token);
-     chrome.extension.sendRequest({
-           "got_access_token": true, 
-           "name": token.screen_name
-           });
    },
    save: function() {
      Persistence.oauthTokenData().save(TokenManager.tokens);

File options.html

         if (request.got_pin) {
            pinInput.value = request.pin;
         }
-        if (request.got_access_token) {
+        if (request.add_token) {
            if (request.name) {
               hidePin();
               signedIn(request.name);