this should make tag delivery (e.g. forums) work - but not yet fully tested

This commit is contained in:
friendica 2013-01-13 18:35:12 -08:00
parent 83ca9dfc23
commit 5182d6d820
3 changed files with 61 additions and 41 deletions

View File

@ -4,7 +4,7 @@ require_once('include/bbcode.php');
require_once('include/oembed.php'); require_once('include/oembed.php');
require_once('include/crypto.php'); require_once('include/crypto.php');
require_once('include/Photo.php'); require_once('include/Photo.php');
require_once('include/permissions.php');
function collect_recipients($item,&$private) { function collect_recipients($item,&$private) {
@ -31,13 +31,19 @@ function collect_recipients($item,&$private) {
); );
if($r) { if($r) {
foreach($r as $rr) { foreach($r as $rr) {
// FIXME check permissions of each
$recipients[] = $rr['abook_xchan']; $recipients[] = $rr['abook_xchan'];
} }
} }
$private = false; $private = false;
} }
// This is a somewhat expensive operation but important.
// Don't send this item to anybody who isn't allowed to see it
$recipients = check_list_permissions($item['uid'],$recipients,'view_stream');
return $recipients; return $recipients;
} }
@ -1511,13 +1517,6 @@ function tag_deliver($uid,$item_id) {
if(! count($u)) if(! count($u))
return; return;
// fixme - look for permissions allowing tag delivery
$community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
$prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false);
$i = q("select * from item where id = %d and uid = %d limit 1", $i = q("select * from item where id = %d and uid = %d limit 1",
intval($item_id), intval($item_id),
intval($uid) intval($uid)
@ -1552,8 +1551,8 @@ function tag_deliver($uid,$item_id) {
else else
return; return;
// At this point we've determined that the person receiving this post was mentioned in it.
// Now let's check for a reshare so we don't spam a forum // Now let's check if this mention was inside a reshare so we don't spam a forum
$body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']); $body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']);
@ -1563,7 +1562,8 @@ function tag_deliver($uid,$item_id) {
} }
// send a notification // All good.
// Send a notification
require_once('include/enotify.php'); require_once('include/enotify.php');
notification(array( notification(array(
@ -1587,39 +1587,34 @@ function tag_deliver($uid,$item_id) {
// FIXME // FIXME
// if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent'])) if(($item['item_flags'] & ITEM_WALL) || ($item['item_flags'] & ITEM_ORIGIN) || ($item['item_flags'] & ITEM_THREAD_TOP) || ($item['id'] != $item['parent']))
// return; return;
// now change this copy of the post to a forum head message and deliver to all the tgroup members // now change this copy of the post to a forum head message and deliver to all the tgroup members
// $c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1",
// intval($u[0]['uid'])
// );
// if(! count($c))
// return;
// also reset all the privacy bits to the forum default permissions // also reset all the privacy bits to the forum default permissions
$private = ($u[0]['allow_cid'] || $u[0]['allow_gid'] || $u[0]['deny_cid'] || $u[0]['deny_gid']) ? 1 : 0; $private = ($u[0]['allow_cid'] || $u[0]['allow_gid'] || $u[0]['deny_cid'] || $u[0]['deny_gid']) ? 1 : 0;
// $forum_mode = (($prvgroup) ? 2 : 1); $flag_bits = ITEM_WALL|ITEM_ORIGIN|ITEM_UPLINK;
if($private)
$flag_bits = $flag_bits | ITEM_PRIVATE;
// q("update item set wall = 1, origin = 1, forum_mode = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s', $r = q("update item set item_flags = ( $item_flags | %d ), owner_xchan = '%s', allow_cid = '%s', allow_gid = '%s',
// `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' where id = %d limit 1", deny_cid = '%s', deny_gid = '%s' where id = %d limit 1",
// intval($forum_mode), intval($flag_bits),
// dbesc($c[0]['name']), dbesc($u[0]['channel_hash']),
// dbesc($c[0]['url']), dbesc($u[0]['allow_cid']),
// dbesc($c[0]['thumb']), dbesc($u[0]['allow_gid']),
// intval($private), dbesc($u[0]['deny_cid']),
// dbesc($u[0]['allow_cid']), dbesc($u[0]['deny_gid']),
// dbesc($u[0]['allow_gid']), intval($item_id)
// dbesc($u[0]['deny_cid']), );
// dbesc($u[0]['deny_gid']), if($r)
// intval($item_id) proc_run('php','include/notifier.php','tgroup',$item_id);
// ); else
logger('tag_deliver: failed to update item');
// proc_run('php','include/notifier.php','tgroup',$item_id);
} }

View File

@ -234,19 +234,25 @@ function notifier_run($argv, $argc){
$encoded_item = encode_item($target_item); $encoded_item = encode_item($target_item);
$relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false); $relay_to_owner = (((! $top_level_post) && ($target_item['item_flags'] & ITEM_ORIGIN)) ? true : false);
$uplink = false;
// $cmd === 'relay' indicates the owner is sending it to the original recipients // $cmd === 'relay' indicates the owner is sending it to the original recipients
// don't allow the item in the relay command to relay to owner under any circumstances, it will loop // don't allow the item in the relay command to relay to owner under any circumstances, it will loop
logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false')); logger('notifier: relay_to_owner: ' . (($relay_to_owner) ? 'true' : 'false'));
logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false')); logger('notifier: top_level_post: ' . (($top_level_post) ? 'true' : 'false'));
logger('notifier: target_item_flags: ' . $target_item['item_flags'] . ' ' . (($target_item['item_flags'] & ITEM_ORIGIN ) ? 'true' : 'false')); logger('notifier: target_item_flags: ' . $target_item['item_flags'] . ' ' . (($target_item['item_flags'] & ITEM_ORIGIN ) ? 'true' : 'false'));
// tag_deliver'd post which needs to be sent back to the original author
if(($relay_to_owner) && ($cmd !== 'relay')) { if(($cmd === 'uplink') && ($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post)) {
$uplink = true;
}
if(($relay_to_owner || $uplink) && ($cmd !== 'relay')) {
logger('notifier: followup relay', LOGGER_DEBUG); logger('notifier: followup relay', LOGGER_DEBUG);
$recipients = array($parent_item['owner_xchan']); $recipients = array(($uplink) ? $parent_item['author_xchan'] : $parent_item['owner_xchan']);
$private = true; $private = true;
if(! $encoded_item['flags']) if(! $encoded_item['flags'])
$encoded_item['flags'] = array(); $encoded_item['flags'] = array();
@ -256,6 +262,15 @@ function notifier_run($argv, $argc){
logger('notifier: normal distribution', LOGGER_DEBUG); logger('notifier: normal distribution', LOGGER_DEBUG);
if($cmd === 'relay') if($cmd === 'relay')
logger('notifier: owner relay'); logger('notifier: owner relay');
// if our parent is a tag_delivery recipient, uplink to the original author causing
// a delivery fork.
if(($parent_item['item_flags'] & ITEM_UPLINK) && (! $top_level_post) && ($cmd !== 'uplink')) {
logger('notifier: uplinking this item');
proc_run('php','include/notifier.php','uplink',$item_id);
}
$private = false; $private = false;
$recipients = collect_recipients($parent_item,$private); $recipients = collect_recipients($parent_item,$private);

View File

@ -278,5 +278,15 @@ function perm_is_allowed($uid,$observer,$permission) {
} }
// Check a simple array of observers against a permissions
// return a simple array of those with permission
function check_list_permissions($uid,$arr,$perm) {
$result = array();
if($arr)
foreach($arr as $x)
if($perm_is_allowed($uid,$x,$perm))
$result[] = $x;
return($result);
}