]> git.mxchange.org Git - friendica.git/commitdiff
Improve communication
authorMichael <heluecht@pirati.ca>
Sat, 22 Sep 2018 14:12:54 +0000 (14:12 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 22 Sep 2018 14:12:54 +0000 (14:12 +0000)
index.php
src/Protocol/ActivityPub.php
src/Worker/APDelivery.php
src/Worker/Notifier.php

index 8b0bd472513fd9c5a1ca9bbd457a60ce963682d3..a62b7a2ea1ff2e5cc52390857ee1294408ebf541 100644 (file)
--- a/index.php
+++ b/index.php
@@ -215,6 +215,10 @@ if (strlen($a->module)) {
         * First see if we have an addon which is masquerading as a module.
         */
 
+       if ($a->module == 'object') {
+               $a->module = 'display';
+       }
+
        // Compatibility with the Android Diaspora client
        if ($a->module == 'stream') {
                goaway('network?f=&order=post');
index 339312245ef988ae4a7cfc01b873350b1c8d7f77..95542ba966200b9fb14aa261f11013814e0468cc 100644 (file)
@@ -155,7 +155,9 @@ class ActivityPub
                                if ($receiver == $profile['followers'] && !empty($item_profile['followers'])) {
                                        $receiver = $item_profile['followers'];
                                }
-                               $permissions[$element][] = $receiver;
+                               if ($receiver != $item['owner-link']) {
+                                       $permissions[$element][] = $receiver;
+                               }
                        }
                }
                return $permissions;
@@ -171,7 +173,7 @@ class ActivityPub
 
                $terms = Term::tagArrayFromItemId($item['id']);
 
-               $contacts = [];
+               $contacts[$item['author-link']] = $item['author-link'];
 
                if (!$item['private']) {
                        $data['to'][] = self::PUBLIC;
@@ -213,11 +215,6 @@ class ActivityPub
                                        $contacts[$contact['url']] = $contact['url'];
                                }
                        }
-
-                       if (empty($data['to'])) {
-                               $data['to'] = $data['cc'];
-                               $data['cc'] = [];
-                       }
                }
 
                $parents = Item::select(['author-link', 'owner-link'], ['parent' => $item['parent']]);
@@ -236,6 +233,11 @@ class ActivityPub
                }
                DBA::close($parents);
 
+               if (empty($data['to'])) {
+                       $data['to'] = $data['cc'];
+                       $data['cc'] = [];
+               }
+
                return $data;
        }
 
@@ -318,9 +320,12 @@ class ActivityPub
                        $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
                }
 
+               $data['context_id'] = $item['parent'];
+               $data['context'] = self::createConversationURLFromItem($item);
+
                $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
 
-               $data['object'] = self::createNote($item);
+               $data['object'] = self::createObjectTypeFromItem($item);
 
                $owner = User::getOwnerDataById($item['uid']);
 
@@ -341,7 +346,7 @@ class ActivityPub
                        'conversation' => 'ostatus:conversation',
                        'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri']]];
 
-               $data = array_merge($data, self::createNote($item));
+               $data = array_merge($data, self::createObjectTypeFromItem($item));
 
 
                return $data;
@@ -364,15 +369,31 @@ class ActivityPub
                                $tags[] = ['type' => 'Mention', 'href' => $term['url'], 'name' => $mention];
                        }
                }
-
                return $tags;
        }
 
