Author: jerome
Date: 2009-10-21 12:06:28 +0200 (Wed, 21 Oct 2009)
New Revision: 5759

Modified:
   
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
   
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
Log:
* Fixed a bug getting messages count by sender ( message id was taken instead 
of user id ).
* Added a method to define current FB permissions.

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
    2009-10-21 10:03:30 UTC (rev 5758)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java
    2009-10-21 10:06:28 UTC (rev 5759)
@@ -34,6 +34,7 @@
 
 import com.google.code.facebookapi.FacebookException;
 import com.google.code.facebookapi.FacebookJsonRestClient;
+import com.kysoh.plugins.facebook.connection.FacebookSessionUtils;
 
 
 public class FacebookFunctions {
@@ -283,10 +284,11 @@
        public String getFacebookName(String uid)
        {
                String result = "Unknown";
-               String query = "SELECT name from user WHERE uid=";
+               String query = "SELECT name FROM user WHERE uid=";
                
                try 
                {
+                       System.out.println(client.fql_query(query + uid));
                        JSONArray username = (JSONArray) client.fql_query(query 
+ uid);
                        
                        result = username.getJSONObject( 0 ).getString("name");
@@ -337,29 +339,58 @@
        public Hashtable<String, Integer> getByNames(Hashtable<String, 
Vector<String>> baseHash)
        {
                Hashtable<String, Integer> result = new Hashtable<String, 
Integer>();
-               Vector<String> v = new Vector<String>(baseHash.keySet());
+               Vector<String> senders = new Vector<String>();
                
                //Handling no datas into hashtable.
-               if ( v.size() == 0)
+               if ( baseHash.keySet().size() == 0)
                {
                        return null;
                }
                
+               Iterator<String> it = baseHash.keySet().iterator();
+               
+               //Gettin all senders ( subject and message id are only for 
history stuff ).
+               while(it.hasNext())
+               {
+                       senders.add(baseHash.get(it.next()).get(1));
+               }
+               
                //Counting by names.
-               for( int i = 0 ; i != v.size() ; i ++)
+               for( int i = 0 ; i != senders.size() ; i ++)
                {       
-                       if (result.containsKey(v.get(i)))
+                       if (result.containsKey(senders.get(i)))
                        {
-                               Integer value = 
Integer.valueOf(result.get(v.get(i)) + 1);
-                           result.remove(v.get(i));
-                           result.put(v.get(i), value);
+                               Integer value = 
Integer.valueOf(result.get(senders.get(i)) + 1);
+                           result.remove(senders.get(i));
+                           result.put(senders.get(i), value);
                        }
                        else
                        {
-                           result.put(v.get(i), Integer.valueOf(1));
+                           result.put(senders.get(i), Integer.valueOf(1));
                        }
                }
                
                return result;
        }
+       
+       
+       /**
+        * Return the current fb rights for the plugin.
+        * @return
+        */
+       public Vector<String> getCurrentFBAuth()
+       {
+               Vector<String> rights = new Vector<String>();
+               
+               try 
+               {
+                       
System.out.println(client.permissions_checkAvailableApiAccess(FacebookSessionUtils.api_key));
+               } 
+               catch (FacebookException e) 
+               {
+                       ;
+               }
+               
+               return rights;
+       }
 }

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
       2009-10-21 10:03:30 UTC (rev 5758)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java
       2009-10-21 10:06:28 UTC (rev 5759)
@@ -104,6 +104,18 @@
                {
                        functions = new FacebookFunctions(facebook.getClient());
                        
+                       //Checking first if user has fb rights.
+                       if(!this.getCommand().equalsIgnoreCase("check"))
+                       {
+                               //like gmail plugin, only in run mode.
+                               functions.getCurrentFBAuth();
+                               
+                               if(false)
+                               {
+                                       this.doConfigure();
+                               }
+                       }
+                       
                        //Updating user status.
                        if(this.configuration().getUpdateStatus())
                        {
@@ -203,11 +215,11 @@
                        {
                                if (emailsBySender.get(sender).intValue() == 1)
                                {
-                                       this.throwMessage("One from {0}", 
functions.getFacebookName(sender));
+                                       this.throwMessage("One from {0}", 
sender);
                                }
                                else
                                {
-                                   this.throwMessage("{0} messages from {1}", 
functions.getFacebookName(sender), emailsBySender.get(sender));
+                                   this.throwMessage("{0} messages from {1}", 
sender, emailsBySender.get(sender));
                                }
                        }
                }


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to