Skip to content

Commit

Permalink
fixed inbox problems with pleroma
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Mar 14, 2019
1 parent fc0c162 commit 8d91b21
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 29 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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? ###
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions includes/class-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function to_simple_array() {
'actor' => $this->actor,
'object' => $this->object,
'to' => $this->to,
'cc' => $this->cc,
);

if ( $this->id ) {
Expand Down
29 changes: 21 additions & 8 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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 );
Expand Down Expand Up @@ -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 ) {
Expand All @@ -195,8 +207,9 @@ function get_identifier_settings( $user_id ) {
<label><?php esc_html_e( 'Profile identifier', 'activitypub' ); ?></label>
</th>
<td>
<p><code><?php echo \Activitypub\get_webfinger_resource( $user_id ); ?></code> or <code><?php echo get_author_posts_url( $user_id ); ?></code></p>
<p class="description"><?php printf( __( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), \Activitypub\get_webfinger_resource( $user_id ) ); ?></p>
<p><code><?php echo esc_html( \Activitypub\get_webfinger_resource( $user_id ) ); ?></code> or <code><?php echo esc_url( get_author_posts_url( $user_id ) ); ?></code></p>
<?php // translators: the webfinger resource ?>
<p class="description"><?php printf( esc_html__( 'Try to follow "@%s" in the mastodon/friendi.ca search field.', 'activitypub' ), esc_html( \Activitypub\get_webfinger_resource( $user_id ) ) ); ?></p>
</td>
</tr>
</tbody>
Expand Down
18 changes: 8 additions & 10 deletions includes/rest/class-outbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ public static function send_post_activity( $post_id ) {
$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 );
}
}

Expand All @@ -161,12 +160,11 @@ public static function send_update_activity( $post_id ) {
$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

$followers = \Activitypub\Db\Followers::get_followers( $user_id );
foreach ( \Activitypub\get_follower_inboxes( $user_id ) as $inbox => $to ) {
$activitypub_activity->set_to( $to );
$activity = $activitypub_activity->to_json(); // phpcs:ignore

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 );
}
}
}
17 changes: 9 additions & 8 deletions languages/activitypub.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ""

Expand Down
13 changes: 12 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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? =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d91b21

Please sign in to comment.