diff options
| author | Anqi Xu | 2012-06-24 03:46:50 -0400 |
|---|---|---|
| committer | Anqi Xu | 2012-06-24 03:46:50 -0400 |
| commit | 8e4f2232fb36024dc931bdc25389f92d55cdef7c (patch) | |
| tree | 9993dc9a60b26a8d70ef697bc332785ddf1d9ccb | |
| parent | eb029dddd70cbb7541a892abb2eccea2671028f1 (diff) | |
| download | LikeFeed-8e4f2232fb36024dc931bdc25389f92d55cdef7c.tar.bz2 | |
Started sequential FQL queries coding
| -rw-r--r-- | Resources/friendship/core/FacebookFQL.js | 38 | ||||
| -rw-r--r-- | Resources/friendship/core/core.js | 2 | ||||
| -rw-r--r-- | Resources/friendship/ui/ApplicationWindow.js | 14 | ||||
| -rw-r--r-- | Resources/friendship/ui/LikeList.js | 27 | ||||
| -rw-r--r-- | Resources/friendship/ui/LoginWindow.js | 5 |
5 files changed, 67 insertions, 19 deletions
diff --git a/Resources/friendship/core/FacebookFQL.js b/Resources/friendship/core/FacebookFQL.js index 2d04bcb..e93abb0 100644 --- a/Resources/friendship/core/FacebookFQL.js +++ b/Resources/friendship/core/FacebookFQL.js @@ -16,15 +16,33 @@ } }; // TODO: find some way to handle timeout (via Ti.Facebook....) - fs.core.handleAllFriendPostsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processPosts"); }; - fs.core.queryAllFriendPostsFQL = function() { // TODO: make a variant that takes in user list and other filter info + fs.core.handleFriendIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processFriendIDs"); }; + fs.core.queryFriendIDsFQL = function() { + var query = "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")" + Ti.Facebook.request('fql.query', {query: query}, fs.core.handleFriendIDsFQLResponse); + }; + + fs.core.handleLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); }; + fs.core.queryLikeIDsFQL = function(friend_ids) { + var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (" + friend_ids.join() + ")"; + Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikeIDsFQLResponse); + }; + + fs.core.handleAllFriendLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); }; + fs.core.queryAllFriendLikeIDsFQL = function() { + var query = "SELECT page_id, created_time FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")"; + Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendLikeIDsFQLResponse); + }; + + fs.core.handleLikesFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikes"); }; + fs.core.queryLikesFQL = function(page_ids) { + //var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info "; + //query += "FROM page WHERE page_id "; + //query += "IN (SELECT page_id FROM page_fan WHERE uid "; + //query += "IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + "))"; + //query += " limit 20"; var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info "; - query += "FROM page WHERE page_id "; - query += "IN (SELECT page_id FROM page_fan WHERE uid "; - //query += "= " + Ti.Facebook.uid + ")"; - query += "IN (SELECT uid2 FROM friend WHERE uid1 = " + Titanium.Facebook.uid + "))"; - query += " limit 20"; // TODO: remove the limit - Ti.API.info(query); // TODO: remove debug printout - Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendPostsFQLResponse); - }; + query += "FROM page WHERE page_id IN (" + page_ids.join() + ")"; + Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikesFQLResponse); + }; })(); diff --git a/Resources/friendship/core/core.js b/Resources/friendship/core/core.js index dd75086..a1f150c 100644 --- a/Resources/friendship/core/core.js +++ b/Resources/friendship/core/core.js @@ -1,5 +1,7 @@ (function() { fs.core = {}; + fs.data = {}; + fs.data.friends = Array(); })(); Ti.include( diff --git a/Resources/friendship/ui/ApplicationWindow.js b/Resources/friendship/ui/ApplicationWindow.js index a88990d..b07838e 100644 --- a/Resources/friendship/ui/ApplicationWindow.js +++ b/Resources/friendship/ui/ApplicationWindow.js @@ -27,7 +27,19 @@ }); win.add(fs.ui.createLikeList()); - fs.ui.refreshLikeList(); + + Ti.API.addEventListener("processFQLError", function(e) { + alert(e.what); + }); + + Ti.API.addEventListener("refreshAllData", function(e) { + if (Ti.Facebook.loggedIn) { + Ti.App.fireEvent('app:show.loader'); + fs.core.queryFriendIDsFQL(); + } + }) + Ti.API.fireEvent("refreshAllData"); + tab_group.addTab(tab); return tab_group; diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js index 8440e01..775c408 100644 --- a/Resources/friendship/ui/LikeList.js +++ b/Resources/friendship/ui/LikeList.js @@ -136,11 +136,28 @@ // Ti.App.fireEvent('app:show.loader'); - Ti.API.addEventListener("processPosts", function(d) { - for ( key in d.data ) { - ll_view.appendRow( create_row( d.data[key] ) ); + Ti.API.addEventListener("processFriendIDs", function(e) { + fs.data.friends = e.data; + fs.core.queryAllFriendLikeIDsFQL(); + }); + + Ti.API.addEventListener("processLikeIDs", function(e) { + Ti.API.info("processLikeIDs"); + Ti.API.info(e.data); + for ( key in e.data ) { + // TODO: 0 go through all the page_ids and insert into a hashset/dictionary; update with latest create_time, and also ++; sort by latest time <- pbly need priority set, or jus filter after fact + //e.data[key].page_id + //e.data[key].created_time } + // TODO: disable the hide loader, and start slowly loading processLikes + Ti.App.fireEvent('app:hide.loader'); + }); + + Ti.API.addEventListener("processLikes", function(e) { + for ( key in e.data ) { + ll_view.appendRow(create_row(e.data[key])); + } Ti.App.fireEvent('app:hide.loader'); }); @@ -150,9 +167,7 @@ fs.ui.refreshLikeList = function(e) { if (Ti.Facebook.loggedIn) { Ti.App.fireEvent('app:show.loader'); - fs.core.queryAllFriendPostsFQL(); - } else { - Ti.Facebook.fireEvent('login'); + fs.core.queryAllFriendLikeIDsFQL(); // TODO: switch to friend_ids version of query } }; })(); diff --git a/Resources/friendship/ui/LoginWindow.js b/Resources/friendship/ui/LoginWindow.js index c6103ff..4593f82 100644 --- a/Resources/friendship/ui/LoginWindow.js +++ b/Resources/friendship/ui/LoginWindow.js @@ -6,6 +6,7 @@ Ti.Facebook.addEventListener('login', function(e) { if (e.success) { fs.app.mainTabGroup.open(); + Ti.API.fireEvent("refreshAllData"); } else { alert('Could not log into Facebook'); } @@ -40,6 +41,6 @@ win.add(view); return tab_group; - } - + }; + })(); |
