Let's respect mentions

This commit is contained in:
Diogo Cordeiro 2018-08-05 22:29:47 +01:00
parent c10585da3f
commit 47b1f2219c
2 changed files with 14 additions and 21 deletions

View File

@ -124,7 +124,6 @@ class Activitypub_notice extends Managed_DataObject
$id = $object['id']; // int32 $id = $object['id']; // int32
$url = $object['url']; // string $url = $object['url']; // string
$content = $object['content']; // string $content = $object['content']; // string
$cc = $object['cc']; // array|string
// possible keys: ['inReplyTo', 'latitude', 'longitude', 'attachment'] // possible keys: ['inReplyTo', 'latitude', 'longitude', 'attachment']
$settings = []; $settings = [];
@ -201,34 +200,28 @@ class Activitypub_notice extends Managed_DataObject
$inReplyTo = null; $inReplyTo = null;
} }
// Mentions
$mentions = [];
if (isset ($object['tag']) && is_array($object['tag'])) {
foreach ($object['tag'] as $tag) {
if ($tag['type'] == 'Mention') {
$mentions[] = $tag['href'];
}
}
}
$mentions_profiles = [];
$discovery = new Activitypub_explorer; $discovery = new Activitypub_explorer;
foreach ($mentions as $mention) {
// Generate Cc objects
$cc_profiles = [];
if (is_array($cc)) {
// Remove duplicates from Cc actors set
array_unique($cc);
foreach ($cc as $cc_url) {
try { try {
$cc_profiles = array_merge($cc_profiles, $discovery->lookup($cc_url)); $mentions_profiles[] = array_merge($mentions_profiles, $discovery->lookup($mention));
} catch (Exception $e) { } catch (Exception $e) {
// Invalid actor found, just let it go. // TODO: Fallback to OStatus // Invalid actor found, just let it go. // TODO: Fallback to OStatus
} }
} }
} elseif (empty($cc) || in_array($cc, ACTIVITYPUB_PUBLIC_TO)) {
// No need to do anything else at this point, let's just break out the if
} else {
try {
$cc_profiles = $discovery->lookup($cc);
} catch (Exception $e) {
// Invalid actor found, just let it go. // TODO: Fallback to OStatus
}
}
unset($discovery); unset($discovery);
foreach ($cc_profiles as $cp) { foreach ($mentions_profiles as $mp) {
$act->context->attention[ActivityPubPlugin::actor_uri($cp)] = 'http://activitystrea.ms/schema/1.0/person'; $act->context->attention[ActivityPubPlugin::actor_uri($mp)] = 'http://activitystrea.ms/schema/1.0/person';
} }
// Add location if that is set // Add location if that is set

View File

@ -64,6 +64,7 @@ class Activitypub_postman
{ {
$this->actor = $from; $this->actor = $from;
$this->to = $to; $this->to = $to;
$this->to[]= common_local_url('apActorFollowers', ['id' => $from->getID()]);
$this->actor_uri = ActivityPubPlugin::actor_uri($this->actor); $this->actor_uri = ActivityPubPlugin::actor_uri($this->actor);
$actor_private_key = new Activitypub_rsa(); $actor_private_key = new Activitypub_rsa();
@ -75,7 +76,6 @@ class Activitypub_postman
'headers' => ['(request-target)', 'date', 'content-type', 'accept', 'user-agent'], 'headers' => ['(request-target)', 'date', 'content-type', 'accept', 'user-agent'],
]); ]);
$this->to = $to;
$this->headers = [ $this->headers = [
'content-type' => 'application/activity+json', 'content-type' => 'application/activity+json',
'accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', 'accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',