From c73130aa6b83951b9e6ecc05c66d25292b5b9091 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 5 Aug 2021 08:58:50 +0200 Subject: [PATCH 1/5] Create the Diaspora signature for the correct user --- include/conversation.php | 2 +- src/Model/Item.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 6a6eff28dc..93ec728baa 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -717,7 +717,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid) $max_comments = DI::config()->get('system', 'max_display_comments', 1000); } - $params = ['order' => ['uri-id' => true]]; + $params = ['order' => ['uri-id' => true, 'uid' => true]]; $activities = []; $uriids = []; diff --git a/src/Model/Item.php b/src/Model/Item.php index a8105f78c3..0c48c95291 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1061,7 +1061,13 @@ class Item // Create Diaspora signature if ($item['origin'] && empty($item['diaspora_signed_text']) && ($item['gravity'] != GRAVITY_PARENT)) { - $signed = Diaspora::createCommentSignature($uid, $item); + if ($uid == 0) { + $sender_contact = Contact::getById($item['contact-id'], ['uid']); + $sender_uid = $sender_contact['uid']; + } else { + $sender_uid = $uid; + } + $signed = Diaspora::createCommentSignature($sender_uid, $item); if (!empty($signed)) { $item['diaspora_signed_text'] = json_encode($signed); } From a26a2a0228e13acc0d227f94b352028a2c6b24a7 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Aug 2021 08:30:44 +0000 Subject: [PATCH 2/5] Make the system owner ready for Diaspora --- src/Model/User.php | 9 +++++++-- src/Module/Xrd.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Model/User.php b/src/Model/User.php index 94e41387ba..55bbb8b841 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -157,8 +157,8 @@ class User $system['net-publish'] = false; // Ensure that the user contains data - $user = DBA::selectFirst('user', ['prvkey'], ['uid' => 0]); - if (empty($user['prvkey'])) { + $user = DBA::selectFirst('user', ['prvkey', 'guid'], ['uid' => 0]); + if (empty($user['prvkey']) || empty($user['guid'])) { $fields = [ 'username' => $system['name'], 'nickname' => $system['nick'], @@ -167,12 +167,17 @@ class User 'prvkey' => $system['prvkey'], 'spubkey' => $system['spubkey'], 'sprvkey' => $system['sprvkey'], + 'guid' => System::createUUID(), 'verified' => true, 'page-flags' => User::PAGE_FLAGS_SOAPBOX, 'account-type' => User::ACCOUNT_TYPE_RELAY, ]; DBA::update('user', $fields, ['uid' => 0]); + + $system['guid'] = $fields['guid']; + } else { + $system['guid'] = $user['guid']; } return $system; diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 7e380946ff..d2813cc270 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -130,6 +130,25 @@ class Xrd extends BaseModule 'rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => DI::baseUrl()->get() . '/follow?url={uri}', ], + [ + 'rel' => ActivityNamespace::FEED, + 'type' => 'application/atom+xml', + 'href' => $owner['poll'] ?? DI::baseUrl()->get(), + ], + [ + 'rel' => 'salmon', + 'href' => DI::baseUrl()->get() . '/salmon/' . $owner['nickname'], + ], + [ + 'rel' => 'http://microformats.org/profile/hcard', + 'type' => 'text/html', + 'href' => DI::baseUrl()->get() . '/hcard/' . $owner['nickname'], + ], + [ + 'rel' => 'http://joindiaspora.com/seed_location', + 'type' => 'text/html', + 'href' => DI::baseUrl()->get(), + ], ] ]; header('Access-Control-Allow-Origin: *'); From 835152d418e9cc006faf8ec0a742d3ac6f732b17 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Aug 2021 08:42:46 +0000 Subject: [PATCH 3/5] Simplified signature creation --- src/Model/Item.php | 8 +------- src/Protocol/Diaspora.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 0c48c95291..3e0faddf75 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1061,13 +1061,7 @@ class Item // Create Diaspora signature if ($item['origin'] && empty($item['diaspora_signed_text']) && ($item['gravity'] != GRAVITY_PARENT)) { - if ($uid == 0) { - $sender_contact = Contact::getById($item['contact-id'], ['uid']); - $sender_uid = $sender_contact['uid']; - } else { - $sender_uid = $uid; - } - $signed = Diaspora::createCommentSignature($sender_uid, $item); + $signed = Diaspora::createCommentSignature($item); if (!empty($signed)) { $item['diaspora_signed_text'] = json_encode($signed); } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 53140521d0..2c3e9add63 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4044,14 +4044,25 @@ class Diaspora /** * Creates the signature for Comments that are created on our system * - * @param integer $uid The user of that comment * @param array $item Item array * * @return array Signed content * @throws \Exception */ - public static function createCommentSignature($uid, array $item) + public static function createCommentSignature(array $item) { + $contact = Contact::getById($item['author-id'], ['url']); + if (empty($contact['url'])) { + Logger::warning('Author Contact not found', ['author-id' => $item['author-id']]); + return false; + } + + $uid = User::getIdForURL($contact['url']); + if (empty($uid)) { + Logger::info('No owner post, so not storing signature', ['url' => $contact['url']]); + return false; + } + $owner = User::getOwnerDataById($uid); if (empty($owner)) { Logger::info('No owner post, so not storing signature'); From eec6cdf01b1c14cf0c99fe91928b99ad5ed7588e Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Aug 2021 08:51:39 +0000 Subject: [PATCH 4/5] Avoid a database query when possible --- src/Protocol/Diaspora.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 2c3e9add63..485e5a7846 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4051,13 +4051,18 @@ class Diaspora */ public static function createCommentSignature(array $item) { - $contact = Contact::getById($item['author-id'], ['url']); - if (empty($contact['url'])) { - Logger::warning('Author Contact not found', ['author-id' => $item['author-id']]); - return false; + if (!empty($item['author-link'])) { + $url = $item['author-link']; + } else { + $contact = Contact::getById($item['author-id'], ['url']); + if (empty($contact['url'])) { + Logger::warning('Author Contact not found', ['author-id' => $item['author-id']]); + return false; + } + $url = $contact['url']; } - $uid = User::getIdForURL($contact['url']); + $uid = User::getIdForURL($url); if (empty($uid)) { Logger::info('No owner post, so not storing signature', ['url' => $contact['url']]); return false; From d6c25dc63c9189c9e56cf5a32edd9d568019e8da Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Aug 2021 11:37:04 +0000 Subject: [PATCH 5/5] Handle profile page detection without a type --- src/Network/Probe.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 1c0ecc3007..c07cc7e605 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1412,6 +1412,8 @@ class Probe $data["guid"] = $link["href"]; } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (($link["type"] ?? "") == "text/html") && !empty($link["href"])) { $data["url"] = $link["href"]; + } elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && empty($link["type"]) && !empty($link["href"])) { + $profile_url = $link["href"]; } elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) { $data["poll"] = $link["href"]; } elseif (($link["rel"] == ActivityNamespace::POCO) && !empty($link["href"])) { @@ -1428,6 +1430,10 @@ class Probe } } + if (empty($data["url"]) && !empty($profile_url)) { + $data["url"] = $profile_url; + } + if (empty($data["url"]) || empty($hcard_url)) { return []; }