Skip to content

Commit

Permalink
GP Profiles: Send notifications for single reviews.
Browse files Browse the repository at this point in the history
See WordPress/five-for-the-future#196

git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11974 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
iandunn committed Jul 18, 2022
1 parent 67e3931 commit e582d96
Showing 1 changed file with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function add_single_translation_activity( GP_Translation $new_translation, GP_Tr
$new_translation->translation_set_id
);

$activities = array();
$review_status = gp_post( 'status' );
$valid_review_statuses = array( 'current', 'rejected', 'fuzzy' );
$is_reviewing = $current_user_is_editor && get_current_user_id() !== $new_translation->user_id &&
$review_status && in_array( $review_status, $valid_review_statuses, true );

/*
* Regular user is suggesting a string.
*
Expand All @@ -57,22 +63,38 @@ function add_single_translation_activity( GP_Translation $new_translation, GP_Tr
* to avoid two notifications for a single action.
*/
if ( 'waiting' === $new_translation->status && ! $current_user_is_editor ) {
$type = 'glotpress_translation_suggested';
$activities[] = array(
'component' => 'glotpress',
'type' => 'glotpress_translation_suggested',
'user_id' => $new_translation->user_id,
);

// Editor is approving a suggested string.
// Avoid sending a notification when a `current` post is re-saved, like when dismissing warnings.
} elseif ( 'current' === $new_translation->status && isset( $previous_translation->status ) && 'current' !== $previous_translation->status ) {
$type = 'glotpress_translation_approved';
$activities[] = array(
'component' => 'glotpress',
'type' => 'glotpress_translation_approved',
'user_id' => $new_translation->user_id,
);
}

} else {
if ( $is_reviewing ) {
$activities[] = array(
'component' => 'glotpress',
'type' => 'glotpress_translation_reviewed',
'user_id' => get_current_user_id(),
);
}

if ( empty( $activities ) ) {
return;
}

$request_body = array(
'action' => 'wporg_handle_activity',
'component' => 'glotpress',
'type' => $type,
'user_id' => $new_translation->user_id,
'activities' => $activities,
);

Profiles_API\api( $request_body );
Expand Down

0 comments on commit e582d96

Please sign in to comment.