close

  
<p> var General = acre.require("lib_general");
var FBLib = acre.require("/user/fbclient/fbclient/lib", General.client_version);
var Recommend = acre.require("lib_recommend");

function all_users(params) {
  var visitor = FBLib.util.get_user_info();
  
  var output_query = [General.require_query("user_info")];
  var filter_query = [General.require_query("tippify_user_query")];
  
  var user_recs_query = {
    "id": null,
    "recs:/type/attribution/links": {
      "source": {
        "type":  "/type/attribution",
        "/freebase/written_by/application": {
          "id": General.app_id
        },
        "/type/attribution/links": [{
          "source": {
            "type": Recommend.recommend_type
          },
          "target":  General.require_query("list_entry_query")[0],
          "timestamp": null,
          "sort": "-timestamp",
          "master_property": "/freebase/list/entries",
          "limit": 3,
          "optional": true
        }]
      },
      "limit": 1,
      "optional": true
    }
  };
  
  output_query = acre.freebase.extend_query(output_query, user_recs_query);
  output_query = acre.freebase.extend_query(output_query, {'/freebase/user_profile/watched_items./type/attribution/links': General.require_query("tippify_user_query")['/type/attribution/links']});
  output_query = acre.freebase.extend_query(output_query, {'!/freebase/user_profile/watched_items./type/attribution/links': General.require_query("tippify_user_query")['/type/attribution/links']});
  
  output_query = acre.freebase.extend_query(output_query, {'!rank:/freebase/user_profile/watched_items': General.require_query("tippify_user_query")});
  output_query = acre.freebase.extend_query(output_query, {'!rank:/freebase/user_profile/watched_items.return': 'count'});
  output_query = acre.freebase.extend_query(output_query, {'!rank:/freebase/user_profile/watched_items.optional': true});
  output_query = acre.freebase.extend_query(output_query, {'sort': '-!rank:/freebase/user_profile/watched_items.count'});
  
  if (visitor) {
    filter_query = acre.freebase.extend_query(filter_query, {"notvisitor:key": {
      "value": visitor.username,
      "namespace": "/user",
      "optional": "forbidden"
    }});
    output_query = acre.freebase.extend_query(output_query, {'!visitor:/freebase/user_profile/watched_items.id': visitor.id});
    output_query = acre.freebase.extend_query(output_query, {'!visitor:/freebase/user_profile/watched_items.optional': true});
  }
  
  if (params.following) {
    filter_query = acre.freebase.extend_query(filter_query, {'following:/freebase/user_profile/watched_items.id': params.following});
  }
  
  if (params.notfollowing) {
    filter_query = acre.freebase.extend_query(filter_query, {'notfollowing:/freebase/user_profile/watched_items.id': params.notfollowing});
    filter_query = acre.freebase.extend_query(filter_query, {'notfollowing:/freebase/user_profile/watched_items.optional': "forbidden"});
  }
  
  if (params.followedby) {
    filter_query = acre.freebase.extend_query(filter_query, {'!followedby:/freebase/user_profile/watched_items.id': params.followedby});
  }
  
  if (params.notfollowedby) {
    filter_query = acre.freebase.extend_query(filter_query, {'!notfollowedby:/freebase/user_profile/watched_items.id': params.notfollowedby});
    filter_query = acre.freebase.extend_query(filter_query, {'!notfollowedby:/freebase/user_profile/watched_items.optional': "forbidden"});
  }
  console.log(output_query, filter_query);
  var result = [];
  if (params.name) {
    result = acre.freebase.search(params.name, {
      "type": "/type/user",
      "mql_filter": filter_query,
      "mql_output": output_query
    }).result;
  } else {
    var query = acre.freebase.extend_query(output_query, filter_query[0]);
    result = acre.freebase.mqlread(query).result;
  }
  console.log(query, result);
  var users = [];
  for (var i in result) {
    var user = result[i];
    user['recs'] = [];
    for (var j in result[i]['recs:/type/attribution/links']['source']['/type/attribution/links']) {
      user['recs'].push(result[i]['recs:/type/attribution/links']['source']['/type/attribution/links'][j].target);
    }
    users.push(user);
  }
  return users;
}

function following_users(user_id) {
  var query = [{
      "id": null,
      "name": null,
      "/freebase/user_profile/my_full_name": null,
      "type": "/type/user",
      "!/freebase/user_profile/watched_items": {
        "id": user_id
      },
      "/type/attribution/links": General.require_query("tippify_user_query")['/type/attribution/links'],
      "limit": 1000
    }];
    return acre.freebase.mqlread(query).result;
}
       
function followed_by_users(user_id) {
  var query = [{
      "id": null,
      "name": null,
      "/freebase/user_profile/my_full_name": null,
      "type": "/type/user",
      "/freebase/user_profile/watched_items": {
        "id": user_id
      },
      "/type/attribution/links": General.require_query("tippify_user_query")['/type/attribution/links'],
      "limit": 1000
    }];
    return acre.freebase.mqlread(query).result;
}

function full_user_info(user_id) {
  var query = General.require_query("full_user_info");
  query = acre.freebase.extend_query(query, {"id": user_id});
  query = acre.freebase.extend_query(query, {'/freebase/user_profile/watched_items./type/attribution/links': General.require_query("tippify_user_query")['/type/attribution/links']});
  query = acre.freebase.extend_query(query, {'!/freebase/user_profile/watched_items./type/attribution/links': General.require_query("tippify_user_query")['/type/attribution/links']});
  
  var visitor = FBLib.util.get_user_info();
  if (visitor) {
    query = acre.freebase.extend_query(query, {"!visitor:/freebase/user_profile/watched_items.id": visitor.id});
    query = acre.freebase.extend_query(query, {"!visitor:/freebase/user_profile/watched_items.optional": true});
  }
  return acre.freebase.mqlread(query).result;
}

function attributions(user_ids) {
  var query = [{
    "type": "/type/attribution",
    "/freebase/written_by/application": {
      "id": General.app_id
    },
    "attribution": {
      "id|=": user_ids
    },
    "id": null
  }];
  return acre.freebase.mqlread(query).result;
}


 </p>

Comments

Hide