From: Michael Date: Sat, 22 Sep 2018 14:12:54 +0000 (+0000) Subject: Improve communication X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=214407bdc8e7ae126f1b44eaaa1f902e38fb1b9d;p=friendica.git Improve communication --- diff --git a/index.php b/index.php index 8b0bd47251..a62b7a2ea1 100644 --- 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'); diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 339312245e..95542ba966 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -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'])) { diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index f43c56a3ec..493bb5fac8 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -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; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 286bcd03ee..b457b78008 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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