A small step for AP, a jump to AP+OS
This commit is contained in:
parent
ca8867c1c0
commit
0475954741
@ -765,27 +765,35 @@ class ActivityPubPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
assert($notice->id > 0); // Ignore if not a valid notice
|
assert($notice->id > 0); // Ignore if not a valid notice
|
||||||
|
|
||||||
$profile = Profile::getKV($notice->profile_id);
|
$profile = $notice->getProfile();
|
||||||
|
|
||||||
if (!$profile->isLocal()) {
|
if (!$profile->isLocal()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = [];
|
// Ignore for activity/non-post-verb notices
|
||||||
try {
|
if (method_exists('ActivityUtils', 'compareVerbs')) {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getProfile());
|
$is_post_verb = ActivityUtils::compareVerbs(
|
||||||
} catch (Exception $e) {
|
$notice->verb,
|
||||||
// Local user can be ignored
|
[ActivityVerb::POST]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$is_post_verb = ($notice->verb == ActivityVerb::POST ? true : false);
|
||||||
}
|
}
|
||||||
foreach ($notice->getAttentionProfiles() as $to_profile) {
|
if ($notice->source == 'activity' || !$is_post_verb) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$other = [];
|
||||||
|
foreach ($notice->getAttentionProfiles() as $mention) {
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
$other[] = Activitypub_profile::from_profile($mention);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is Announce
|
// Is an Announce?
|
||||||
if ($notice->isRepeat()) {
|
if ($notice->isRepeat()) {
|
||||||
$repeated_notice = Notice::getKV('id', $notice->repeat_of);
|
$repeated_notice = Notice::getKV('id', $notice->repeat_of);
|
||||||
if ($repeated_notice instanceof Notice) {
|
if ($repeated_notice instanceof Notice) {
|
||||||
@ -803,20 +811,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore for activity/non-post-verb notices
|
// Is a reply?
|
||||||
if (method_exists('ActivityUtils', 'compareVerbs')) {
|
|
||||||
$is_post_verb = ActivityUtils::compareVerbs(
|
|
||||||
$notice->verb,
|
|
||||||
[ActivityVerb::POST]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$is_post_verb = ($notice->verb == ActivityVerb::POST ? true : false);
|
|
||||||
}
|
|
||||||
if ($notice->source == 'activity' || !$is_post_verb) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create
|
|
||||||
if ($notice->reply_to) {
|
if ($notice->reply_to) {
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($notice->getParent()->getProfile());
|
$other[] = Activitypub_profile::from_profile($notice->getParent()->getProfile());
|
||||||
@ -824,10 +819,9 @@ class ActivityPubPlugin extends Plugin
|
|||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$mentions = $notice->getParent()->getAttentionProfiles();
|
foreach ($notice->getParent()->getAttentionProfiles() as $mention) {
|
||||||
foreach ($mentions as $to_profile) {
|
|
||||||
try {
|
try {
|
||||||
$other[] = Activitypub_profile::from_profile($to_profile);
|
$other[] = Activitypub_profile::from_profile($mention);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
@ -839,10 +833,14 @@ class ActivityPubPlugin extends Plugin
|
|||||||
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
|
common_log(LOG_ERR, "Parent notice's author not found: ".$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$postman = new Activitypub_postman($profile, $other);
|
|
||||||
|
|
||||||
// That was it
|
// That was it
|
||||||
$postman->create_note($notice);
|
try {
|
||||||
|
$postman = new Activitypub_postman($profile, $other);
|
||||||
|
$postman->create_note($notice);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Let another plugin handle this instead.
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +60,13 @@ class Activitypub_postman
|
|||||||
* @param Profile $from Profile of sender
|
* @param Profile $from Profile of sender
|
||||||
* @param Array of Activitypub_profile $to destinataries
|
* @param Array of Activitypub_profile $to destinataries
|
||||||
*/
|
*/
|
||||||
public function __construct($from, $to = [])
|
public function __construct($from, $to)
|
||||||
{
|
{
|
||||||
$this->actor = $from;
|
$this->actor = $from;
|
||||||
|
|
||||||
|
if (empty ($to)) {
|
||||||
|
throw new Exception ('You can not summon up a postman without recipients!');
|
||||||
|
}
|
||||||
$discovery = new Activitypub_explorer();
|
$discovery = new Activitypub_explorer();
|
||||||
$this->to = $to;
|
$this->to = $to;
|
||||||
$followers = apActorFollowersAction::generate_followers($this->actor, 0, null);
|
$followers = apActorFollowersAction::generate_followers($this->actor, 0, null);
|
||||||
@ -245,9 +248,6 @@ class Activitypub_postman
|
|||||||
$this->actor_uri,
|
$this->actor_uri,
|
||||||
Activitypub_notice::notice_to_array($notice)
|
Activitypub_notice::notice_to_array($notice)
|
||||||
);
|
);
|
||||||
if (isset($notice->reply_to)) {
|
|
||||||
$data["object"]["reply_to"] = $notice->getParent()->getUrl();
|
|
||||||
}
|
|
||||||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||||
|
|
||||||
foreach ($this->to_inbox() as $inbox) {
|
foreach ($this->to_inbox() as $inbox) {
|
||||||
|
Reference in New Issue
Block a user