From aa3532cd3b5b95aaad82683c39ccab31f4d2533f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 16:02:51 -0500 Subject: [PATCH 1/5] Fix wrong class constant in Model\APContact --- src/Model/APContact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index c606e3107e..3d196c46de 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -201,7 +201,7 @@ class APContact extends BaseObject if (is_int($contact_type)) { $contact_fields['contact-type'] = $contact_type; - if ($contact_fields['contact-type'] != Contact::ACCOUNT_TYPE_COMMUNITY) { + if ($contact_fields['contact-type'] != User::ACCOUNT_TYPE_COMMUNITY) { // Resetting the 'forum' and 'prv' field when it isn't a forum $contact_fields['forum'] = false; $contact_fields['prv'] = false; From 604262a70e4d56e91db3a43049f2c0196cf9fdee Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 21 Jan 2019 23:15:03 -0500 Subject: [PATCH 2/5] Extract title determination from OStatus::entryHeader logic --- src/Protocol/OStatus.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 551253e6a0..acb49efcc7 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -1693,7 +1693,7 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); $condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]]; @@ -1758,7 +1758,7 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); $verb = NAMESPACE_ACTIVITY_SCHEMA."favorite"; self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false); @@ -1879,7 +1879,7 @@ class OStatus $item["body"] = sprintf($message, $owner["nick"], $contact["nick"]); - self::entryHeader($doc, $entry, $owner, $item, $toplevel); + $entry = self::entryHeader($doc, $owner, $item, $toplevel); self::entryContent($doc, $entry, $item, $owner, $title); @@ -1910,7 +1910,17 @@ class OStatus Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } - $title = self::entryHeader($doc, $entry, $owner, $item, $toplevel); + if (!$toplevel) { + if (!empty($item['title'])) { + $title = BBCode::convert($item['title'], false, 7); + } else { + $title = sprintf("New note by %s", $owner["nick"]); + } + } else { + $title = sprintf("New comment by %s", $owner["nick"]); + } + + $entry = self::entryHeader($doc, $owner, $item, $toplevel); XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); @@ -1925,25 +1935,18 @@ class OStatus * @brief Adds a header element to the XML document * * @param DOMDocument $doc XML document - * @param object $entry The entry element where the elements are added * @param array $owner Contact data of the poster * @param array $item * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * - * @return string The title for the element + * @return \DOMElement The entry element where the elements are added * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function entryHeader(DOMDocument $doc, &$entry, array $owner, array $item, $toplevel) + private static function entryHeader(DOMDocument $doc, array $owner, array $item, $toplevel) { - /// @todo Check if this title stuff is really needed (I guess not) if (!$toplevel) { $entry = $doc->createElement("entry"); - if (!empty($item['title'])) { - $title = BBCode::convert($item['title'], false, 7); - } else { - $title = sprintf("New note by %s", $owner["nick"]); - } if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) { $contact = self::contactEntry($item['author-link'], $owner); @@ -1964,10 +1967,9 @@ class OStatus $author = self::addAuthor($doc, $owner); $entry->appendChild($author); - - $title = sprintf("New comment by %s", $owner["nick"]); } - return $title; + + return $entry; } /** From 282bc019943b22b1004c0d37d976116c43e5763b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 01:30:03 -0500 Subject: [PATCH 3/5] Fix using wrong uid for APDelivery in Worker\Notifier --- src/Worker/Notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index d991e6a4e9..02e69064c5 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -587,7 +587,7 @@ class Notifier Logger::log('Deliver ' . $target_item['id'] .' to ' . $inbox .' via ActivityPub', Logger::DEBUG); Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true], - 'APDelivery', $cmd, $target_item['id'], $inbox, $target_item['contact-uid']); + 'APDelivery', $cmd, $target_item['id'], $inbox, $target_item['contact-uid'] ?: $target_item['uid']); } return count($inboxes); From 5d4bafb116eee6e1791a189803c85de8a72f86de Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 08:31:39 -0500 Subject: [PATCH 4/5] Fix two additional uses of uid in Worker\Notifier --- src/Worker/Notifier.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 02e69064c5..9e5430e8fa 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -562,8 +562,10 @@ class Notifier { $inboxes = []; + $uid = $target_item['contact-uid'] ?: $target_item['uid']; + if ($target_item['origin']) { - $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $target_item['contact-uid']); + $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid); Logger::log('Origin item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG); } elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) { Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', Logger::DEBUG); @@ -571,7 +573,7 @@ class Notifier } elseif ($parent['origin']) { // Remote items are transmitted via the personal inboxes. // Doing so ensures that the dedicated receiver will get the message. - $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $target_item['contact-uid'], true, $target_item['id']); + $inboxes = ActivityPub\Transmitter::fetchTargetInboxes($parent, $uid, true, $target_item['id']); Logger::log('Remote item ' . $target_item['id'] . ' with URL ' . $target_item['uri'] . ' will be distributed.', Logger::DEBUG); } @@ -587,7 +589,7 @@ class Notifier Logger::log('Deliver ' . $target_item['id'] .' to ' . $inbox .' via ActivityPub', Logger::DEBUG); Worker::add(['priority' => $priority, 'created' => $created, 'dont_fork' => true], - 'APDelivery', $cmd, $target_item['id'], $inbox, $target_item['contact-uid'] ?: $target_item['uid']); + 'APDelivery', $cmd, $target_item['id'], $inbox, $uid); } return count($inboxes); From 0cc1a07cfa98d5e6fdd273148aae2c0de76c3407 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 22 Jan 2019 08:53:53 -0500 Subject: [PATCH 5/5] Fix default value of contact parameter of OStatus::import in mod/salmon --- mod/salmon.php | 2 +- src/Protocol/OStatus.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/salmon.php b/mod/salmon.php index 536a4516ce..84d2942d53 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -184,7 +184,7 @@ function salmon_post(App $a, $xml = '') { // Placeholder for hub discovery. $hub = ''; - $contact_rec = ((DBA::isResult($r)) ? $r[0] : null); + $contact_rec = ((DBA::isResult($r)) ? $r[0] : []); OStatus::import($data, $importer, $contact_rec, $hub); diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index acb49efcc7..b1cc4f4020 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -74,7 +74,7 @@ class OStatus $author["contact-id"] = $contact["id"]; - $contact = null; + $contact = []; /* This here would be better, but we would get problems with contacts from the statusnet addon @@ -231,7 +231,7 @@ class OStatus GContact::link($gcid, $contact["uid"], $contact["id"]); } elseif ($contact["network"] != Protocol::DFRN) { - $contact = null; + $contact = []; } return $author;