]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #5845 from annando/ap-suggest
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 7 Oct 2018 12:58:21 +0000 (08:58 -0400)
committerGitHub <noreply@github.com>
Sun, 7 Oct 2018 12:58:21 +0000 (08:58 -0400)
Preparation for suggestions under AP

mod/fsuggest.php
src/Protocol/ActivityPub/Transmitter.php
src/Worker/APDelivery.php

index 8fc0f07deef7b8b6becee9cd7f2d2a849c6cfbf7..35710bb338d0139717ed133228d3bcaf3bd53222 100644 (file)
@@ -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",
index 9fad787b1b19586daa97d29f97c157a00745b80d..cb3e1f30af046b6ed5b8ce9d6e1f6e7a21829a94 100644 (file)
@@ -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
         *
index 039cdfbb3b6acec830bd6270a378b5825115eb88..7b1ad760557022e3144c5d03382cabfe53ed6ada 100644 (file)
@@ -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);