Merge pull request #5845 from annando/ap-suggest

Preparation for suggestions under AP
This commit is contained in:
Hypolite Petovan 2018-10-07 08:58:21 -04:00 committed by GitHub
commit 772d735f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View file

@ -36,7 +36,7 @@ function fsuggest_post(App $a)
$hash = random_string(); $hash = random_string();
$note = escape_tags(trim($_POST['note'])); $note = escape_tags(trim(defaults($_POST, 'note', '')));
if ($new_contact) { if ($new_contact) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",

View file

@ -797,6 +797,36 @@ class Transmitter
return $data; return $data;
} }
/**
* Transmits a contact suggestion to a given inbox
*
* @param integer $uid User ID
* @param string $inbox Target inbox
* @param integer $suggestion_id Suggestion ID
*/
public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
{
$owner = User::getOwnerDataById($uid);
$profile = APContact::getByURL($owner['url']);
$suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]);
$data = ['@context' => 'https://www.w3.org/ns/activitystreams',
'id' => System::baseUrl() . '/activity/' . System::createGUID(),
'type' => 'Announce',
'actor' => $owner['url'],
'object' => $suggestion['url'],
'content' => $suggestion['note'],
'published' => DateTimeFormat::utc($suggestion['created'] . '+00:00', DateTimeFormat::ATOM),
'to' => [ActivityPub::PUBLIC_COLLECTION],
'cc' => []];
$signed = LDSignature::sign($data, $owner);
logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', LOGGER_DEBUG);
HTTPSignature::transmit($signed, $inbox, $uid);
}
/** /**
* Transmits a profile deletion to a given inbox * Transmits a profile deletion to a given inbox
* *

View file

@ -25,6 +25,7 @@ class APDelivery extends BaseObject
if ($cmd == Delivery::MAIL) { if ($cmd == Delivery::MAIL) {
} elseif ($cmd == Delivery::SUGGESTION) { } elseif ($cmd == Delivery::SUGGESTION) {
ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id);
} elseif ($cmd == Delivery::RELOCATION) { } elseif ($cmd == Delivery::RELOCATION) {
} elseif ($cmd == Delivery::REMOVAL) { } elseif ($cmd == Delivery::REMOVAL) {
ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox); ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox);