You are here

public function PrivateMessageActivityContext::getRecipients in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  2. 8 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  3. 8.3 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  4. 8.4 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  5. 8.5 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  6. 8.6 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  7. 8.7 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  8. 8.8 modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  9. 10.3.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  10. 10.0.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  11. 10.1.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()
  12. 10.2.x modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php \Drupal\social_private_message\Plugin\ActivityContext\PrivateMessageActivityContext::getRecipients()

Returns a batched list of recipients for this context.

Format array( array ( id = uid or gip type = "user / group" ) )

Overrides ActivityContextBase::getRecipients

File

modules/social_features/social_private_message/src/Plugin/ActivityContext/PrivateMessageActivityContext.php, line 22

Class

PrivateMessageActivityContext
Provides a 'PrivateMessageActivityContext' activity context.

Namespace

Drupal\social_private_message\Plugin\ActivityContext

Code

public function getRecipients(array $data, $last_uid, $limit) {
  $recipients = [];

  // We only know the context if there is a related object.
  if (isset($data['related_object']) && !empty($data['related_object'])) {
    $related_object = $data['related_object'][0];
    if ($related_object['target_type'] == 'private_message') {
      $related_object = $data['related_object'][0];
      if ($related_object['target_type'] === 'private_message') {
        $private_message = PrivateMessage::load($related_object['target_id']);

        // Must be a Private Message.
        if ($private_message instanceof PrivateMessage) {
          $pmService = \Drupal::service('private_message.service');

          // Get the thread of this message.
          $thread = $pmService
            ->getThreadFromMessage($private_message);

          // Get all members of this thread.

          /** @var \Drupal\private_message\Entity\PrivateMessageThreadInterface $members */
          $members = $thread
            ->getMembers();

          // Loop over all PMT participants.
          foreach ($members as $member) {
            if ($member instanceof User) {

              // Filter out the author of this message.
              if ($member
                ->id() == $data['actor']) {
                continue;
              }

              // Create the recipients array.
              $recipients[] = [
                'target_type' => 'user',
                'target_id' => $member
                  ->id(),
              ];
            }
          }
        }
      }
    }
  }
  return $recipients;
}