From cfaf82372e1f6efd86fdc6771d242ceaed53a703 Mon Sep 17 00:00:00 2001 From: Nikita Bernstein Date: Sun, 29 Jul 2012 00:20:22 -0400 Subject: Checking in - can't figure out bug Can't figure out why FacebookFQL.js line 70 - 73 show different result than the graph navigator. Help? --- Resources/app.js | 6 +++ Resources/friendship/core/FacebookFQL.js | 66 +++++++++++++++++++++------- Resources/friendship/ui/ActivityIndicator.js | 15 +++++++ Resources/friendship/ui/ApplicationWindow.js | 1 + Resources/friendship/ui/LikeList.js | 32 +++++++++++--- tiapp.xml | 2 +- 6 files changed, 101 insertions(+), 21 deletions(-) diff --git a/Resources/app.js b/Resources/app.js index 3835b41..ecaba9a 100644 --- a/Resources/app.js +++ b/Resources/app.js @@ -2,6 +2,12 @@ Ti.include('/friendship/friendship.js'); fs.app.mainTabGroup = fs.ui.createApplicationTabGroup(); +function output_log( str ) +{ + Ti.API.info( str ); +} +output_log( "created a file"); + // Login switch if (Ti.Facebook.loggedIn) { fs.app.mainTabGroup.open(); diff --git a/Resources/friendship/core/FacebookFQL.js b/Resources/friendship/core/FacebookFQL.js index 823e86f..8b105f0 100644 --- a/Resources/friendship/core/FacebookFQL.js +++ b/Resources/friendship/core/FacebookFQL.js @@ -1,53 +1,84 @@ (function() { fs.core.queryFQL = function(fqlQuery, fqlCallback) { var fqlURL = "fql?q=" + fqlQuery.replace(/ /g, "+"); - //Ti.API.info("https://graph.facebook.com/" + fqlURL); + Ti.API.info("https://graph.facebook.com/" + fqlURL); Ti.Facebook.requestWithGraphPath(fqlURL, {}, 'GET', fqlCallback); }; fs.core.handleFQLResponse = function(response, eventName) { + Ti.App.fireEvent('app:msg.loader', {text:"Event: " + eventName }); if (response.success) { - //Ti.API.info(eventName + ": FQL response: got " + response.result.length + " Bytes"); + Ti.API.info(eventName + ": FQL response: got " + response.result.length + " Bytes"); if (response.result.length < 100) { - //Ti.API.info("> " + response.result); + Ti.API.info("> " + response.result); } var data = JSON.parse(response.result); - //Ti.API.info(eventName + ": FQL response: parsed " + data.length + " entries"); + Ti.API.info(eventName + ": FQL response: parsed " + data.length + " entries"); Ti.App.fireEvent(eventName, {data: data}); } else if (response.error) { - //Ti.API.info(eventName + ": FQL response error: " + response.error); + Ti.API.info(eventName + ": FQL response error: " + response.error); Ti.App.fireEvent("processFQLError", {what: response.error}); } else { - //Ti.API.info(eventName + ": FQL response error: UNKNOWN"); + Ti.API.info(eventName + ": FQL response error: UNKNOWN"); Ti.App.fireEvent("processFQLError", {what: "unrecognized query response"}); } }; // LATER: find some way to handle timeout (via Ti.Facebook....) + // -------------------------------------------- + // processFriendIDs + // -------------------------------------------- fs.core.handleFriendIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processFriendIDs"); }; fs.core.queryFriendIDsFQL = function() { - ////Ti.API.info("calling queryFriendIDsFQL"); + Ti.API.info("calling queryFriendIDsFQL"); + Ti.App.fireEvent('app:msg.loader', {text:"Getting Friend IDs."}); + 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); + output_log( query ); + Ti.Facebook.request( 'fql.query', {query: query}, fs.core.handleFriendIDsFQLResponse ); }; + // -------------------------------------------- + // processLikeIDs + // -------------------------------------------- + fs.core.handleLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); }; fs.core.queryLikeIDsFQL = function(friend_ids) { - //Ti.API.info("calling queryLikeIDsFQL:"); + Ti.API.info("calling queryLikeIDsFQL:"); + Ti.App.fireEvent('app:msg.loader', {text:"Pulling likes."}); var query = "SELECT page_id, created_time, uid FROM page_fan WHERE uid IN (" + friend_ids.join() + ")"; - //Ti.API.info(query); + output_log( query ); Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikeIDsFQLResponse); }; - fs.core.handleAllFriendLikeIDsFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikeIDs"); }; + // -------------------------------------------- + // processLikeIDs + // -------------------------------------------- + + fs.core.handleAllFriendLikeIDsFQLResponse = function (result) { + output_log( result ); + fs.core.handleFQLResponse(result, "processLikeIDs"); + }; fs.core.queryAllFriendLikeIDsFQL = function() { - //Ti.API.info("calling queryAllFriendLikeIDsFQL"); - var query = "SELECT page_id, created_time, uid FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = " + Ti.Facebook.uid + ")"; + Ti.API.info("calling queryAllFriendLikeIDsFQL"); + var ts = Math.round((new Date()).getTime() / 1000); + ts = ts - 2 * 14 * 24 * 60 * 60; + + Ti.App.fireEvent('app:msg.loader', {text:"Pulling all friends' likes."}); + + // BAH! Why is the result from this query via API different from the result on + // https://developers.facebook.com/tools/explorer?fql=SELECT%20page_id%2C%20created_time%2C%20uid%20FROM%20page_fan%20WHERE%20uid%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me())%20limit%205 + var query = "SELECT page_id, created_time, uid FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me() ) limit 5"; // " + Ti.Facebook.uid + " // and created_time > " + ts; + output_log( query ); Ti.Facebook.request('fql.query', {query: query}, fs.core.handleAllFriendLikeIDsFQLResponse); }; + // -------------------------------------------- + // processLikes + // -------------------------------------------- + fs.core.handleLikesFQLResponse = function (result) { fs.core.handleFQLResponse(result, "processLikes"); }; fs.core.queryLikesFQL = function(page_ids) { - //Ti.API.info("calling queryLikesFQL"); + Ti.API.info("calling queryLikesFQL"); //var query = "SELECT page_id, name, description, page_url, pic_square, fan_count, type, website, general_info "; //query += "FROM page WHERE page_id "; @@ -56,12 +87,17 @@ //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 IN (" + page_ids.join() + ")"; + output_log( query ); Ti.Facebook.request('fql.query', {query: query}, fs.core.handleLikesFQLResponse); }; + // -------------------------------------------- + // fetchMoreLikes + // -------------------------------------------- + fs.core.fetchMoreLikes = function(numLikesMore) { numLikesMore = Math.min((fs.data.reverseChronoLikedIDs.length - fs.data.numLikesFetched), numLikesMore); - //Ti.API.info("calling fetchMoreLikes: fetching more = " + numLikesMore + ", currently have: " + fs.data.numLikesFetched + ", total: " + fs.data.reverseChronoLikedIDs.length); + Ti.API.info("calling fetchMoreLikes: fetching more = " + numLikesMore + ", currently have: " + fs.data.numLikesFetched + ", total: " + fs.data.reverseChronoLikedIDs.length); page_ids = Array(); for (var i = fs.data.numLikesFetched; i < fs.data.numLikesFetched + numLikesMore; i++) { page_ids.push(fs.data.reverseChronoLikedIDs[i].pid); diff --git a/Resources/friendship/ui/ActivityIndicator.js b/Resources/friendship/ui/ActivityIndicator.js index 1430b6f..ef2949c 100644 --- a/Resources/friendship/ui/ActivityIndicator.js +++ b/Resources/friendship/ui/ActivityIndicator.js @@ -15,8 +15,19 @@ style: (fs.app.isAndroid) ? null : Titanium.UI.iPhone.ActivityIndicatorStyle.BIG }); + var loader_msg = Ti.UI.createLabel( { + text:'loading', + height:'auto', + width:'auto', + top:0, + color:'#fff', + font:{fontSize:10}, + textAlign:'center' + }); + loading_view.add(background); loading_view.add(loader); + loading_view.add( loader_msg ); loader.show(); Ti.App.addEventListener('app:show.loader', function() { @@ -24,6 +35,10 @@ loading_view.visible = true; } }); + + Ti.App.addEventListener('app:msg.loader', function(msg) { + loader_msg.text = msg.text; + }); Ti.App.addEventListener('app:hide.loader', function() { loading_view.visible = false; diff --git a/Resources/friendship/ui/ApplicationWindow.js b/Resources/friendship/ui/ApplicationWindow.js index 85809a0..75a6a31 100644 --- a/Resources/friendship/ui/ApplicationWindow.js +++ b/Resources/friendship/ui/ApplicationWindow.js @@ -37,6 +37,7 @@ Ti.App.addEventListener("refreshAllData", function(e) { if (Ti.Facebook.loggedIn) { Ti.App.fireEvent('app:show.loader'); + Ti.App.fireEvent('app:msg.loader', {text:"Loading up..."}); fs.core.queryFriendIDsFQL(); } }) diff --git a/Resources/friendship/ui/LikeList.js b/Resources/friendship/ui/LikeList.js index 39f71cf..5e637af 100644 --- a/Resources/friendship/ui/LikeList.js +++ b/Resources/friendship/ui/LikeList.js @@ -1,4 +1,5 @@ (function() { + var MAX_ROW_HEIGHT = 150; var lookup = { 'BOOK':'#b0d3a4', @@ -128,6 +129,7 @@ var liked_by = Ti.UI.createLabel({ text: key.friend_name, + //text: key.uid, font:{fontSize:11,fontWeight:'single'}, //color: 'white', @@ -196,6 +198,7 @@ }; fs.ui.createLikeList = function() { + var ll_view = Ti.UI.createTableView(); ll_view.maxRowHeight = MAX_ROW_HEIGHT; @@ -207,9 +210,11 @@ //Ti.App.fireEvent('app:show.loader'); Ti.App.addEventListener("processFriendIDs", function(e) { - //Ti.API.info("processFriendIDs callback"); + Ti.API.info("processFriendIDs callback"); fs.data.friends = Array(); for (var i = 0; i < e.data.length; i++) { + Ti.App.fireEvent('app:msg.loader', {text:"processFriendIDs: " + i }); + fs.data.friends[e.data[i].uid.toString()] = {uid: e.data[i].uid, pic: e.data[i].pic_square, name: e.data[i].name, selected: true}; } @@ -217,7 +222,9 @@ }); Ti.App.addEventListener("processLikeIDs", function(e) { - //Ti.API.info("processLikeIDs callback"); + Ti.API.info("processLikeIDs callback"); + Ti.App.fireEvent('app:msg.loader', {text:"processLikeIDs"}); + fs.data.likeIDs = Array(); fs.data.reverseChronoLikedIDs = Array(); @@ -225,6 +232,8 @@ pid = e.data[key].page_id + ''; tm = e.data[key].created_time; uid = e.data[key].uid; + + output_log( "Processing: pid = " + pid + ", uid = " + uid ); if (pid in fs.data.likeIDs) { fs.data.likeIDs[pid].count += 1; @@ -268,13 +277,26 @@ }); Ti.App.addEventListener("processLikes", function(e) { - //Ti.API.info("processLikes callback"); + Ti.API.info("processLikes callback"); + Ti.App.fireEvent('app:msg.loader', {text:"Process_likes - Callback."}); + for ( key in e.data ) { - e.data[key].more = fs.data.reverseChronoLikedIDs[fs.data.numLikesFetched]; - e.data[key].friend_name = friend_name_from_uid(e.data[key].more.uid); + Ti.App.fireEvent('app:msg.loader', {text:"Process_likes - " + key }); + + //e.data[key].friend_name = friend_name_from_uid(e.data[key].more.uid); + var page_id = e.data[key].page_id; + e.data[key].friend_name = friend_name_from_uid( fs.data.likeIDs[page_id].uid ); + output_log( "Page ID: " + page_id.toString() + + " -> uid: " + fs.data.likeIDs[page_id].uid + + " -> friend: " + friend_name_from_uid( fs.data.likeIDs[page_id].uid ) ); + //e.data[key].friend_name = "----aaaa----"; + fs.data.numLikesFetched++; ll_view.appendRow(create_row(e.data[key])); } + + // Moved from inside the loop. Is this ok? + e.data[key].more = fs.data.reverseChronoLikedIDs[fs.data.numLikesFetched]; ll_view.footerTitle = fs.data.numLikesFetched + " / " + fs.data.reverseChronoLikedIDs.length + " loaded"; fs.data.isQueryingMore = false; diff --git a/tiapp.xml b/tiapp.xml index a455030..bc1acaf 100644 --- a/tiapp.xml +++ b/tiapp.xml @@ -13,7 +13,7 @@ true false - 1.6.2 + 1.8.2 com.sphnx.Sphnx Sphnx 1.0 -- cgit v1.2.3