public function checkIfMessageExist($message_type, $context, array $destination, array $related_object, $uid) {
    $exists = FALSE;

    $query = \Drupal::entityQuery('message');
    $query->condition('template', $message_type);
    $query->condition('field_message_related_object.target_id', $related_object['target_id']);
    $query->condition('field_message_related_object.target_type', $related_object['target_type']);
    $query->condition('field_message_context', $context);
    $query->condition('uid', $uid);
    if (is_array($destination)) {
      foreach ($destination as $delta => $dest_value) {
        $query->condition('field_message_destination.' . $delta . '.value', $dest_value['value']);
      }
    }
    $query->accessCheck(FALSE);

    // Fix duplicates for create_bundle_group && moved_content_between_groups
    // create_bundle_group is run on cron, it could be there is already a
    // message for moving content between groups. So we need to make sure we
    // check if either create_bundle_group or move_content is already there
    // before we add another message that content is created in a group.
    $types = [
      'moved_content_between_groups',
      'create_topic_group',
      'create_event_group',
    ];

    if (in_array($message_type, $types, TRUE)) {
      $query = \Drupal::entityQuery('message');
      $query->condition('template', $types, 'IN');
      $query->condition('field_message_related_object.target_id', $related_object['target_id']);
      $query->condition('field_message_related_object.target_type', $related_object['target_type']);
      $query->condition('field_message_context', $context);
      $query->condition('uid', $uid);
      $query->accessCheck(FALSE);
    }

    $ids = $query->execute();
    if (!empty($ids) && $message_type != 'moved_content_between_groups') {
      $exists = TRUE;
    }
    return $exists;
  }