From 8d91b213e786fc4e159eeb726c11e93e71069149 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 14 Mar 2019 23:10:11 +0100 Subject: [PATCH] fixed inbox problems with pleroma --- README.md | 13 ++++++++++++- activitypub.php | 2 +- includes/class-activity.php | 1 + includes/functions.php | 29 +++++++++++++++++++++-------- includes/rest/class-outbox.php | 18 ++++++++---------- languages/activitypub.pot | 17 +++++++++-------- readme.txt | 13 ++++++++++++- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index f45574d..dee46f4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** OStatus, fediverse, activitypub, activitystream **Requires at least:** 4.7 **Tested up to:** 5.1.1 -**Stable tag:** 0.7.0 +**Stable tag:** 0.7.1 **Requires PHP:** 5.6 **License:** MIT **License URI:** http://opensource.org/licenses/MIT @@ -17,6 +17,13 @@ This is **BETA** software, see the FAQ to see the current feature set or rather The plugin implements the ActivityPub protocol for your Blog. Your readers will be able to follow your Blogposts on Mastodon and other Federated Plattforms that support ActivityPub. +The plugin works with the following federated plattforms: + +* [mastodon](https://joinmastodon.org/) +* [pleroma](https://pleroma.social/) +* [friendi.ca](https://friendi.ca/) +* [hubzilla](https://hubzilla.org/) + ## Frequently Asked Questions ## ### What is the status of this plugin? ### @@ -55,6 +62,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). +### 0.7.1 ### + +* fixed inbox problems with pleroma + ### 0.7.0 ### * finally fixed pleroma compatibility diff --git a/activitypub.php b/activitypub.php index 19cda5f..0871d7c 100644 --- a/activitypub.php +++ b/activitypub.php @@ -3,7 +3,7 @@ * Plugin Name: ActivityPub * Plugin URI: https://github.com/pfefferle/wordpress-activitypub/ * Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format. - * Version: 0.7.0 + * Version: 0.7.1 * Author: Matthias Pfefferle * Author URI: https://notiz.blog/ * License: MIT diff --git a/includes/class-activity.php b/includes/class-activity.php index 2a18403..20fbde7 100644 --- a/includes/class-activity.php +++ b/includes/class-activity.php @@ -79,6 +79,7 @@ class Activity { 'actor' => $this->actor, 'object' => $this->object, 'to' => $this->to, + 'cc' => $this->cc, ); if ( $this->id ) { diff --git a/includes/functions.php b/includes/functions.php index c6e362d..4b29b3b 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -61,7 +61,11 @@ function safe_remote_post( $url, $body, $user_id ) { 'body' => $body, ); - return wp_safe_remote_post( $url, $args ); + $response = wp_safe_remote_post( $url, $args ); + + do_action( 'activitypub_safe_remote_post_response', $response, $url, $body, $user_id ); + + return $response; } /** @@ -85,8 +89,9 @@ function get_webfinger_resource( $user_id ) { /** * [get_metadata_by_actor description] * - * @param [type] $actor [description] - * @return [type] [description] + * @param sting $actor + * + * @return array */ function get_remote_metadata_by_actor( $actor ) { $metadata = get_transient( 'activitypub_' . $actor ); @@ -177,13 +182,20 @@ function get_publickey_by_actor( $actor, $key_id ) { return new \WP_Error( 'activitypub_no_public_key', __( 'No "Public-Key" found', 'activitypub' ), $metadata ); } -function get_follower_inboxes( $user_id, $followers ) { +function get_follower_inboxes( $user_id ) { + $followers = \Activitypub\Db\Followers::get_followers( $user_id ); $inboxes = array(); + foreach ( $followers as $follower ) { - $inboxes[] = \Activitypub\get_inbox_by_actor( $follower ); + $inbox = \Activitypub\get_inbox_by_actor( $follower ); + // init array if empty + if ( ! empty( $inboxes[ $inbox ] ) ) { + $inboxes[ $inbox ] = array(); + } + $inboxes[ $inbox ][] = $follower; } - return array_unique( $inboxes ); + return $inboxes; } function get_identifier_settings( $user_id ) { @@ -195,8 +207,9 @@ function get_identifier_settings( $user_id ) { -

