aboutsummaryrefslogtreecommitdiffstats
path: root/include/api.php
diff options
context:
space:
mode:
authorMicMee <michael@meer.name>2013-01-23 04:55:09 -0800
committerMicMee <michael@meer.name>2013-01-23 04:55:09 -0800
commit9996d5ee9b7196774cb1d95334507c20f1883428 (patch)
tree4c10561076f16d9f18b7b5943bc1930814c6d52c /include/api.php
parentfca354aa463e84b67fe62e4067905e8f363c0e80 (diff)
parent0b18dd15c5377da121f0fb781c0530ca0d328eb9 (diff)
downloadvolse-hubzilla-9996d5ee9b7196774cb1d95334507c20f1883428.tar.gz
volse-hubzilla-9996d5ee9b7196774cb1d95334507c20f1883428.tar.bz2
volse-hubzilla-9996d5ee9b7196774cb1d95334507c20f1883428.zip
Merge pull request #1 from friendica/master
get changes
Diffstat (limited to 'include/api.php')
-rw-r--r--include/api.php356
1 files changed, 171 insertions, 185 deletions
diff --git a/include/api.php b/include/api.php
index 1864d511e..cf4d45c1a 100644
--- a/include/api.php
+++ b/include/api.php
@@ -1,10 +1,11 @@
<?php
- require_once("bbcode.php");
- require_once("datetime.php");
- require_once("conversation.php");
- require_once("oauth.php");
- require_once("html2plain.php");
- require_once('include/security.php');
+
+require_once("bbcode.php");
+require_once("datetime.php");
+require_once("conversation.php");
+require_once("oauth.php");
+require_once("html2plain.php");
+require_once('include/security.php');
/*
*
@@ -12,7 +13,13 @@
*
*/
- $API = Array();
+
+ /**
+ ** TWITTER API
+ */
+
+ $API = array();
+
$called_api = Null;
// All commands which require authentication accept a "channel" parameter
@@ -114,6 +121,7 @@
/**************************
* MAIN API ENTRY POINT *
**************************/
+
function api_call(&$a){
GLOBAL $API, $called_api;
@@ -373,30 +381,20 @@
}
+
function api_item_get_user(&$a, $item) {
global $usercache;
// The author is our direct contact, in a conversation with us.
- if(link_compare($item['url'],$item['author-link'])) {
- return api_get_user($a,$item['cid']);
- }
- else {
- // The author may be a contact of ours, but is replying to somebody else.
- // Figure out if we know him/her.
- $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
- if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
- return api_get_user($a,$a->contacts[$normalised]['id']);
- }
+
+ if($item['author']['abook_id']) {
+ return api_get_user($a,$item['author']['abook_id']);
+ }
+
// We don't know this person directly.
- list($nick, $name) = array_map("trim",explode("(",$item['author-name']));
- $name=str_replace(")","",$name);
-
- if ($name == '')
- $name = $nick;
-
- if ($nick == '')
- $nick = $name;
+ $nick = substr($item['author']['xchan_addr'],0,strpos($item['author']['xchan_addr'],'@'));
+ $name = $item['author']['xchan_name'];
// Generating a random ID
if (is_null($usercache[$nick]) or !array_key_exists($nick, $usercache))
@@ -408,8 +406,8 @@
'screen_name' => $nick,
'location' => '', //$uinfo[0]['default-location'],
'description' => '',
- 'profile_image_url' => $item['author-avatar'],
- 'url' => $item['author-link'],
+ 'profile_image_url' => $item['author']['xchan_photo_m'],
+ 'url' => $item['author']['xchan_url'],
'protected' => false, #
'followers_count' => 0,
'friends_count' => 0,
@@ -466,9 +464,6 @@
return $ret;
}
- /**
- ** TWITTER API
- */
/**
* Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
@@ -524,27 +519,27 @@
function api_statuses_mediap(&$a, $type) {
- if (api_user()===false) {
- logger('api_statuses_update: no user');
- return false;
- }
- $user_info = api_get_user($a);
-
- $_REQUEST['type'] = 'wall';
- $_REQUEST['profile_uid'] = api_user();
- $_REQUEST['api_source'] = true;
- $txt = requestdata('status');
- //$txt = urldecode(requestdata('status'));
-
- require_once('library/HTMLPurifier.auto.php');
- require_once('include/html2bbcode.php');
-
- if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
+ if (api_user() === false) {
+ logger('api_statuses_update: no user');
+ return false;
+ }
+ $user_info = api_get_user($a);
+
+ $_REQUEST['type'] = 'wall';
+ $_REQUEST['profile_uid'] = api_user();
+ $_REQUEST['api_source'] = true;
+
+ $txt = requestdata('status');
+
+ require_once('library/HTMLPurifier.auto.php');
+ require_once('include/html2bbcode.php');
+
+ if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
$txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault();
- $config->set('Cache.DefinitionImpl', null);
+ $config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
- $txt = $purifier->purify($txt);
+ $txt = $purifier->purify($txt);
}
$txt = html2bbcode($txt);
@@ -552,10 +547,10 @@
$_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo
require_once('mod/wall_upload.php');
- $bebop = wall_upload_post($a);
+ $posted = wall_upload_post($a);
//now that we have the img url in bbcode we can add it to the status and insert the wall item.
- $_REQUEST['body']=$txt."\n\n".$bebop;
+ $_REQUEST['body']=$txt."\n\n".$posted;
require_once('mod/item.php');
item_post($a);
@@ -564,8 +559,6 @@
}
api_register_func('api/statuses/mediap','api_statuses_mediap', true);
-
-
function api_statuses_update(&$a, $type) {
if (api_user() === false) {
logger('api_statuses_update: no user');
@@ -647,13 +640,15 @@
// get last public message
+ require_once('include/security.php');
+
$lastwall = q("SELECT * from item where 1
- and not ( item_flags & %d ) and item_restrict = 0
+ and item_private != 0 and item_restrict = 0
and author_xchan = '%s'
and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = ''
and verb = '%s'
+ and uid in ( " . stream_perms_api_uids() . " )
order by created desc limit 1",
- intval(ITEM_PRIVATE),
dbesc($user_info['guid']),
dbesc(ACTIVITY_POST)
);
@@ -717,13 +712,15 @@
function api_users_show(&$a, $type){
$user_info = api_get_user($a);
+ require_once('include/security.php');
+
$lastwall = q("SELECT * from item where 1
- and not ( item_flags & %d ) and item_restrict = 0
+ and item_private != 0 and item_restrict = 0
and author_xchan = '%s'
and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = ''
and verb = '%s'
+ and uid in ( " . stream_perms_api_uids() . " )
order by created desc limit 1",
- intval(ITEM_PRIVATE),
dbesc($user_info['guid']),
dbesc(ACTIVITY_POST)
);
@@ -784,18 +781,20 @@
*/
function api_statuses_home_timeline(&$a, $type){
- if (api_user()===false) return false;
+ if (api_user() === false)
+ return false;
$user_info = api_get_user($a);
- // get last newtork messages
+ // get last network messages
// params
- $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
- $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
- if ($page<0) $page=0;
- $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
- $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
+ $count = (x($_REQUEST,'count')?$_REQUEST['count']:20);
+ $page = (x($_REQUEST,'page')?$_REQUEST['page']-1:0);
+ if($page < 0)
+ $page = 0;
+ $since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
+ $max_id = (x($_REQUEST,'max_id')?$_REQUEST['max_id']:0);
$exclude_replies = (x($_REQUEST,'exclude_replies')?1:0);
//$since_id = 0;//$since_id = (x($_REQUEST,'since_id')?$_REQUEST['since_id']:0);
@@ -809,33 +808,40 @@
if ($exclude_replies > 0)
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
- $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
- `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM `item`, `contact`
- WHERE `item`.`uid` = %d
- AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
- AND `contact`.`id` = `item`.`contact-id`
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+ if (api_user() != $user_info['uid']) {
+ $observer = get_app()->get_observer();
+ require_once('include/permissions.php');
+ if(! perm_is_allowed($user_info['uid'],(($observer) ? $observer['xchan_hash'] : ''),'view_stream'))
+ return '';
+ $sql_extra .= " and item_private = 0 ";
+ }
+
+ $r = q("SELECT * from item WHERE uid = %d and item_restrict = 0
$sql_extra
- AND `item`.`id`>%d
- ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
+ AND id > %d
+ ORDER BY received DESC LIMIT %d ,%d ",
intval($user_info['uid']),
intval($since_id),
- intval($start), intval($count)
+ intval($start),
+ intval($count)
);
+ xchan_query($r,true);
+
$ret = api_format_items($r,$user_info);
// We aren't going to try to figure out at the item, group, and page
// level which items you've seen and which you haven't. If you're looking
// at the network timeline just mark everything seen.
- $r = q("UPDATE `item` SET `unseen` = 0
- WHERE `unseen` = 1 AND `uid` = %d",
- intval($user_info['uid'])
- );
+ if (api_user() == $user_info['uid']) {
+ $r = q("UPDATE `item` SET item_flags = ( item_flags ^ %d )
+ WHERE item_flags & %d and uid = %d",
+ intval(ITEM_UNSEEN),
+ intval(ITEM_UNSEEN),
+ intval($user_info['uid'])
+ );
+ }
$data = array('$statuses' => $ret);
@@ -878,42 +884,22 @@
if ($max_id > 0)
$sql_extra = 'AND `item`.`id` <= '.intval($max_id);
+ require_once('include/security.php');
- /*$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
- `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM `item`, `contact`
- WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
- AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
- AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
- AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
- AND `contact`.`id` = `item`.`contact-id`
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+ $r = q("select * from item where item_restrict = 0
+ and allow_cid = '' and allow_gid = ''
+ and deny_cid = '' and deny_gid = ''
+ and item_private = 0
+ and uid in ( " . stream_perms_api_uids() . " )
$sql_extra
- AND `item`.`id`>%d
- ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
+ AND id > %d group by uri
+ order by received desc LIMIT %d, %d ",
intval($since_id),
- intval($start), intval($count)
- );*/
- $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
- `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`,
- `user`.`nickname`, `user`.`hidewall`
- FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
- LEFT JOIN `user` ON `user`.`uid` = `item`.`uid`
- WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
- AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
- AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
- AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- $sql_extra
- AND `item`.`id`>%d
- ORDER BY `received` DESC LIMIT %d, %d ",
- intval($since_id),
- intval($start),
- intval($count));
+ intval($start),
+ intval($count)
+ );
+
+ xchan_query($r,true);
$ret = api_format_items($r,$user_info);
@@ -926,7 +912,7 @@
break;
case "as":
$as = api_format_as($a, $ret, $user_info);
- $as['title'] = $a->config['sitename']." Public Timeline";
+ $as['title'] = $a->config['sitename']. " " . t('Public Timeline');
$as['link']['url'] = $a->get_baseurl()."/";
return($as);
break;
@@ -938,6 +924,7 @@
/**
*
+
*/
function api_statuses_show(&$a, $type){
if (api_user()===false) return false;
@@ -945,7 +932,7 @@
$user_info = api_get_user($a);
// params
- $id = intval($a->argv[3]);
+ $id = intval(argv(3));
logger('API: api_statuses_show: '.$id);
@@ -958,17 +945,10 @@
else
$sql_extra .= " AND `item`.`id` = %d";
- $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
- `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM `item`, `contact`
- WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
- AND `contact`.`id` = `item`.`contact-id`
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- $sql_extra",
+ $r = q("select * from item where item_restrict = 0 $sql_extra",
intval($id)
);
+ xchan_query($r,true);
$ret = api_format_items($r,$user_info);
@@ -997,34 +977,31 @@
$user_info = api_get_user($a);
// params
- $id = intval($a->argv[3]);
+ $id = intval(argv(3));
logger('API: api_statuses_repeat: '.$id);
//$include_entities = (x($_REQUEST,'include_entities')?$_REQUEST['include_entities']:false);
- $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `contact`.`nick` as `reply_author`,
- `contact`.`name`, `contact`.`photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
- `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn_id`, `contact`.`self`,
- `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
- FROM `item`, `contact`
- WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
- AND `contact`.`id` = `item`.`contact-id`
- AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
- $sql_extra
- AND `item`.`id`=%d",
+ $observer = get_app()->get_observer();
+
+ $r = q("SELECT * from item where item_restrict = 0 and id = %d limit 1",
intval($id)
);
- if ($r[0]['body'] != "") {
- $_REQUEST['body'] = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
- $_REQUEST['profile_uid'] = api_user();
- $_REQUEST['type'] = 'wall';
- $_REQUEST['api_source'] = true;
+ if(perm_is_allowed($r[0]['uid'],$observer['xchan_hash'],'view_stream')) {
+ if ($r[0]['body'] != "") {
+ $_REQUEST['body'] = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body'];
+ $_REQUEST['profile_uid'] = api_user();
+ $_REQUEST['type'] = 'wall';
+ $_REQUEST['api_source'] = true;
- require_once('mod/item.php');
- item_post($a);
+ require_once('mod/item.php');
+ item_post($a);
+ }
}
+ else
+ return false;
if ($type == 'xml')
$ok = "true";
@@ -1038,13 +1015,14 @@
/**
*
*/
+
function api_statuses_destroy(&$a, $type){
if (api_user()===false) return false;
$user_info = api_get_user($a);
// params
- $id = intval($a->argv[3]);
+ $id = intval(argv(3));
logger('API: api_statuses_destroy: '.$id);
@@ -1065,6 +1043,8 @@
* http://developer.twitter.com/doc/get/statuses/mentions
*
*/
+
+// FIXME
function api_statuses_mentions(&$a, $type){
if (api_user()===false) return false;
@@ -1142,6 +1122,7 @@
return api_apply_template("timeline", $type, $data);
}
api_register_func('api/statuses/mentions','api_statuses_mentions', true);
+ // FIXME?? I don't think mentions and replies are congruent in this case
api_register_func('api/statuses/replies','api_statuses_mentions', true);
@@ -1149,7 +1130,7 @@
if (api_user()===false) return false;
$user_info = api_get_user($a);
- // get last newtork messages
+ // get last network messages
logger("api_statuses_user_timeline: api_user: ". api_user() .
@@ -1325,7 +1306,7 @@
function api_format_messages($item, $recipient, $sender) {
// standard meta information
- $ret=Array(
+ $ret = array(
'id' => $item['id'],
'created_at' => api_date($item['created']),
'sender_id' => $sender['id'] ,
@@ -1364,25 +1345,27 @@
//logger('api_format_items: ' . print_r($user_info,true));
$a = get_app();
- $ret = Array();
+ $ret = array();
foreach($r as $item) {
localize_item($item);
- $status_user = (($item['cid']==$user_info['id'])?$user_info: api_item_get_user($a,$item));
- if ($item['parent']!=$item['id']) {
- $r = q("select id from item where parent=%s and id<%s order by id desc limit 1",
- intval($item['parent']), intval($item['id']));
+ $status_user = (($item['author_xchan']==$user_info['guid'])?$user_info: api_item_get_user($a,$item));
+
+ if($item['parent'] != $item['id']) {
+ $r = q("select id from item where parent= %d and id < %d order by id desc limit 1",
+ intval($item['parent']),
+ intval($item['id'])
+ );
if ($r)
$in_reply_to_status_id = $r[0]['id'];
else
$in_reply_to_status_id = $item['parent'];
- $r = q("select `item`.`contact-id`, `contact`.nick, `item`.`author-name` from item, contact
- where `contact`.`id` = `item`.`contact-id` and `item`.id=%d", intval($in_reply_to_status_id));
+ xchan_query($r,true);
- $in_reply_to_screen_name = $r[0]['author-name'];
- $in_reply_to_user_id = $r[0]['contact-id'];
+ $in_reply_to_screen_name = $r[0]['author']['xchan_name'];
+ $in_reply_to_user_id = $r[0]['author']['abook_id'];
} else {
$in_reply_to_screen_name = '';
@@ -1399,41 +1382,39 @@
else
$statustext = trim($statustitle."\n\n".$statusbody);
- if (($item["network"] == NETWORK_FEED) and (strlen($statustext)> 1000))
- $statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
$status = array(
- 'text' => $statustext,
- 'truncated' => False,
- 'created_at'=> api_date($item['created']),
- 'in_reply_to_status_id' => $in_reply_to_status_id,
- 'source' => (($item['app']) ? $item['app'] : 'web'),
- 'id' => intval($item['id']),
- 'in_reply_to_user_id' => $in_reply_to_user_id,
- 'in_reply_to_screen_name' => $in_reply_to_screen_name,
- 'geo' => '',
- 'favorited' => $item['starred'] ? true : false,
- 'user' => $status_user ,
- 'statusnet_html' => trim(bbcode($item['body'])),
+ 'text' => $statustext,
+ 'truncated' => False,
+ 'created_at' => api_date($item['created']),
+ 'in_reply_to_status_id' => $in_reply_to_status_id,
+ 'source' => (($item['app']) ? $item['app'] : 'web'),
+ 'id' => intval($item['id']),
+ 'in_reply_to_user_id' => $in_reply_to_user_id,
+ 'in_reply_to_screen_name' => $in_reply_to_screen_name,
+ 'geo' => '',
+ 'favorited' => (($item['item_flags'] & ITEM_STARRED) ? true : false),
+ 'user' => $status_user ,
+ 'statusnet_html' => trim(bbcode($item['body'])),
'statusnet_conversation_id' => $item['parent'],
);
// Seesmic doesn't like the following content
if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') {
$status2 = array(
- 'updated' => api_date($item['edited']),
- 'published' => api_date($item['created']),
- 'message_id' => $item['uri'],
- 'url' => ($item['plink']!=''?$item['plink']:$item['author-link']),
- 'coordinates' => $item['coord'],
- 'place' => $item['location'],
+ 'updated' => api_date($item['edited']),
+ 'published' => api_date($item['created']),
+ 'message_id' => $item['uri'],
+ 'url' => $item['plink'],
+ 'coordinates' => $item['coord'],
+ 'place' => $item['location'],
'contributors' => '',
'annotations' => '',
- 'entities' => '',
- 'objecttype' => (($item['obj_type']) ? $item['obj_type'] : ACTIVITY_OBJ_NOTE),
- 'verb' => (($item['verb']) ? $item['verb'] : ACTIVITY_POST),
- 'self' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
- 'edit' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
+ 'entities' => '',
+ 'objecttype' => (($item['obj_type']) ? $item['obj_type'] : ACTIVITY_OBJ_NOTE),
+ 'verb' => (($item['verb']) ? $item['verb'] : ACTIVITY_POST),
+ 'self' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
+ 'edit' => $a->get_baseurl()."/api/statuses/show/".$item['id'].".".$type,
);
$status = array_merge($status, $status2);
@@ -1499,12 +1480,14 @@
return false;
}
+ // For Red, the closest thing we can do to figure out if you're friends is if both of you are sending each other your streams.
+ // This won't work if either of you send your stream to everybody on the network
if($qtype == 'friends')
- $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
+ $sql_extra = sprintf(" AND ( their_perms & %d ) and ( my_perms & %d ) ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
if($qtype == 'followers')
- $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
+ $sql_extra = sprintf(" AND ( my_perms & %d ) and not ( their_perms & %d ) ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
- $r = q("SELECT id FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
+ $r = q("SELECT id FROM abook where abook_flags = 0 and abook_channel = %d $sql_extra",
intval(api_user())
);
@@ -1611,13 +1594,16 @@
if(! api_user())
return false;
+
+ // For Red, the closest thing we can do to figure out if you're friends is if both of you are sending each other your streams.
+ // This won't work if either of you send your stream to everybody on the network
+
if($qtype == 'friends')
- $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
+ $sql_extra = sprintf(" AND ( their_perms & %d ) and ( my_perms & %d ) ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
if($qtype == 'followers')
- $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
+ $sql_extra = sprintf(" AND ( my_perms & %d ) and not ( their_perms & %d ) ", intval(PERMS_W_STREAM), intval(PERMS_W_STREAM));
-
- $r = q("SELECT id FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 $sql_extra",
+ $r = q("SELECT id FROM abook where abook_flags = 0 and abook_channel = %d $sql_extra",
intval(api_user())
);