From 192c6c8d4fb1d99981b46acc9d99bb212b754466 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Oct 2018 18:42:26 +0000 Subject: [PATCH 1/2] Preparation for suggestions under AP --- src/Protocol/ActivityPub/Transmitter.php | 30 ++++++++++++++++++++++++ src/Worker/APDelivery.php | 1 + 2 files changed, 31 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 9fad787b1..cb3e1f30a 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -797,6 +797,36 @@ class Transmitter 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 * diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 039cdfbb3..7b1ad7605 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -25,6 +25,7 @@ class APDelivery extends BaseObject if ($cmd == Delivery::MAIL) { } elseif ($cmd == Delivery::SUGGESTION) { + ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id); } elseif ($cmd == Delivery::RELOCATION) { } elseif ($cmd == Delivery::REMOVAL) { ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox); From f8b74033a4f990e421814ea5bf8b443104e61feb Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Oct 2018 18:44:42 +0000 Subject: [PATCH 2/2] Avoid a notice --- mod/fsuggest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 8fc0f07de..35710bb33 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -36,7 +36,7 @@ function fsuggest_post(App $a) $hash = random_string(); - $note = escape_tags(trim($_POST['note'])); + $note = escape_tags(trim(defaults($_POST, 'note', ''))); if ($new_contact) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",