or

-

+

or

+ +

diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 4ce34d4..fdf6845 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -139,12 +139,11 @@ class Outbox { $activitypub_activity = new \Activitypub\Activity( 'Create', \Activitypub\Activity::TYPE_FULL ); $activitypub_activity->from_post( $activitypub_post->to_array() ); - $activity = $activitypub_activity->to_json(); // phpcs:ignore + foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) { + $activitypub_activity->set_to( $to ); + $activity = $activitypub_activity->to_json(); // phpcs:ignore - $followers = \Activitypub\Db\Followers::get_followers( $user_id ); - - foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) { - $response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id ); + \Activitypub\safe_remote_post( $inbox, $activity, $user_id ); } } @@ -161,12 +160,11 @@ class Outbox { $activitypub_activity = new \Activitypub\Activity( 'Update', \Activitypub\Activity::TYPE_FULL ); $activitypub_activity->from_post( $activitypub_post->to_array() ); - $activity = $activitypub_activity->to_json(); // phpcs:ignore + foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) { + $activitypub_activity->set_to( $to ); + $activity = $activitypub_activity->to_json(); // phpcs:ignore - $followers = \Activitypub\Db\Followers::get_followers( $user_id ); - - foreach ( \Activitypub\get_follower_inboxes( $user_id, $followers ) as $inbox ) { - $response = \Activitypub\safe_remote_post( $inbox, $activity, $user_id ); + \Activitypub\safe_remote_post( $inbox, $activity, $user_id ); } } } diff --git a/languages/activitypub.pot b/languages/activitypub.pot index fa28aee..d50c3ac 100644 --- a/languages/activitypub.pot +++ b/languages/activitypub.pot @@ -2,9 +2,9 @@ # This file is distributed under the MIT. msgid "" msgstr "" -"Project-Id-Version: ActivityPub 0.6.0\n" +"Project-Id-Version: ActivityPub 0.7.1\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n" -"POT-Creation-Date: 2019-03-12 21:22:31+00:00\n" +"POT-Creation-Date: 2019-03-14 22:10:06+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -79,27 +79,28 @@ msgstr "" msgid "Unknown Actor schema" msgstr "" -#: includes/functions.php:99 +#: includes/functions.php:104 msgid "The \"actor\" is no valid URL" msgstr "" -#: includes/functions.php:123 +#: includes/functions.php:128 msgid "No valid JSON data" msgstr "" -#: includes/functions.php:151 +#: includes/functions.php:156 msgid "No \"Inbox\" found" msgstr "" -#: includes/functions.php:177 +#: includes/functions.php:182 msgid "No \"Public-Key\" found" msgstr "" -#: includes/functions.php:195 +#: includes/functions.php:207 msgid "Profile identifier" msgstr "" -#: includes/functions.php:199 +#: includes/functions.php:212 +#. translators: the webfinger resource msgid "Try to follow \"@%s\" in the mastodon/friendi.ca search field." msgstr "" diff --git a/readme.txt b/readme.txt index d540294..8815124 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://notiz.blog/donate/ Tags: OStatus, fediverse, activitypub, activitystream Requires at least: 4.7 Tested up to: 5.1.1 -Stable tag: 0.7.0 +Stable tag: 0.7.1 Requires PHP: 5.6 License: MIT License URI: http://opensource.org/licenses/MIT @@ -17,6 +17,13 @@ This is **BETA** software, see the FAQ to see the current feature set or rather The plugin implements the ActivityPub protocol for your Blog. Your readers will be able to follow your Blogposts on Mastodon and other Federated Plattforms that support ActivityPub. +The plugin works with the following federated plattforms: + +* [mastodon](https://joinmastodon.org/) +* [pleroma](https://pleroma.social/) +* [friendi.ca](https://friendi.ca/) +* [hubzilla](https://hubzilla.org/) + == Frequently Asked Questions == = What is the status of this plugin? = @@ -55,6 +62,10 @@ To implement: Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub). += 0.7.1 = + +* fixed inbox problems with pleroma + = 0.7.0 = * finally fixed pleroma compatibility