-       public static function createNote($item)
+       private static function createConversationURLFromItem($item)
        {
+               $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]);
+               if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
+                       $conversation_uri = $conversation['conversation-uri'];
+               } else {
+                       $conversation_uri = $item['parent-uri'];
+               }
+               return $conversation_uri;
+       }
+
+       private static function createObjectTypeFromItem($item)
+       {
+               if (!empty($item['title'])) {
+                       $type = 'Article';
+               } else {
+                       $type = 'Note';
+               }
+
                $data = [];
                $data['id'] = $item['uri'];
-               $data['type'] = 'Note';
+               $data['type'] = $type;
                $data['summary'] = null; // Ignore by now
 
                if ($item['uri'] != $item['thr-parent']) {
@@ -387,19 +408,12 @@ class ActivityPub
                        $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
                }
 
-               $data['url'] = $item['uri'];
+               $data['url'] = $item['plink'];
                $data['attributedTo'] = $item['author-link'];
                $data['actor'] = $item['author-link'];
                $data['sensitive'] = false; // - Query NSFW
-
-               $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]);
-               if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
-                       $conversation_uri = $conversation['conversation-uri'];
-               } else {
-                       $conversation_uri = $item['parent-uri'];
-               }
-
-               $data['conversation'] = $conversation_uri;
+               $data['context_id'] = $item['parent'];
+               $data['conversation'] = $data['context'] = self::createConversationURLFromItem($item);
 
                if (!empty($item['title'])) {
                        $data['name'] = BBCode::convert($item['title'], false, 7);
@@ -704,14 +718,17 @@ class ActivityPub
 
                if (LDSignature::isSigned($activity)) {
                        $ld_signer = LDSignature::getSigner($activity);
-                       if (!empty($ld_signer)) {
+                       if (!empty($ld_signer && ($actor == $http_signer))) {
+                               logger('The HTTP and the JSON-LD signature belong to ' . $ld_signer, LOGGER_DEBUG);
+                               $trust_source = true;
+                       } elseif (!empty($ld_signer)) {
                                logger('JSON-LD signature is signed by ' . $ld_signer, LOGGER_DEBUG);
                                $trust_source = true;
                        } elseif ($actor == $http_signer) {
                                logger('Bad JSON-LD signature, but HTTP signer fits the actor.', LOGGER_DEBUG);
                                $trust_source = true;
                        } else {
-                               logger('Invalid JSON-LD signature.', LOGGER_DEBUG);
+                               logger('Invalid JSON-LD signature and the HTTP signer is different.', LOGGER_DEBUG);
                                $trust_source = false;
                        }
                } elseif ($actor == $http_signer) {
@@ -1005,7 +1022,7 @@ class ActivityPub
                                return false;
                        }
                        logger('Using already stored item for url ' . $object_url, LOGGER_DEBUG);
-                       $data = self::createNote($item);
+                       $data = self::createObjectTypeFromItem($item);
                }
 
                if (empty($data['type'])) {
index f43c56a3ecb6d95eff9507ceb2bbf4f9dc80d464..493bb5fac83a993256e77d836808eb45daf0ea12 100644 (file)
@@ -11,7 +11,7 @@ use Friendica\Util\HTTPSignature;
 
 class APDelivery extends BaseObject
 {
-       public static function execute($cmd, $item_id, $inbox)
+       public static function execute($cmd, $item_id, $inbox, $uid)
        {
                logger('Invoked: ' . $cmd . ': ' . $item_id . ' to ' . $inbox, LOGGER_DEBUG);
 
@@ -19,9 +19,8 @@ class APDelivery extends BaseObject
                } elseif ($cmd == Delivery::SUGGESTION) {
                } elseif ($cmd == Delivery::RELOCATION) {
                } else {
-                       $item = Item::selectFirst(['uid'], ['id' => $item_id]);
                        $data = ActivityPub::createActivityFromItem($item_id);
-                       HTTPSignature::transmit($data, $inbox, $item['uid']);
+                       HTTPSignature::transmit($data, $inbox, $uid);
                }
 
                return;
index 286bcd03ee9be2e6afea22287fea902e11fe059c..b457b7800851177c4254f505e4ef515c5c290992 100644 (file)
@@ -429,7 +429,7 @@ class Notifier
                        logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
 
                        Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                       'APDelivery', $cmd, $item_id, $inbox);
+                                       'APDelivery', $cmd, $item_id, $inbox, $uid);
                }
 
                // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts