-
Notifications
You must be signed in to change notification settings - Fork 83
Comment: Send announce for all new comments #1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 39 commits
0f4155e
bb1ad46
adab316
c167c7c
c069473
b1d461c
3fcdf0f
ec02ba3
8821578
e658a63
cccddce
592df9b
ced037c
c9bdb96
fb8938d
4a119b3
4bd182a
3888f57
2af0df3
926610b
f8261ad
39afe00
1892e6d
a5ceb57
cd6f04c
cd6e6e3
c701c90
70ccddb
635fdc3
83cc587
2bbaa48
122a951
7f32440
f16bf04
f90bdb0
11e098c
8777641
eb9262d
0dfe418
1c30a7c
a046ba9
a861977
ba1f84f
e2f3a75
2f678e0
ab718f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Incoming interactions create an Announce activity so other instances get notified about it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| namespace Activitypub\Scheduler; | ||
|
|
||
| use Activitypub\Activity\Activity; | ||
| use Activitypub\Collection\Actors; | ||
| use Activitypub\Comment as Comment_Utils; | ||
|
|
||
| use function Activitypub\add_to_outbox; | ||
|
|
@@ -45,9 +47,12 @@ public static function schedule_comment_activity( $new_status, $old_status, $com | |
| } | ||
|
|
||
| $comment = get_comment( $comment ); | ||
| if ( ! $comment ) { | ||
| return; | ||
| } | ||
|
|
||
| // Federate only comments that are written by a registered user. | ||
| if ( ! $comment || ! $comment->user_id ) { | ||
| if ( ! $comment->user_id ) { | ||
| self::maybe_announce_interaction( $new_status, $old_status, $comment ); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -81,6 +86,64 @@ public static function schedule_comment_activity( $new_status, $old_status, $com | |
| add_to_outbox( $comment, $type, $comment->user_id ); | ||
| } | ||
|
|
||
| /** | ||
| * Announce an interaction. | ||
| * | ||
| * When a comment is received from another ActivityPub instance and approved, | ||
| * this method creates an Announce activity so the blog's followers are notified | ||
| * about the interaction. | ||
| * | ||
| * @param string $new_status The new comment status. | ||
| * @param string $old_status The old comment status. | ||
| * @param \WP_Comment $comment The comment object. | ||
| */ | ||
| public static function maybe_announce_interaction( $new_status, $old_status, $comment ) { | ||
| // Only if we're in both Blog and User modes. | ||
| if ( ACTIVITYPUB_ACTOR_AND_BLOG_MODE !== \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( 'approved' !== $new_status || 'approved' === $old_status ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( ! Comment_Utils::was_received( $comment ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // Get activity from comment meta. | ||
| $activity = \get_comment_meta( $comment->comment_ID, '_activitypub_activity', true ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get this from the Inbox, instead of saving it in comment meta?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can postpone this a bit until we have the inbox activated by default. PR incoming. |
||
|
|
||
| // Validate activity structure. | ||
| if ( ! $activity || ! \is_array( $activity ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // Ensure object exists in the activity. | ||
| if ( empty( $activity['object'] ) || ! \is_array( $activity['object'] ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // Get the blog actor. | ||
| $blog_actor = Actors::get_by_id( Actors::BLOG_USER_ID ); | ||
| if ( ! $blog_actor || \is_wp_error( $blog_actor ) ) { | ||
| return; | ||
| } | ||
|
|
||
| $blog_actor_id = $blog_actor->get_id(); | ||
|
|
||
| // Create the Announce activity. | ||
| $announce = new Activity(); | ||
| $announce->set_type( 'Announce' ); | ||
| $announce->set_actor( $blog_actor_id ); | ||
| $announce->set_object( $activity ); | ||
pfefferle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $announce->set_to( array( $blog_actor_id ) ); | ||
| $announce->set_cc( array( $blog_actor_id ) ); | ||
pfefferle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Add to outbox with error handling. | ||
| add_to_outbox( $announce, null, Actors::BLOG_USER_ID, ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC ); | ||
| } | ||
|
|
||
| /** | ||
| * Schedule Comment Activities on insert. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.