]> git.mxchange.org Git - friendica.git/commitdiff
Processing of personal inbox enabled
authorMichael <heluecht@pirati.ca>
Sat, 15 Sep 2018 10:14:56 +0000 (10:14 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 15 Sep 2018 10:14:56 +0000 (10:14 +0000)
src/Module/Inbox.php
src/Protocol/ActivityPub.php

index dafc418f69ef7eb39f3a044cc19fba477b9bbdcc..d47419a415c4d08a74ca7a453f5be5124a4975cd 100644 (file)
@@ -7,6 +7,7 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
+use Friendica\Database\DBA;
 
 /**
  * ActivityPub Inbox
@@ -30,11 +31,21 @@ class Inbox extends BaseModule
                }
 
                $tempfile = tempnam(get_temppath(), $filename);
-               file_put_contents($tempfile, json_encode(['header' => $_SERVER, 'body' => $postdata]));
+               file_put_contents($tempfile, json_encode(['argv' => $a->argv, 'header' => $_SERVER, 'body' => $postdata]));
 
                logger('Incoming message stored under ' . $tempfile);
 
-               ActivityPub::processInbox($postdata, $_SERVER);
+               if (!empty($a->argv[1])) {
+                       $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
+                       if (!DBA::isResult($user)) {
+                               System::httpExit(404);
+                       }
+                       $uid = $user['uid'];
+               } else {
+                       $uid = 0;
+               }
+
+               ActivityPub::processInbox($postdata, $_SERVER, $uid);
 
                System::httpExit(202);
        }
index 6489ef812167e9518857b48e64dc0e584261e739..e80568487b48a0879ad2a83a5c69d5c4024c7b94 100644 (file)
@@ -32,6 +32,20 @@ use Friendica\Network\Probe;
  *
  * Digest: https://tools.ietf.org/html/rfc5843
  * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15
+ *
+ * To-do:
+ *
+ * Receiver:
+ * - Activities: Follow, Accept, Update
+ * - Object Types: Person, Tombstome
+ *
+ * Transmitter:
+ * - Activities: Like, Dislike, Follow, Accept, Update
+ * - Object Tyoes: Article, Announce, Person, Tombstone
+ *
+ * General:
+ * - Message distribution
+ * - Endpoints: Outbox, Object, Follower, Following
  */
 class ActivityPub
 {
@@ -187,7 +201,7 @@ class ActivityPub
                $owner = User::getOwnerDataById($uid);
 
                $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
-                       'id' => 'https://pirati.ca/' . strtolower($activity) . '/' . System::createGUID(),
+                       'id' => 'https://pirati.ca/activity/' . System::createGUID(),
                        'type' => $activity,
                        'actor' => $owner['url'],
                        'object' => $profile['url']];
@@ -486,9 +500,9 @@ class ActivityPub
                return $profile;
        }
 
-       public static function processInbox($body, $header)
+       public static function processInbox($body, $header, $uid)
        {
-               logger('Incoming message', LOGGER_DEBUG);
+               logger('Incoming message for user ' . $uid, LOGGER_DEBUG);
 
                if (!self::verifySignature($body, $header)) {
                        logger('Invalid signature, message will be discarded.', LOGGER_DEBUG);
@@ -502,7 +516,7 @@ class ActivityPub
                        return;
                }
 
-               self::processActivity($activity, $body);
+               self::processActivity($activity, $body, $uid);
        }
 
        public static function fetchOutbox($url)
@@ -528,7 +542,7 @@ class ActivityPub
                }
        }
 
-       function processActivity($activity, $body = '')
+       function processActivity($activity, $body = '', $uid = null)
        {
                if (empty($activity['type'])) {
                        logger('Empty type', LOGGER_DEBUG);
@@ -578,21 +592,25 @@ class ActivityPub
                unset($activity['location']);
                unset($activity['signature']);
 */
+               // Fetch all receivers from to, cc, bto and bcc
+               $receivers = self::getReceivers($activity);
 
-               if (!in_array($activity['type'], ['Like', 'Dislike'])) {
-                       $receivers = self::getReceivers($activity);
-                       if (empty($receivers)) {
-                               logger('No receivers found', LOGGER_DEBUG);
-                               return;
-                       }
+               // When it is a delivery to a personal inbox we add that user to the receivers
+               if (!empty($uid)) {
+                       $owner = User::getOwnerDataById($uid);
+                       $additional = [$owner['url'] => $uid];
+                       $receivers = array_merge($receivers, $additional);
+               }
 
+               logger('Receivers: ' . json_encode($receivers), LOGGER_DEBUG);
+
+               if (!in_array($activity['type'], ['Like', 'Dislike'])) {
                        $item = self::fetchObject($object_url, $activity['object']);
                        if (empty($item)) {
                                logger("Object data couldn't be processed", LOGGER_DEBUG);
                                return;
                        }
                } else {
-                       $receivers = [];
                        $item['object'] = $object_url;
                        $item['receiver'] = [];
                        $item['type'] = $activity['type'];