Merge pull request #7139 from annando/ap-mail
Sending direct messages via AP does work now - receiving is pending
This commit is contained in:
commit
969b7744c9
|
@ -44,8 +44,10 @@ class ActivityPub
|
||||||
['vcard' => 'http://www.w3.org/2006/vcard/ns#',
|
['vcard' => 'http://www.w3.org/2006/vcard/ns#',
|
||||||
'dfrn' => 'http://purl.org/macgirvin/dfrn/1.0/',
|
'dfrn' => 'http://purl.org/macgirvin/dfrn/1.0/',
|
||||||
'diaspora' => 'https://diasporafoundation.org/ns/',
|
'diaspora' => 'https://diasporafoundation.org/ns/',
|
||||||
|
'litepub' => 'http://litepub.social/ns#',
|
||||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||||
'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag']];
|
'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
|
||||||
|
'directMessage' => 'litepub:directMessage']];
|
||||||
const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application'];
|
const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application'];
|
||||||
/**
|
/**
|
||||||
* Checks if the web request is done for the AP protocol
|
* Checks if the web request is done for the AP protocol
|
||||||
|
|
|
@ -631,6 +631,100 @@ class Transmitter
|
||||||
return $inboxes;
|
return $inboxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an array in the structure of the item table for a given mail id
|
||||||
|
*
|
||||||
|
* @param integer $mail_id
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function ItemArrayFromMail($mail_id)
|
||||||
|
{
|
||||||
|
$mail = DBA::selectFirst('mail', [], ['id' => $mail_id]);
|
||||||
|
|
||||||
|
$reply = DBA::selectFirst('mail', ['uri'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
|
||||||
|
|
||||||
|
$mail['author-link'] = $mail['owner-link'] = $mail['from-url'];
|
||||||
|
$mail['allow_cid'] = '<'.$mail['contact-id'].'>';
|
||||||
|
$mail['allow_gid'] = '';
|
||||||
|
$mail['deny_cid'] = '';
|
||||||
|
$mail['deny_gid'] = '';
|
||||||
|
$mail['private'] = true;
|
||||||
|
$mail['deleted'] = false;
|
||||||
|
$mail['edited'] = $mail['created'];
|
||||||
|
$mail['plink'] = $mail['uri'];
|
||||||
|
$mail['thr-parent'] = $reply['uri'];
|
||||||
|
$mail['gravity'] = ($mail['reply'] ? GRAVITY_COMMENT: GRAVITY_PARENT);
|
||||||
|
|
||||||
|
$mail['event-type'] = '';
|
||||||
|
$mail['attach'] = '';
|
||||||
|
|
||||||
|
$mail['parent'] = 0;
|
||||||
|
|
||||||
|
return $mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an activity array for a given mail id
|
||||||
|
*
|
||||||
|
* @param integer $mail_id
|
||||||
|
* @param boolean $object_mode Is the activity item is used inside another object?
|
||||||
|
*
|
||||||
|
* @return array of activity
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function createActivityFromMail($mail_id, $object_mode = false)
|
||||||
|
{
|
||||||
|
$mail = self::ItemArrayFromMail($mail_id);
|
||||||
|
$object = self::createNote($mail);
|
||||||
|
|
||||||
|
$object['to'] = $object['cc'];
|
||||||
|
unset($object['cc']);
|
||||||
|
|
||||||
|
$object['tag'] = [['type' => 'Mention', 'href' => $object['to'][0], 'name' => 'test']];
|
||||||
|
|
||||||
|
if (!$object_mode) {
|
||||||
|
$data = ['@context' => ActivityPub::CONTEXT];
|
||||||
|
} else {
|
||||||
|
$data = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['id'] = $mail['uri'] . '#Create';
|
||||||
|
$data['type'] = 'Create';
|
||||||
|
$data['actor'] = $mail['author-link'];
|
||||||
|
$data['published'] = DateTimeFormat::utc($mail['created'] . '+00:00', DateTimeFormat::ATOM);
|
||||||
|
$data['instrument'] = self::getService();
|
||||||
|
$data = array_merge($data, self::createPermissionBlockForItem($mail, true));
|
||||||
|
|
||||||
|
if (empty($data['to']) && !empty($data['cc'])) {
|
||||||
|
$data['to'] = $data['cc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($data['to']) && !empty($data['bcc'])) {
|
||||||
|
$data['to'] = $data['bcc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($data['cc']);
|
||||||
|
unset($data['bcc']);
|
||||||
|
|
||||||
|
$object['to'] = $data['to'];
|
||||||
|
unset($object['cc']);
|
||||||
|
unset($object['bcc']);
|
||||||
|
|
||||||
|
$data['directMessage'] = true;
|
||||||
|
|
||||||
|
$data['object'] = $object;
|
||||||
|
|
||||||
|
$owner = User::getOwnerDataById($mail['uid']);
|
||||||
|
|
||||||
|
if (!$object_mode && !empty($owner)) {
|
||||||
|
return LDSignature::sign($data, $owner);
|
||||||
|
} else {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the activity type of a given item
|
* Returns the activity type of a given item
|
||||||
*
|
*
|
||||||
|
|
|
@ -96,7 +96,8 @@ class JsonLD
|
||||||
'diaspora' => (object)['@id' => 'https://diasporafoundation.org/ns/', '@type' => '@id'],
|
'diaspora' => (object)['@id' => 'https://diasporafoundation.org/ns/', '@type' => '@id'],
|
||||||
'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'],
|
'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'],
|
||||||
'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'],
|
'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'],
|
||||||
'toot' => (object)['@id' => 'http://joinmastodon.org/ns#', '@type' => '@id']];
|
'toot' => (object)['@id' => 'http://joinmastodon.org/ns#', '@type' => '@id'],
|
||||||
|
'litepub' => (object)['@id' => 'http://litepub.social/ns#', '@type' => '@id']];
|
||||||
|
|
||||||
// Preparation for adding possibly missing content to the context
|
// Preparation for adding possibly missing content to the context
|
||||||
if (!empty($json['@context']) && is_string($json['@context'])) {
|
if (!empty($json['@context']) && is_string($json['@context'])) {
|
||||||
|
|
|
@ -30,6 +30,10 @@ class APDelivery extends BaseObject
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
||||||
if ($cmd == Delivery::MAIL) {
|
if ($cmd == Delivery::MAIL) {
|
||||||
|
$data = ActivityPub\Transmitter::createActivityFromMail($target_id);
|
||||||
|
if (!empty($data)) {
|
||||||
|
$success = HTTPSignature::transmit($data, $inbox, $uid);
|
||||||
|
}
|
||||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||||
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
|
$success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $target_id);
|
||||||
} elseif ($cmd == Delivery::RELOCATION) {
|
} elseif ($cmd == Delivery::RELOCATION) {
|
||||||
|
|
|
@ -76,6 +76,14 @@ class Notifier
|
||||||
}
|
}
|
||||||
$uid = $message['uid'];
|
$uid = $message['uid'];
|
||||||
$recipients[] = $message['contact-id'];
|
$recipients[] = $message['contact-id'];
|
||||||
|
|
||||||
|
$mail = ActivityPub\Transmitter::ItemArrayFromMail($target_id);
|
||||||
|
$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($mail, §uid, true);
|
||||||
|
foreach ($inboxes as $inbox) {
|
||||||
|
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_id, 'inbox' => $inbox]);
|
||||||
|
Worker::add(['priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true],
|
||||||
|
'APDelivery', $cmd, $target_id, $inbox, $uid);
|
||||||
|
}
|
||||||
} elseif ($cmd == Delivery::SUGGESTION) {
|
} elseif ($cmd == Delivery::SUGGESTION) {
|
||||||
$suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $target_id]);
|
$suggest = DBA::selectFirst('fsuggest', ['uid', 'cid'], ['id' => $target_id]);
|
||||||
if (!DBA::isResult($suggest)) {
|
if (!DBA::isResult($suggest)) {
|
||||||
|
@ -593,7 +601,7 @@ class Notifier
|
||||||
|
|
||||||
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
|
$inboxes = ActivityPub\Transmitter::fetchTargetInboxesforUser(0);
|
||||||
foreach ($inboxes as $inbox) {
|
foreach ($inboxes as $inbox) {
|
||||||
Logger::log('Account removal for user ' . $self_user_id . ' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
|
Logger::info('Account removal via ActivityPub', ['uid' => $self_user_id, 'inbox' => $inbox]);
|
||||||
Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true],
|
Worker::add(['priority' => PRIORITY_NEGLIGIBLE, 'created' => $created, 'dont_fork' => true],
|
||||||
'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id);
|
'APDelivery', Delivery::REMOVAL, '', $inbox, $self_user_id);
|
||||||
}
|
}
|
||||||
|
@ -642,7 +650,7 @@ class Notifier
|
||||||
ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
|
ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
|
||||||
|
|
||||||
foreach ($inboxes as $inbox) {
|
foreach ($inboxes as $inbox) {
|
||||||
Logger::log('Deliver ' . $target_item['id'] .' to ' . $inbox .' via ActivityPub', Logger::DEBUG);
|
Logger::info('Delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'inbox' => $inbox]);
|
||||||
|
|
||||||
Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true],
|
||||||
'APDelivery', $cmd, $target_item['id'], $inbox, $uid);
|
'APDelivery', $cmd, $target_item['id'], $inbox, $uid);
|
||||||
|
|
Loading…
Reference in a new issue