mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:35:13 +00:00
remove all the FEP-5624 stuff - it is no longer compatible
This commit is contained in:
parent
7c2fd81fd0
commit
5c86943112
7 changed files with 11 additions and 373 deletions
|
@ -452,8 +452,7 @@ class Notifier implements DaemonInterface
|
|||
$upstream = true;
|
||||
self::$packet_type = 'response';
|
||||
$is_moderated = their_perms_contains($parent_item['uid'], (is_array($sendto) ? $sendto[0] : $sendto), 'moderated');
|
||||
$allowed_comment = $target_item['approved'] || !Config::Get('system', 'use_fep5624');
|
||||
if ($relay_to_owner && $thread_is_public && $allowed_comment && (! $is_moderated) && (! $question) && (! Channel::is_group($parent_item['uid']))) {
|
||||
if ($relay_to_owner && $thread_is_public && (! $is_moderated) && (! $question) && (! Channel::is_group($parent_item['uid']))) {
|
||||
if (get_pconfig($target_item['uid'], 'system', 'hyperdrive', true)) {
|
||||
Run::Summon([ 'Notifier' , 'hyper', $item_id ]);
|
||||
}
|
||||
|
@ -487,7 +486,7 @@ class Notifier implements DaemonInterface
|
|||
}
|
||||
|
||||
|
||||
if ($thread_is_public && $target_item['approved'] && $cmd === 'hyper') {
|
||||
if ($thread_is_public && $cmd === 'hyper') {
|
||||
// Add hyperdrive (friend-of-friend recipients for public activities.
|
||||
// Don't add Hubzilla (zot6) connections, since that software doesn't support
|
||||
// hyperdrive and this would just clutter the airwaves with rejected deliveries.
|
||||
|
|
|
@ -1244,9 +1244,6 @@ class Activity
|
|||
}
|
||||
|
||||
if ($item['mid'] !== $item['parent_mid']) {
|
||||
if ($item['approved']) {
|
||||
$activity['approval'] = $item['approved'];
|
||||
}
|
||||
$activity['inReplyTo'] = $item['thr_parent'];
|
||||
$cnv = get_iconfig($item['parent'], 'activitypub', 'context');
|
||||
if (!$cnv) {
|
||||
|
@ -3956,24 +3953,9 @@ class Activity
|
|||
}
|
||||
}
|
||||
}
|
||||
if ($item['approved']) {
|
||||
$valid = CommentApproval::verify($item, $channel);
|
||||
if (!$valid) {
|
||||
logger('commentApproval failed');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$objtype = $act->objprop('type','');
|
||||
if (in_array($item['verb'], ['Accept', 'Reject']) && !in_array($objtype, ['Invite', 'Event'])) {
|
||||
if (CommentApproval::doVerify($item, $channel, $act)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$item['approved'] && $parent_item['owner_xchan'] === $channel['channel_hash'] && $item['author_xchan'] !== $channel['channel_hash']) {
|
||||
$commentApproval = new CommentApproval($channel, $item);
|
||||
}
|
||||
|
||||
$allowed = self::comment_allowed($channel, $item, $parent_item);
|
||||
|
||||
|
@ -3983,16 +3965,10 @@ class Activity
|
|||
|| $allowed === 'moderated') {
|
||||
$item['item_blocked'] = ITEM_MODERATED;
|
||||
}
|
||||
if ($item['item_blocked'] !== ITEM_MODERATED && $commentApproval) {
|
||||
$commentApproval->Accept();
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
logger('rejected comment from ' . $item['author_xchan'] . ' for ' . $channel['channel_address']);
|
||||
logger('rejected: ' . print_r($item, true), LOGGER_DATA);
|
||||
// let the sender know we received their comment, but we don't permit spam here.
|
||||
$commentApproval?->Reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -4001,16 +3977,7 @@ class Activity
|
|||
// A side effect of this action is that if you take away send_stream permission, comments to those
|
||||
// posts you previously allowed will still be accepted. It is possible but might be difficult to fix this.
|
||||
|
||||
if ($item['approved']) {
|
||||
$allowed = CommentApproval::verify($item, $channel);
|
||||
if (!$allowed) {
|
||||
logger('commentApproval failed');
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$allowed = !(bool) Config::Get('system', 'use_fep5624');
|
||||
}
|
||||
$allowed = true;
|
||||
|
||||
// reject public stream comments that weren't sent by the conversation owner
|
||||
// but only on remote message deliveries to our site ($fetch_parents === true)
|
||||
|
@ -4909,6 +4876,7 @@ class Activity
|
|||
->setObjType($object['type'])
|
||||
->setParentMid(str_replace('/conversation/','/item/', $target))
|
||||
->setThrParent(str_replace('/conversation/','/item/', $target))
|
||||
->setApproved($object['object']['id'] ?? '')
|
||||
->setReplyto(z_root() . '/channel/' . $channel['channel_address'])
|
||||
->setTgtType('Collection')
|
||||
->setTarget([
|
||||
|
|
|
@ -1,326 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Code\Lib;
|
||||
|
||||
use Code\Daemon\Run;
|
||||
|
||||
class CommentApproval
|
||||
{
|
||||
protected $channel = null;
|
||||
protected $item = null;
|
||||
|
||||
public function __construct($channel, $item)
|
||||
{
|
||||
if (Config::Get('system', 'use_fep5624')) {
|
||||
$this->channel = $channel;
|
||||
$this->item = $item;
|
||||
}
|
||||
}
|
||||
|
||||
public function Accept()
|
||||
{
|
||||
if (!$this->item) {
|
||||
return;
|
||||
}
|
||||
$obj = $this->item['obj'];
|
||||
if (! is_array($obj)) {
|
||||
$obj = json_decode($obj, true);
|
||||
}
|
||||
|
||||
// Have I approved this already?
|
||||
$approvals = q("select * from item where verb = 'Accept' and obj = '%s' and uid = %d",
|
||||
dbesc('"' . $obj['id'] . '"'),
|
||||
dbesc($this->channel['channel_id'])
|
||||
);
|
||||
|
||||
if ($approvals) {
|
||||
return;
|
||||
}
|
||||
$parent = $this->get_parent();
|
||||
$activity = post_activity_item(
|
||||
[
|
||||
'verb' => 'Accept',
|
||||
'obj_type' => $obj['type'],
|
||||
'obj' => $obj['id'],
|
||||
'item_wall' => 1,
|
||||
'allow_cid' => '',
|
||||
'owner_xchan' => $this->channel['xchan_hash'],
|
||||
'author_xchan' => $this->channel['xchan_hash'],
|
||||
'parent_mid' => $parent,
|
||||
'thr_parent' => $parent,
|
||||
'uid' => $this->channel['channel_id'],
|
||||
'title' => 'comment accepted'
|
||||
],
|
||||
deliver: false,
|
||||
channel: $this->channel,
|
||||
observer: $this->channel
|
||||
);
|
||||
if ($activity['item_id']) {
|
||||
IConfig::Set($activity['item_id'], 'system', 'comment_recipient', $this->item['author_xchan']);
|
||||
}
|
||||
q("UPDATE item SET approved = '%s' WHERE id = %d",
|
||||
dbesc(str_replace('/item/','/activity/', $activity['activity']['mid'])),
|
||||
intval($activity['item_id'])
|
||||
);
|
||||
|
||||
Run::Summon(['Notifier', 'comment_approval', $activity['item_id']]);
|
||||
}
|
||||
|
||||
public function Reject()
|
||||
{
|
||||
if (!$this->item) {
|
||||
return;
|
||||
}
|
||||
$obj = $this->item['obj'];
|
||||
if (! is_array($obj)) {
|
||||
$obj = json_decode($obj, true);
|
||||
}
|
||||
|
||||
// Have I rejected this already?
|
||||
$rejections = q("select * from item where verb = 'Reject' and obj = '%s' and uid = %d",
|
||||
dbesc('"' . $obj['id'] . '"'),
|
||||
dbesc($this->channel['channel_id'])
|
||||
);
|
||||
|
||||
if ($rejections) {
|
||||
return;
|
||||
}
|
||||
$parent = $this->get_parent();
|
||||
$activity = post_activity_item(
|
||||
[
|
||||
'verb' => 'Reject',
|
||||
'obj_type' => $obj['type'],
|
||||
'obj' => $obj['id'],
|
||||
'item_wall' => 1,
|
||||
'allow_cid' => '',
|
||||
'owner_xchan' => $this->channel['xchan_hash'],
|
||||
'author_xchan' => $this->channel['xchan_hash'],
|
||||
'parent_mid' => $parent,
|
||||
'thr_parent' => $parent,
|
||||
'uid' => $this->channel['channel_id'],
|
||||
'title' => 'comment rejected'
|
||||
],
|
||||
deliver: false,
|
||||
channel: $this->channel,
|
||||
observer: $this->channel
|
||||
);
|
||||
if ($activity['item_id']) {
|
||||
IConfig::Set($activity['item_id'], 'system', 'comment_recipient', $this->item['author_xchan']);
|
||||
}
|
||||
q("UPDATE item SET approved = '' WHERE id = %d",
|
||||
intval($activity['item_id'])
|
||||
);
|
||||
|
||||
Run::Summon(['Notifier', 'comment_approval', $activity['item_id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* To be considered valid, the Accept activity referenced in approval MUST
|
||||
* satisfy the following properties:
|
||||
*
|
||||
* its actor property is the authority
|
||||
* its authenticity can be asserted
|
||||
* its object property is the reply under consideration
|
||||
* its inReplyTo property matches that of the reply under consideration
|
||||
*
|
||||
* In addition, if the reply is considered valid, but has no valid approval
|
||||
* despite the object it is in reply to having a canReply property, the recipient MAY hide
|
||||
* the reply from certain views.
|
||||
*/
|
||||
public static function verify($item, $channel, $approvalActivity = null)
|
||||
{
|
||||
|
||||
if(!$approvalActivity) {
|
||||
$approvalActivity = Activity::fetch($item['approved'], $channel, true);
|
||||
}
|
||||
if (! $approvalActivity) {
|
||||
logger('no approval activity');
|
||||
return false;
|
||||
}
|
||||
$parent_item = q("select * from item where mid = '%s'", $item['parent_mid']);
|
||||
if (!$parent_item) {
|
||||
logger('no parent item');
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($approvalActivity instanceof ActivityStreams) {
|
||||
$act = $approvalActivity;
|
||||
}
|
||||
else {
|
||||
$act = new ActivityStreams($approvalActivity);
|
||||
}
|
||||
if (! $act->is_valid()) {
|
||||
logger('invalid parse');
|
||||
return false;
|
||||
}
|
||||
if (!$act->obj) {
|
||||
logger('no object');
|
||||
return false;
|
||||
}
|
||||
if ($act->type !== 'Accept') {
|
||||
logger('not an accept');
|
||||
return false;
|
||||
}
|
||||
if (!isset($act->actor)) {
|
||||
logger('no actor');
|
||||
return false;
|
||||
}
|
||||
$sender = Activity::find_best_identity($act->actor['id']);
|
||||
if (!$sender || $sender !== $parent_item[0]['owner_xchan']) {
|
||||
logger('no identity');
|
||||
return false;
|
||||
}
|
||||
$comment = is_string($act->obj) ? $act->obj : $act->obj['id'];
|
||||
if ($comment !== $item['mid']) {
|
||||
logger('incorrect mid');
|
||||
return false;
|
||||
}
|
||||
if(!in_array($act->parent_id, [$item['thr_parent'], $item['parent_mid']])) {
|
||||
logger('wrong provenance');
|
||||
logger('act: ' . $act->parent_id);
|
||||
logger('item: ' . print_r($item,true));
|
||||
return false;
|
||||
}
|
||||
logger('comment verified', LOGGER_DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function verifyReject($item, $channel, $approvalActivity = null)
|
||||
{
|
||||
|
||||
if(!$approvalActivity) {
|
||||
$approvalActivity = Activity::fetch($item['approved'], $channel, true);
|
||||
}
|
||||
$parent_item = q("select * from item where mid = '%s'", $item['parent_mid']);
|
||||
|
||||
if (! $approvalActivity) {
|
||||
return false;
|
||||
}
|
||||
if (!$parent_item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($approvalActivity instanceof ActivityStreams) {
|
||||
$act = $approvalActivity;
|
||||
}
|
||||
else {
|
||||
$act = new ActivityStreams($approvalActivity);
|
||||
}
|
||||
if (! $act->is_valid()) {
|
||||
return false;
|
||||
}
|
||||
if (!$act->obj) {
|
||||
return false;
|
||||
}
|
||||
if ($act->type !== 'Reject') {
|
||||
return false;
|
||||
}
|
||||
if (!isset($act->actor)) {
|
||||
return false;
|
||||
}
|
||||
$sender = Activity::find_best_identity($act->actor['id']);
|
||||
if (!$sender || $sender !== $parent_item['owner_xchan']) {
|
||||
return false;
|
||||
}
|
||||
$comment = is_string($act->obj) ? $act->obj : $act->obj['id'];
|
||||
if ($comment !== $item['mid']) {
|
||||
return false;
|
||||
}
|
||||
if(!in_array($act->parent_id, [$item['thr_parent'], $item['parent_mid']])) {
|
||||
return false;
|
||||
}
|
||||
logger('comment verified', LOGGER_DEBUG);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function doVerify($arr, $channel, $act)
|
||||
{
|
||||
logger('verifying comment accept/reject', LOGGER_DEBUG);
|
||||
$i = q("select * from item where mid = '%s' and uid = %d",
|
||||
dbesc(is_array($arr['obj']) ? $arr['obj']['id'] : $arr['obj']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($i) {
|
||||
|
||||
if ($arr['verb'] === 'Accept' && !$i[0]['approved']) {
|
||||
$valid = self::verify($i[0], $channel, $act);
|
||||
if ($valid) {
|
||||
self::storeApprove($arr, $channel, $arr['mid']);
|
||||
Run::Summon(['Notifier', 'activity', $i[0]['id']]);
|
||||
}
|
||||
}
|
||||
elseif ($i[0]['approved']) {
|
||||
$valid = self::verifyReject($i[0], $channel, $act);
|
||||
if ($valid) {
|
||||
self::storeApprove($arr, $channel, '');
|
||||
Run::Summon(['Notifier', 'activity', $i[0]['id']]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function storeApprove($arr, $channel, $value)
|
||||
{
|
||||
q("update item set approved = '%s' where mid = '%s' and uid = %d",
|
||||
dbesc($value),
|
||||
dbesc(is_array($arr['obj']) ? $arr['obj']['id'] : $arr['obj']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
$saved = q("select * from item where mid = '%s' and uid = %d",
|
||||
dbesc(is_array($arr['obj']) ? $arr['obj']['id'] : $arr['obj']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
if ($saved) {
|
||||
// we will need to remove the object and provide an author array
|
||||
// in order to re-generate the object JSON with the added approval
|
||||
xchan_query($saved);
|
||||
$saved[0]['obj'] = '';
|
||||
q("update item set obj = '%s' where mid = '%s' and uid = '%s'",
|
||||
dbesc(json_encode(Activity::encode_item($saved[0], true), JSON_UNESCAPED_SLASHES)),
|
||||
dbesc(is_array($arr['obj']) ? $arr['obj']['id'] : $arr['obj']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
}
|
||||
$r = q(
|
||||
"select * from item where mid = '%s' and uid = %d",
|
||||
dbesc(is_array($arr['obj']) ? $arr['obj']['id'] : $arr['obj']),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
|
||||
if ($r) {
|
||||
xchan_query($r);
|
||||
$sync_item = fetch_post_tags($r);
|
||||
Libsync::build_sync_packet($channel['channel_id'], ['item' => [encode_item($sync_item[0], true)]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function get_parent()
|
||||
{
|
||||
$results = q("select mid, replyto from item where mid = '%s'",
|
||||
dbesc($this->item['parent_mid'])
|
||||
);
|
||||
if ($results) {
|
||||
$item = array_shift($results);
|
||||
if($item['replyto']) {
|
||||
// Not a Twitter-like platform. Use the conversation parent
|
||||
return $item['mid'];
|
||||
}
|
||||
else {
|
||||
$results = q("select mid from item where mid = '%s'",
|
||||
dbesc($this->item['thr_parent'])
|
||||
);
|
||||
if ($results) {
|
||||
// Twitter-like platform. Use the immediate parent
|
||||
$item = array_shift($results);
|
||||
return $item['mid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
|
@ -1766,11 +1766,6 @@ class Libzot
|
|||
}
|
||||
|
||||
$objtype = $act->objprop('type','');
|
||||
if (in_array($arr['verb'], ['Accept', 'Reject']) && !in_array($objtype, ['Invite', 'Event'])) {
|
||||
if (CommentApproval::doVerify($arr, $channel, $act)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// perform pre-storage check to see if it's "likely" that this is a group or collection post
|
||||
|
||||
|
|
|
@ -1653,8 +1653,6 @@ class Item extends Controller
|
|||
dbesc('"', $datarray['mid'] . '"'),
|
||||
intval($channel['channel_id'])
|
||||
);
|
||||
unset($datarray['approved']);
|
||||
|
||||
|
||||
$x = item_store_update($datarray);
|
||||
|
||||
|
|
|
@ -458,7 +458,6 @@ class Ping extends Controller
|
|||
$r = q(
|
||||
"SELECT * FROM item
|
||||
WHERE uid = %d
|
||||
AND author_xchan != '%s'
|
||||
$seenstr
|
||||
$approvals
|
||||
$item_normal_moderate
|
||||
|
@ -466,8 +465,7 @@ class Ping extends Controller
|
|||
AND item_blocked = 4
|
||||
ORDER BY created DESC
|
||||
LIMIT 300",
|
||||
intval(local_channel()),
|
||||
dbesc($ob_hash)
|
||||
intval(local_channel())
|
||||
);
|
||||
if ($r) {
|
||||
xchan_query($r);
|
||||
|
|
|
@ -278,6 +278,12 @@ function visible_activity($item)
|
|||
return false;
|
||||
}
|
||||
|
||||
// we didn't receive the initial post over the network so hide the initial add activity from yourself.
|
||||
// It is just a duplicate of your top-level post.
|
||||
if ($item['verb'] === 'Add' && (int) $item['item_level'] === 1 && $item['item_wall']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is an experiment at group federation with microblog platforms.
|
||||
// We need the Announce or "boost" for group replies by non-connections to end up in the personal timeline
|
||||
// of those patforms. Hide them on our own platform because they make the conversation look like dung.
|
||||
|
|
Loading…
Reference in a new issue