Exemplo n.º 1
0
exports.toString = function(entry, options) {
  if (options && options.map) entry.map = dMap.map(entry);

  // just to be consistent
  if (!entry.types) entry.types = {};
  // get all the possible types
  dMap.typeOf(entry.idr, entry.types).forEach(function(type) {
    entry.types[type] = true;
  });
  Object.keys(entry.types).forEach(function(type) {
    if (type.indexOf('_') > 0 && PLURAL[type.split('_')[0]]) entry.types[PLURAL[type.split('_')[0]]] = true; // strip off the feed types
    if (PLURAL[type]) { // switch to the non-plural name
      entry.types[PLURAL[type]] = true;
      delete entry.types[type];
    }
  }); // map the feed ones to their parent too
  // to be nice and provide singular names consistently
  Object.keys(entry.types).forEach(function(type) {
    if (PLURAL[type]) entry.types[PLURAL[type]] = true;
  });
  if (entry.oembed && !entry.types[entry.oembed.type]) {
    entry.types[entry.oembed.type] = true;
  }
  if (entry.oembed && !entry.oembed.source_name) entry.oembed.source_name = idr.parse(entry.idr).host;

  if (options && options.select) {
    entry = lutil.selectFields(entry, options.select);
  } else if (options && options.fields) {
    var fentry = {};
    options.fields.split(',').forEach(function(field) {
      fentry[field] = fieldz(field.split('.'),entry);
    });
    entry = fentry;
  }
  
  if(entry.idr && entry.idr.indexOf("@twitter") > 0 && entry.idr.indexOf("@twitter/self") == -1 && options.app && lconfig.whitelist && lconfig.whitelist.indexOf(options.app) == -1)
  {
    delete entry.data;
  }

  if(entry.idr && entry.idr.indexOf("self") == -1) entry._warning = "This API is being deprecated, please contact support@singly.com";
  // workaround for v8/node6 see https://github.com/Singly/API/issues/35
  var str = JSON.stringify(entry);
  var len = str.length;
  str = str.replace(/[\u0080-\uffff]/g, function(ch) {
    var code = ch.charCodeAt(0).toString(16);
    while (code.length < 4) code = "0" + code;
    return "\\u" + code;
  });

  return str;
};
Exemplo n.º 2
0
  cset.forEach(function(entry) {
    if (!entry.saved) return; // only process *new* content!

    // we process our self entry specially to index global ids across the whole app
    var id = idr.parse(entry.idr);
    if (id.path === 'self') self = entry;

    // process based on the type
    var types = dMap.typeOf(entry.idr, entry.types);
    if (types.length === 0) return;
    if (types.indexOf('contacts') >= 0 || id.path === 'self') {
      // below we do a lot more work on contacts, including self
      id = idr.parse(entry.idr);
      // a device contact id is in the format devicename.accountid.appid@devices
      if (id.host === 'devices') deviceId = id.auth.split('.');
      var dest = encodeURIComponent(id.hash)+'@'+id.host;
      pids[dest] = entry;
      // TODO: for normal non-device contacts we should be looking for matching
      // phone/email's too, as they may not be friends on the same network but
      // across networks and still the same person
    }

    var participants = ijod.participants(entry);
    if (participants.length > 0) {
      var me = idr.parse(entry.idr).auth;
      // index of everyone we have interactions with
      if (participants.length > 1 && participants.indexOf(me) >= 0) {
        participants.forEach(function(p) {
          if (!iact.inter[p]) iact.inter[p] = 0;
          iact.inter[p]++;
        });
      }

      // keep track of sharing activity of others
      if (participants[0] !== me) {
        var author = participants[0];
        if (!iact.act[author]) iact.act[author] = 0;
        iact.act[author]++;
        // additionally track photos as a sub-sortable option
        if (types.indexOf('photos_feed') >= 0) {
          if (!iact.photos[author]) iact.photos[author] = 0;
          iact.photos[author]++;
        }
        // track last seen location
        var ll = dMap.get('ll', entry.data, entry.idr);
        if (ll && entry.at > (iact.ll[author] || 0)) iact.ll[author] = ll;
      }
    }
  });
Exemplo n.º 3
0
 cset.forEach(function(entry){
   var types = dMap.typeOf(entry.idr);
   if (types.indexOf('contacts') >= 0) entry._v = ver;
 });