| Línea 210... | 
            Línea 210... | 
          
          
            | 210 | 
             
  | 
            210 | 
             
  | 
          
          
            | 211 | 
                        // TODO MDL-31118 performance improvement - edit the function so we can pass an array instead userid
  | 
            211 | 
                        // TODO MDL-31118 performance improvement - edit the function so we can pass an array instead userid
  | 
          
          
            | 212 | 
                        // Check if the recipient can be messaged by the sender.
  | 
            212 | 
                        // Check if the recipient can be messaged by the sender.
  | 
          
          
            | 213 | 
                        if ($success && !\core_message\api::can_send_message($tousers[$message['touserid']]->id, $USER->id)) {
  | 
            213 | 
                        if ($success && !\core_message\api::can_send_message($tousers[$message['touserid']]->id, $USER->id)) {
  | 
          
          
            | 214 | 
                            $success = false;
  | 
            214 | 
                            $success = false;
  | 
          
          
            | 215 | 
                            $errormessage = get_string('usercantbemessaged', 'message', fullname(\core_user::get_user($message['touserid'])));
  | 
            215 | 
                            $errormessage = get_string('usercantbemessaged', 'message');
  | 
          
          
            | Línea 216... | 
            Línea 216... | 
          
          
            | 216 | 
                        }
  | 
            216 | 
                        }
  | 
          
          
            | 217 | 
             
  | 
            217 | 
             
  | 
          
          
            | 218 | 
                        // Now we can send the message (at least try).
  | 
            218 | 
                        // Now we can send the message (at least try).
  | 
          
          
            | Línea 1067... | 
            Línea 1067... | 
          
          
            | 1067 | 
                        'isdeleted' => new external_value(PARAM_BOOL, 'Is the user deleted?'),
  | 
            1067 | 
                        'isdeleted' => new external_value(PARAM_BOOL, 'Is the user deleted?'),
  | 
          
          
            | 1068 | 
                        'canmessageevenifblocked' => new external_value(PARAM_BOOL,
  | 
            1068 | 
                        'canmessageevenifblocked' => new external_value(PARAM_BOOL,
  | 
          
          
            | 1069 | 
                            'If the user can still message even if they get blocked'),
  | 
            1069 | 
                            'If the user can still message even if they get blocked'),
  | 
          
          
            | 1070 | 
                        'canmessage' => new external_value(PARAM_BOOL, 'If the user can be messaged'),
  | 
            1070 | 
                        'canmessage' => new external_value(PARAM_BOOL, 'If the user can be messaged'),
  | 
          
          
            | 1071 | 
                        'requirescontact' => new external_value(PARAM_BOOL, 'If the user requires to be contacts'),
  | 
            1071 | 
                        'requirescontact' => new external_value(PARAM_BOOL, 'If the user requires to be contacts'),
  | 
          
          
            | - | 
               | 
            1072 | 
                        'cancreatecontact' => new external_value(PARAM_BOOL, 'Is the user permitted to add a contact'),
  | 
          
          
            | 1072 | 
                    ];
  | 
            1073 | 
                    ];
  | 
          
          
            | Línea 1073... | 
            Línea 1074... | 
          
          
            | 1073 | 
             
  | 
            1074 | 
             
  | 
          
          
            | 1074 | 
                    $result['contactrequests'] = new external_multiple_structure(
  | 
            1075 | 
                    $result['contactrequests'] = new external_multiple_structure(
  | 
          
          
            | 1075 | 
                        new external_single_structure(
  | 
            1076 | 
                        new external_single_structure(
  | 
          
          
            | Línea 1331... | 
            Línea 1332... | 
          
          
            | 1331 | 
                 *             when private conversations are requested.
  | 
            1332 | 
                 *             when private conversations are requested.
  | 
          
          
            | 1332 | 
                 * @return stdClass
  | 
            1333 | 
                 * @return stdClass
  | 
          
          
            | 1333 | 
                 * @throws \moodle_exception if the messaging feature is disabled on the site.
  | 
            1334 | 
                 * @throws \moodle_exception if the messaging feature is disabled on the site.
  | 
          
          
            | 1334 | 
                 * @since 3.2
  | 
            1335 | 
                 * @since 3.2
  | 
          
          
            | 1335 | 
                 */
  | 
            1336 | 
                 */
  | 
          
          
            | 1336 | 
                public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, int $type = null, bool $favourites = null,
  | 
            1337 | 
                public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, ?int $type = null, ?bool $favourites = null,
  | 
          
          
            | 1337 | 
                        bool $mergeself = false) {
  | 
            1338 | 
                        bool $mergeself = false) {
  | 
          
          
            | 1338 | 
                    global $CFG, $USER;
  | 
            1339 | 
                    global $CFG, $USER;
  | 
          
          
            | Línea 1339... | 
            Línea 1340... | 
          
          
            | 1339 | 
             
  | 
            1340 | 
             
  | 
          
          
            | 1340 | 
                    // All the standard BL checks.
  | 
            1341 | 
                    // All the standard BL checks.
  | 
          
          
            | Línea 3026... | 
            Línea 3027... | 
          
          
            | 3026 | 
                /**
  | 
            3027 | 
                /**
  | 
          
          
            | 3027 | 
                 * Returns a notification or message preference structure.
  | 
            3028 | 
                 * Returns a notification or message preference structure.
  | 
          
          
            | 3028 | 
                 *
  | 
            3029 | 
                 *
  | 
          
          
            | 3029 | 
                 * @return external_single_structure the structure
  | 
            3030 | 
                 * @return external_single_structure the structure
  | 
          
          
            | 3030 | 
                 * @since  Moodle 3.2
  | 
            3031 | 
                 * @since  Moodle 3.2
  | 
          
          
            | 3031 | 
                 * @todo Remove loggedin and loggedoff from processors structure on MDL-73284.
  | 
            - | 
               | 
          
          
            | 3032 | 
                 */
  | 
            3032 | 
                 */
  | 
          
          
            | 3033 | 
                protected static function get_preferences_structure() {
  | 
            3033 | 
                protected static function get_preferences_structure() {
  | 
          
          
            | 3034 | 
                    return new external_single_structure(
  | 
            3034 | 
                    return new external_single_structure(
  | 
          
          
            | 3035 | 
                        array(
  | 
            3035 | 
                        array(
  | 
          
          
            | 3036 | 
                            'userid' => new external_value(PARAM_INT, 'User id'),
  | 
            3036 | 
                            'userid' => new external_value(PARAM_INT, 'User id'),
  | 
          
          
            | Línea 3063... | 
            Línea 3063... | 
          
          
            | 3063 | 
                                                                'name' => new external_value(PARAM_PLUGIN, 'Processor name'),
  | 
            3063 | 
                                                                'name' => new external_value(PARAM_PLUGIN, 'Processor name'),
  | 
          
          
            | 3064 | 
                                                                'locked' => new external_value(PARAM_BOOL, 'Is locked by admin?'),
  | 
            3064 | 
                                                                'locked' => new external_value(PARAM_BOOL, 'Is locked by admin?'),
  | 
          
          
            | 3065 | 
                                                                'lockedmessage' => new external_value(PARAM_TEXT,
  | 
            3065 | 
                                                                'lockedmessage' => new external_value(PARAM_TEXT,
  | 
          
          
            | 3066 | 
                                                                    'Text to display if locked', VALUE_OPTIONAL),
  | 
            3066 | 
                                                                    'Text to display if locked', VALUE_OPTIONAL),
  | 
          
          
            | 3067 | 
                                                                'userconfigured' => new external_value(PARAM_INT, 'Is configured?'),
  | 
            3067 | 
                                                                'userconfigured' => new external_value(PARAM_INT, 'Is configured?'),
  | 
          
          
            | 3068 | 
                                                                'loggedin' => new external_single_structure(
  | 
            - | 
               | 
          
          
            | 3069 | 
                                                                    array(
  | 
            - | 
               | 
          
          
            | 3070 | 
                                                                        'name' => new external_value(PARAM_NOTAGS, 'Name'),
  | 
            - | 
               | 
          
          
            | 3071 | 
                                                                        'displayname' => new external_value(PARAM_TEXT, 'Display name'),
  | 
            - | 
               | 
          
          
            | 3072 | 
                                                                        'checked' => new external_value(PARAM_BOOL, 'Is checked?'),
  | 
            - | 
               | 
          
          
            | 3073 | 
                                                                    ),
  | 
            - | 
               | 
          
          
            | 3074 | 
                                                                    'DEPRECATED ATTRIBUTE -
  | 
            - | 
               | 
          
          
            | 3075 | 
                                                                    Kept for backward compatibility, use enabled instead.',
  | 
            - | 
               | 
          
          
            | 3076 | 
                                                                ),
  | 
            - | 
               | 
          
          
            | 3077 | 
                                                                'loggedoff' => new external_single_structure(
  | 
            - | 
               | 
          
          
            | 3078 | 
                                                                    array(
  | 
            - | 
               | 
          
          
            | 3079 | 
                                                                        'name' => new external_value(PARAM_NOTAGS, 'Name'),
  | 
            - | 
               | 
          
          
            | 3080 | 
                                                                        'displayname' => new external_value(PARAM_TEXT, 'Display name'),
  | 
            - | 
               | 
          
          
            | 3081 | 
                                                                        'checked' => new external_value(PARAM_BOOL, 'Is checked?'),
  | 
            - | 
               | 
          
          
            | 3082 | 
                                                                    ),
  | 
            - | 
               | 
          
          
            | 3083 | 
                                                                    'DEPRECATED ATTRIBUTE -
  | 
            - | 
               | 
          
          
            | 3084 | 
                                                                    Kept for backward compatibility, use enabled instead.',
  | 
            - | 
               | 
          
          
            | 3085 | 
                                                                ),
  | 
            - | 
               | 
          
          
            | 3086 | 
                                                                'enabled' => new external_value(PARAM_BOOL, 'Is enabled?'),
  | 
            3068 | 
                                                                'enabled' => new external_value(PARAM_BOOL, 'Is enabled?'),
  | 
          
          
            | 3087 | 
                                                            )
  | 
            3069 | 
                                                            )
  | 
          
          
            | 3088 | 
                                                        ),
  | 
            3070 | 
                                                        ),
  | 
          
          
            | 3089 | 
                                                        'Processors values for this notification'
  | 
            3071 | 
                                                        'Processors values for this notification'
  | 
          
          
            | 3090 | 
                                                    ),
  | 
            3072 | 
                                                    ),
  | 
          
          
            | Línea 3393... | 
            Línea 3375... | 
          
          
            | 3393 | 
                    int $referenceuserid,
  | 
            3375 | 
                    int $referenceuserid,
  | 
          
          
            | 3394 | 
                    array $userids,
  | 
            3376 | 
                    array $userids,
  | 
          
          
            | 3395 | 
                    bool $includecontactrequests = false,
  | 
            3377 | 
                    bool $includecontactrequests = false,
  | 
          
          
            | 3396 | 
                    bool $includeprivacyinfo = false
  | 
            3378 | 
                    bool $includeprivacyinfo = false
  | 
          
          
            | 3397 | 
                ) {
  | 
            3379 | 
                ) {
  | 
          
          
            | 3398 | 
                    global $CFG, $USER;
  | 
            3380 | 
                    global $CFG, $USER, $DB;
  | 
          
          
            | Línea 3399... | 
            Línea 3381... | 
          
          
            | 3399 | 
             
  | 
            3381 | 
             
  | 
          
          
            | 3400 | 
                    // All the business logic checks that really shouldn't be in here.
  | 
            3382 | 
                    // All the business logic checks that really shouldn't be in here.
  | 
          
          
            | 3401 | 
                    if (empty($CFG->messaging)) {
  | 
            3383 | 
                    if (empty($CFG->messaging)) {
  | 
          
          
            | 3402 | 
                        throw new moodle_exception('disabled', 'message');
  | 
            3384 | 
                        throw new moodle_exception('disabled', 'message');
  | 
          
          
            | Línea 3413... | 
            Línea 3395... | 
          
          
            | 3413 | 
             
  | 
            3395 | 
             
  | 
          
          
            | 3414 | 
                    if (($USER->id != $referenceuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
  | 
            3396 | 
                    if (($USER->id != $referenceuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
  | 
          
          
            | 3415 | 
                        throw new moodle_exception('You do not have permission to perform this action.');
  | 
            3397 | 
                        throw new moodle_exception('You do not have permission to perform this action.');
  | 
          
          
            | Línea -... | 
            Línea 3398... | 
          
          
            | - | 
               | 
            3398 | 
                    }
  | 
          
          
            | - | 
               | 
            3399 | 
             
  | 
          
          
            | - | 
               | 
            3400 | 
                    // Return early if no userids are provided.
  | 
          
          
            | - | 
               | 
            3401 | 
                    if (empty($params['userids'])) {
  | 
          
          
            | - | 
               | 
            3402 | 
                        return [];
  | 
          
          
            | - | 
               | 
            3403 | 
                    }
  | 
          
          
            | - | 
               | 
            3404 | 
             
  | 
          
          
            | - | 
               | 
            3405 | 
                    // Filter the user IDs, removing the IDs of the users that the current user cannot view.
  | 
          
          
            | - | 
               | 
            3406 | 
                    require_once($CFG->dirroot . '/user/lib.php');
  | 
          
          
            | - | 
               | 
            3407 | 
                    $userfieldsapi = \core_user\fields::for_userpic()->including('username', 'deleted');
  | 
          
          
            | - | 
               | 
            3408 | 
                    $userfields = $userfieldsapi->get_sql('', false, '', '', false)->selects;
  | 
          
          
            | - | 
               | 
            3409 | 
                    $users = $DB->get_records_list('user', 'id', $userids, '', $userfields, 0, 100);
  | 
          
          
            | - | 
               | 
            3410 | 
                    $filteredids = array_filter($params['userids'], function($userid) use ($users, $params) {
  | 
          
          
            | - | 
               | 
            3411 | 
                        $targetuser = $users[$userid];
  | 
          
          
            | - | 
               | 
            3412 | 
                        // Check if the user has the contact already.
  | 
          
          
            | - | 
               | 
            3413 | 
                        $iscontact = \core_message\api::is_contact($params['referenceuserid'], $userid);
  | 
          
          
            | - | 
               | 
            3414 | 
                        if ($iscontact) {
  | 
          
          
            | - | 
               | 
            3415 | 
                            // User is a contact, so we can return the info for this user.
  | 
          
          
            | - | 
               | 
            3416 | 
                            return true;
  | 
          
          
            | - | 
               | 
            3417 | 
                        } else {
  | 
          
          
            | - | 
               | 
            3418 | 
                            // User is not a contact, so we need to check if the user is allowed to see the profile or not.
  | 
          
          
            | - | 
               | 
            3419 | 
                            return user_can_view_profile($targetuser);
  | 
          
          
            | - | 
               | 
            3420 | 
                        }
  | 
          
          
            | - | 
               | 
            3421 | 
                    });
  | 
          
          
            | - | 
               | 
            3422 | 
             
  | 
          
          
            | - | 
               | 
            3423 | 
                    // Return early if no user IDs are left after filtering.
  | 
          
          
            | - | 
               | 
            3424 | 
                    if (empty($filteredids)) {
  | 
          
          
            | - | 
               | 
            3425 | 
                        return [];
  | 
          
          
            | 3416 | 
                    }
  | 
            3426 | 
                    }
  | 
          
          
            | 3417 | 
             
  | 
            3427 | 
             
  | 
          
          
            | 3418 | 
                    return \core_message\helper::get_member_info(
  | 
            3428 | 
                    return \core_message\helper::get_member_info(
  | 
          
          
            | 3419 | 
                        $params['referenceuserid'],
  | 
            3429 | 
                        $params['referenceuserid'],
  | 
          
          
            | 3420 | 
                        $params['userids'],
  | 
            3430 | 
                        $filteredids,
  | 
          
          
            | 3421 | 
                        $params['includecontactrequests'],
  | 
            3431 | 
                        $params['includecontactrequests'],
  | 
          
          
            | 3422 | 
                        $params['includeprivacyinfo']
  | 
            3432 | 
                        $params['includeprivacyinfo']
  |