Merge branch 'MDL-63882-master' of git://github.com/damyon/moodle
authorDavid Monllao <davidm@moodle.com>
Tue, 13 Nov 2018 15:07:14 +0000 (16:07 +0100)
committerDavid Monllao <davidm@moodle.com>
Tue, 13 Nov 2018 15:07:14 +0000 (16:07 +0100)
1  2 
message/externallib.php

diff --combined message/externallib.php
@@@ -39,76 -39,6 +39,76 @@@ require_once($CFG->dirroot . "/message/
   * @since Moodle 2.2
   */
  class core_message_external extends external_api {
 +    /**
 +     * Returns description of method parameters
 +     *
 +     * @return external_function_parameters
 +     * @since Moodle 3.6
 +     */
 +    public static function send_messages_to_conversation_parameters() {
 +        return new external_function_parameters(
 +            array(
 +                'conversationid' => new external_value(PARAM_INT, 'id of the conversation'),
 +                'messages' => new external_multiple_structure(
 +                    new external_single_structure(
 +                        array(
 +                            'text' => new external_value(PARAM_RAW, 'the text of the message'),
 +                            'textformat' => new external_format_value('text', VALUE_DEFAULT, FORMAT_MOODLE),
 +                        )
 +                    )
 +                )
 +            )
 +        );
 +    }
 +
 +    /**
 +     * Send messages from the current USER to a conversation.
 +     *
 +     * This conversation may be any type of conversation, individual or group.
 +     *
 +     * @param int $conversationid the id of the conversation to which the messages will be sent.
 +     * @param array $messages An array of message to send.
 +     * @return array the array of messages which were sent (created).
 +     * @since Moodle 3.6
 +     */
 +    public static function send_messages_to_conversation(int $conversationid, array $messages = []) {
 +        global $CFG, $USER;
 +
 +        // Check if messaging is enabled.
 +        if (empty($CFG->messaging)) {
 +            throw new moodle_exception('disabled', 'message');
 +        }
 +
 +        // Ensure the current user is allowed to run this function.
 +        $context = context_system::instance();
 +        self::validate_context($context);
 +
 +        $params = self::validate_parameters(self::send_messages_to_conversation_parameters(), [
 +            'conversationid' => $conversationid,
 +            'messages' => $messages
 +        ]);
 +
 +        $messages = [];
 +        foreach ($params['messages'] as $message) {
 +            $messages[] = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'],
 +                $message['textformat']);
 +        }
 +
 +        return $messages;
 +    }
 +
 +    /**
 +     * Returns description of method result value.
 +     *
 +     * @return external_description
 +     * @since Moodle 3.6
 +     */
 +    public static function send_messages_to_conversation_returns() {
 +        return new external_multiple_structure(
 +            self::get_conversation_message_structure()
 +        );
 +    }
 +
  
      /**
       * Returns description of method parameters
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = array('userids' => $userids, 'userid' => $userid);
+         $params = self::validate_parameters(self::create_contacts_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = array('userids' => $userids, 'userid' => $userid);
-         $params = self::validate_parameters(self::create_contacts_parameters(), $params);
          $warnings = array();
          foreach ($params['userids'] as $id) {
-             if (!message_add_contact($id, 0, $userid)) {
+             if (!message_add_contact($id, 0, $params['userid'])) {
                  $warnings[] = array(
                      'item' => 'user',
                      'itemid' => $id,
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = array('userids' => $userids, 'userid' => $userid);
+         $params = self::validate_parameters(self::delete_contacts_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = array('userids' => $userids, 'userid' => $userid);
-         $params = self::validate_parameters(self::delete_contacts_parameters(), $params);
          foreach ($params['userids'] as $id) {
-             \core_message\api::remove_contact($userid, $id);
+             \core_message\api::remove_contact($params['userid'], $id);
          }
  
          return null;
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = ['userid' => $userid, 'blockeduserid' => $blockeduserid];
+         $params = self::validate_parameters(self::block_user_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = ['userid' => $userid, 'blockeduserid' => $blockeduserid];
-         $params = self::validate_parameters(self::block_user_parameters(), $params);
          if (!\core_message\api::is_blocked($params['userid'], $params['blockeduserid'])) {
              \core_message\api::block_user($params['userid'], $params['blockeduserid']);
          }
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = ['userid' => $userid, 'unblockeduserid' => $unblockeduserid];
+         $params = self::validate_parameters(self::unblock_user_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = ['userid' => $userid, 'unblockeduserid' => $unblockeduserid];
-         $params = self::validate_parameters(self::unblock_user_parameters(), $params);
          \core_message\api::unblock_user($params['userid'], $params['unblockeduserid']);
  
          return [];
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = array('userids' => $userids, 'userid' => $userid);
+         $params = self::validate_parameters(self::block_contacts_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = array('userids' => $userids, 'userid' => $userid);
-         $params = self::validate_parameters(self::block_contacts_parameters(), $params);
          $warnings = array();
          foreach ($params['userids'] as $id) {
-             if (!message_block_contact($id, $userid)) {
+             if (!message_block_contact($id, $params['userid'])) {
                  $warnings[] = array(
                      'item' => 'user',
                      'itemid' => $id,
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = array('userids' => $userids, 'userid' => $userid);
+         $params = self::validate_parameters(self::unblock_contacts_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = array('userids' => $userids, 'userid' => $userid);
-         $params = self::validate_parameters(self::unblock_contacts_parameters(), $params);
          foreach ($params['userids'] as $id) {
-             message_unblock_contact($id, $userid);
+             message_unblock_contact($id, $params['userid']);
          }
  
          return null;
      public static function get_contact_requests_parameters() {
          return new external_function_parameters(
              [
 -                'userid' => new external_value(PARAM_INT, 'The id of the user we want the requests for')
 +                'userid' => new external_value(PARAM_INT, 'The id of the user we want the requests for'),
 +                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
 +                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0)
              ]
          );
      }
       * It will not include blocked users.
       *
       * @param int $userid The id of the user we want to get the contact requests for
 +     * @param int $limitfrom
 +     * @param int $limitnum
       */
 -    public static function get_contact_requests(int $userid) {
 +    public static function get_contact_requests(int $userid, int $limitfrom = 0, int $limitnum = 0) {
          global $CFG, $USER;
  
          // Check if messaging is enabled.
          $context = context_system::instance();
          self::validate_context($context);
  
-         $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
-             throw new required_capability_exception($context, $capability, 'nopermissions', '');
-         }
 -        $params = ['userid' => $userid];
 +        $params = [
 +            'userid' => $userid,
 +            'limitfrom' => $limitfrom,
 +            'limitnum' => $limitnum
 +        ];
          $params = self::validate_parameters(self::get_contact_requests_parameters(), $params);
  
 -        return \core_message\api::get_contact_requests($params['userid']);
+         $capability = 'moodle/site:manageallmessaging';
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
+             throw new required_capability_exception($context, $capability, 'nopermissions', '');
+         }
 +        return \core_message\api::get_contact_requests($params['userid'], $params['limitfrom'], $params['limitnum']);
      }
  
      /**
       */
      public static function get_contact_requests_returns() {
          return new external_multiple_structure(
 -            new external_single_structure(
 -                [
 -                    'id' => new external_value(core_user::get_property_type('id'), 'ID of the user'),
 -                    'contactrequestid' => new external_value(PARAM_INT, 'The ID of the contact request'),
 -                    'picture' => new external_value(core_user::get_property_type('picture'), 'The picture'),
 -                    'firstname' => new external_value(core_user::get_property_type('firstname'),
 -                        'The first name(s) of the user'),
 -                    'lastname' => new external_value(core_user::get_property_type('lastname'),
 -                        'The family name of the user'),
 -                    'firstnamephonetic' => new external_value(core_user::get_property_type('firstnamephonetic'),
 -                        'The phonetic first name of the user'),
 -                    'lastnamephonetic' => new external_value(core_user::get_property_type('lastnamephonetic'),
 -                        'The phonetic last name of the user'),
 -                    'middlename' => new external_value(core_user::get_property_type('middlename'),
 -                        'The middle name of the user'),
 -                    'alternatename' => new external_value(core_user::get_property_type('alternatename'),
 -                        'The alternate name of the user'),
 -                    'email' => new external_value(core_user::get_property_type('email'), 'An email address')
 -                ]
 -            )
 +            self::get_conversation_member_structure()
          );
      }
  
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = [
+             'userid' => $userid,
+             'conversationid' => $conversationid,
+             'includecontactrequests' => $includecontactrequests,
+             'limitfrom' => $limitfrom,
+             'limitnum' => $limitnum
+         ];
+         $params = self::validate_parameters(self::get_conversation_members_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
          // The user needs to be a part of the conversation before querying who the members are.
-         if (!\core_message\api::is_user_in_conversation($userid, $conversationid)) {
+         if (!\core_message\api::is_user_in_conversation($params['userid'], $params['conversationid'])) {
              throw new moodle_exception('You are not a member of this conversation.');
          }
  
-         $params = [
-             'userid' => $userid,
-             'conversationid' => $conversationid,
-             'includecontactrequests' => $includecontactrequests,
-             'limitfrom' => $limitfrom,
-             'limitnum' => $limitnum
-         ];
-         self::validate_parameters(self::get_conversation_members_parameters(), $params);
  
-         return \core_message\api::get_conversation_members($userid, $conversationid, $includecontactrequests,
-             $limitfrom, $limitnum);
+         return \core_message\api::get_conversation_members($params['userid'], $params['conversationid'], $params['includecontactrequests'],
+             $params['limitfrom'], $params['limitnum']);
      }
  
      /**
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
+         $params = self::validate_parameters(self::create_contact_request_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $userid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['userid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
-         $params = self::validate_parameters(self::create_contact_request_parameters(), $params);
          if (!\core_message\api::can_create_contact($params['userid'], $params['requesteduserid'])) {
              $warning[] = [
                  'item' => 'user',
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
+         $params = self::validate_parameters(self::confirm_contact_request_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $requesteduserid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['requesteduserid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
-         $params = self::validate_parameters(self::confirm_contact_request_parameters(), $params);
          \core_message\api::confirm_contact_request($params['userid'], $params['requesteduserid']);
  
          return [];
          $context = context_system::instance();
          self::validate_context($context);
  
+         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
+         $params = self::validate_parameters(self::decline_contact_request_parameters(), $params);
          $capability = 'moodle/site:manageallmessaging';
-         if (($USER->id != $requesteduserid) && !has_capability($capability, $context)) {
+         if (($USER->id != $params['requesteduserid']) && !has_capability($capability, $context)) {
              throw new required_capability_exception($context, $capability, 'nopermissions', '');
          }
  
-         $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid];
-         $params = self::validate_parameters(self::decline_contact_request_parameters(), $params);
          \core_message\api::decline_contact_request($params['userid'], $params['requesteduserid']);
  
          return [];
       * @return external_single_structure
       * @since Moodle 3.6
       */
 +
      private static function get_conversation_structure() {
          return new external_single_structure(
              array(
                  'id' => new external_value(PARAM_INT, 'The conversation id'),
                  'name' => new external_value(PARAM_NOTAGS, 'The conversation name, if set', VALUE_DEFAULT, null),
                  'subname' => new external_value(PARAM_NOTAGS, 'A subtitle for the conversation name, if set', VALUE_DEFAULT, null),
 +                'imageurl' => new external_value(PARAM_URL, 'A link to the conversation picture, if set', VALUE_DEFAULT, null),
                  'type' => new external_value(PARAM_INT, 'The type of the conversation (1=individual,2=group)'),
                  'membercount' => new external_value(PARAM_INT, 'Total number of conversation members'),
                  'isfavourite' => new external_value(PARAM_BOOL, 'If the user marked conversation this conversation as a favourite'),
                  'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation',
                      VALUE_DEFAULT, null),
                  'members' => new external_multiple_structure(
 -                    self::get_conversation_member_structure()
 +                    self::get_conversation_member_structure(true)
                  ),
                  'messages' => new external_multiple_structure(
                      self::get_conversation_message_structure()
       * Return the structure of a conversation member.
       *
       * @param bool $includecontactrequests Are we including contact requests?
 +     * @param bool $includeconversations Are we including conversations?
       * @return external_single_structure
       * @since Moodle 3.6
       */
 -    private static function get_conversation_member_structure(bool $includecontactrequests = false) {
 +    private static function get_conversation_member_structure(bool $includecontactrequests = false,
 +                                                              bool $includeconversations = false) {
          $result = [
              'id' => new external_value(PARAM_INT, 'The user id'),
              'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'),
              'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'),
              'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'),
              'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?'),
 +            'isdeleted' => new external_value(PARAM_BOOL, 'Is the user deleted?'),
 +            'canmessage' => new external_value(PARAM_BOOL, 'If the user can be messaged'),
 +            'requirescontact' => new external_value(PARAM_BOOL, 'If the user requires to be contacts'),
          ];
  
          if ($includecontactrequests) {
              );
          }
  
 +        if ($includeconversations) {
 +            $result['conversations'] = new external_multiple_structure(new external_single_structure(
 +                array(
 +                    'id' => new external_value(PARAM_INT, 'Conversations id'),
 +                    'type' => new external_value(PARAM_INT, 'Conversation type: private or public'),
 +                    'name' => new external_value(PARAM_TEXT, 'Multilang compatible conversation name'. VALUE_OPTIONAL),
 +                    'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the conversation'),
 +                ), 'information about conversation', VALUE_OPTIONAL),
 +                'Conversations between users', VALUE_OPTIONAL
 +            );
 +        }
 +
          return new external_single_structure(
              $result
          );
      /**
       * Get messagearea search users in course parameters.
       *
 +     * @deprecated since 3.6
 +     *
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get messagearea search users in course results.
       *
 +     * @deprecated since 3.6
 +     *
 +     * NOTE: We are deprecating this function but not search_users_in_course API function for backwards compatibility
 +     * with messaging UI. But should be removed once new group messaging UI is in place and old messaging UI is removed.
 +     * Followup: MDL-63915
 +     *
       * @param int $userid The id of the user who is performing the search
       * @param int $courseid The id of the course
       * @param string $search The string being searched
              'limitfrom' => $limitfrom,
              'limitnum' => $limitnum
          );
-         self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $users = \core_message\api::search_users_in_course($userid, $courseid, $search, $limitfrom, $limitnum);
+         $users = \core_message\api::search_users_in_course(
+             $params['userid'],
+             $params['courseid'],
+             $params['search'],
+             $params['limitfrom'],
+             $params['limitnum']
+         );
          $results = new \core_message\output\messagearea\user_search_results($users);
  
          $renderer = $PAGE->get_renderer('core_message');
      /**
       * Get messagearea search users in course returns.
       *
 +     * @deprecated since 3.6
 +     *
       * @return external_single_structure
       * @since 3.2
       */
          );
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_search_users_in_course_is_deprecated() {
 +        return true;
 +    }
 +
      /**
       * Get messagearea search users parameters.
       *
 +     * @deprecated since 3.6
 +     *
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get messagearea search users results.
       *
 +     * @deprecated since 3.6
 +     *
 +     * NOTE: We are deprecating this function but not search_users API function for backwards compatibility
 +     * with messaging UI. But should be removed once new group messaging UI is in place and old messaging UI is removed.
 +     * Followup: MDL-63915
 +     *
       * @param int $userid The id of the user who is performing the search
       * @param string $search The string being searched
       * @param int $limitnum
              'search' => $search,
              'limitnum' => $limitnum
          );
-         self::validate_parameters(self::data_for_messagearea_search_users_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_search_users_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         list($contacts, $courses, $noncontacts) = \core_message\api::search_users($userid, $search, $limitnum);
+         list($contacts, $courses, $noncontacts) = \core_message\api::search_users(
+             $params['userid'],
+             $params['search'],
+             $params['limitnum']
+         );
          $search = new \core_message\output\messagearea\user_search_results($contacts, $courses, $noncontacts);
  
          $renderer = $PAGE->get_renderer('core_message');
      /**
       * Get messagearea search users returns.
       *
 +     * @deprecated since 3.6
 +     *
       * @return external_single_structure
       * @since 3.2
       */
          );
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_search_users_is_deprecated() {
 +        return true;
 +    }
 +
 +    /**
 +     * Get messagearea message search users parameters.
 +     *
 +     * @return external_function_parameters
 +     * @since 3.6
 +     */
 +    public static function message_search_users_parameters() {
 +        return new external_function_parameters(
 +            array(
 +                'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'),
 +                'search' => new external_value(PARAM_RAW, 'The string being searched'),
 +                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
 +                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0),
 +            )
 +        );
 +    }
 +
 +    /**
 +     * Get search users results.
 +     *
 +     * @param int $userid The id of the user who is performing the search
 +     * @param string $search The string being searched
 +     * @param int $limitfrom
 +     * @param int $limitnum
 +     * @return array
 +     * @throws moodle_exception
 +     * @since 3.6
 +     */
 +    public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) {
 +        global $CFG, $USER;
 +
 +        // Check if messaging is enabled.
 +        if (empty($CFG->messaging)) {
 +            throw new moodle_exception('disabled', 'message');
 +        }
 +
 +        $systemcontext = context_system::instance();
 +
 +        $params = array(
 +            'userid' => $userid,
 +            'search' => $search,
 +            'limitfrom' => $limitfrom,
 +            'limitnum' => $limitnum
 +        );
 +        $params = self::validate_parameters(self::message_search_users_parameters(), $params);
 +        self::validate_context($systemcontext);
 +
 +        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
 +            throw new moodle_exception('You do not have permission to perform this action.');
 +        }
 +
 +        list($contacts, $noncontacts) = \core_message\api::message_search_users(
 +            $params['userid'],
 +            $params['search'],
 +            $params['limitfrom'],
 +            $params['limitnum']);
 +
 +        return array('contacts' => $contacts, 'noncontacts' => $noncontacts);
 +    }
 +
 +    /**
 +     * Get messagearea message search users returns.
 +     *
 +     * @return external_single_structure
 +     * @since 3.2
 +     */
 +    public static function message_search_users_returns() {
 +        return new external_single_structure(
 +            array(
 +                'contacts' => new external_multiple_structure(
 +                    self::get_conversation_member_structure(false, true)
 +                ),
 +                'noncontacts' => new external_multiple_structure(
 +                    self::get_conversation_member_structure(false, true)
 +                )
 +            )
 +        );
 +    }
 +
      /**
       * Get messagearea search messages parameters.
       *
              'limitnum' => $limitnum
  
          );
-         self::validate_parameters(self::data_for_messagearea_search_messages_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_search_messages_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $messages = \core_message\api::search_messages($userid, $search, $limitfrom, $limitnum);
+         $messages = \core_message\api::search_messages(
+             $params['userid'],
+             $params['search'],
+             $params['limitfrom'],
+             $params['limitnum']
+         );
          $results = new \core_message\output\messagearea\message_search_results($messages);
  
          $renderer = $PAGE->get_renderer('core_message');
              'type' => $type,
              'favourites' => $favourites
          );
-         self::validate_parameters(self::get_conversations_parameters(), $params);
+         $params = self::validate_parameters(self::get_conversations_parameters(), $params);
  
          $systemcontext = context_system::instance();
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $conversations = \core_message\api::get_conversations($userid, $limitfrom, $limitnum, $type, $favourites);
+         $conversations = \core_message\api::get_conversations(
+             $params['userid'],
+             $params['limitfrom'],
+             $params['limitnum'],
+             $params['type'],
+             $params['favourites']
+         );
          return (object) ['conversations' => $conversations];
      }
  
              'limitfrom' => $limitfrom,
              'limitnum' => $limitnum
          );
-         self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $conversations = \core_message\api::get_conversations($userid, $limitfrom, $limitnum);
+         $conversations = \core_message\api::get_conversations($params['userid'], $params['limitfrom'], $params['limitnum']);
  
          // Format the conversations in the legacy style, as the get_conversations method has since been changed.
          $conversations = \core_message\helper::get_conversations_legacy_formatter($conversations);
      /**
       * The messagearea contacts return parameters.
       *
 +     * @deprecated since 3.6
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get messagearea contacts parameters.
       *
 +     * @deprecated since 3.6
       * @param int $userid The id of the user who we are viewing conversations for
       * @param int $limitfrom
       * @param int $limitnum
              'limitfrom' => $limitfrom,
              'limitnum' => $limitnum
          );
-         self::validate_parameters(self::data_for_messagearea_contacts_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_contacts_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $contacts = \core_message\api::get_contacts($userid, $limitfrom, $limitnum);
+         $contacts = \core_message\api::get_contacts($params['userid'], $params['limitfrom'], $params['limitnum']);
          $contacts = new \core_message\output\messagearea\contacts(null, $contacts);
  
          $renderer = $PAGE->get_renderer('core_message');
      /**
       * The messagearea contacts return structure.
       *
 +     * @deprecated since 3.6
       * @return external_single_structure
       * @since 3.2
       */
          return self::data_for_messagearea_conversations_returns();
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_contacts_is_deprecated() {
 +        return true;
 +    }
 +
      /**
       * The messagearea messages parameters.
       *
 +     * @deprecated since 3.6
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get messagearea messages.
       *
 +     * @deprecated since 3.6
       * @param int $currentuserid The current user's id
       * @param int $otheruserid The other user's id
       * @param int $limitfrom
              'newest' => $newest,
              'timefrom' => $timefrom,
          );
-         self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $currentuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         if ($newest) {
+         if ($params['newest']) {
              $sort = 'timecreated DESC';
          } else {
              $sort = 'timecreated ASC';
          // case those messages will be lost.
          //
          // Instead we ignore the current time in the result set to ensure that second is allowed to finish.
-         if (!empty($timefrom)) {
+         if (!empty($params['timefrom'])) {
              $timeto = time() - 1;
          } else {
              $timeto = 0;
          }
  
          // No requesting messages from the current time, as stated above.
-         if ($timefrom == time()) {
+         if ($params['timefrom'] == time()) {
              $messages = [];
          } else {
-             $messages = \core_message\api::get_messages($currentuserid, $otheruserid, $limitfrom,
-                                                         $limitnum, $sort, $timefrom, $timeto);
+             $messages = \core_message\api::get_messages($params['currentuserid'], $params['otheruserid'], $params['limitfrom'],
+                                                         $params['limitnum'], $sort, $params['timefrom'], $timeto);
          }
  
-         $messages = new \core_message\output\messagearea\messages($currentuserid, $otheruserid, $messages);
+         $messages = new \core_message\output\messagearea\messages($params['currentuserid'], $params['otheruserid'], $messages);
  
          $renderer = $PAGE->get_renderer('core_message');
          return $messages->export_for_template($renderer);
      /**
       * The messagearea messages return structure.
       *
 +     * @deprecated since 3.6
       * @return external_single_structure
       * @since 3.2
       */
          );
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_messages_is_deprecated() {
 +        return true;
 +    }
 +
      /**
       * The conversation messages parameters.
       *
              'newest' => $newest,
              'timefrom' => $timefrom,
          );
-         self::validate_parameters(self::get_conversation_messages_parameters(), $params);
+         $params = self::validate_parameters(self::get_conversation_messages_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $currentuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
          // case those messages will be lost.
          //
          // Instead we ignore the current time in the result set to ensure that second is allowed to finish.
-         $timeto = empty($timefrom) ? 0 : time() - 1;
+         $timeto = empty($params['timefrom']) ? 0 : time() - 1;
  
          // No requesting messages from the current time, as stated above.
-         if ($timefrom == time()) {
+         if ($params['timefrom'] == time()) {
              $messages = [];
          } else {
-             $messages = \core_message\api::get_conversation_messages($currentuserid, $convid, $limitfrom,
-                                                         $limitnum, $sort, $timefrom, $timeto);
+             $messages = \core_message\api::get_conversation_messages(
+                 $params['currentuserid'],
+                 $params['convid'],
+                 $params['limitfrom'],
+                 $params['limitnum'],
+                 $sort,
+                 $params['timefrom'],
+                 $timeto);
          }
  
          return $messages;
      /**
       * The get most recent message return parameters.
       *
 +     * @deprecated since 3.6
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get the most recent message in a conversation.
       *
 +     * @deprecated since 3.6
       * @param int $currentuserid The current user's id
       * @param int $otheruserid The other user's id
       * @return stdClass
              'currentuserid' => $currentuserid,
              'otheruserid' => $otheruserid
          );
-         self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $currentuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $message = \core_message\api::get_most_recent_message($currentuserid, $otheruserid);
+         $message = \core_message\api::get_most_recent_message($params['currentuserid'], $params['otheruserid']);
          $message = new \core_message\output\messagearea\message($message);
  
          $renderer = $PAGE->get_renderer('core_message');
      /**
       * The get most recent message return structure.
       *
 +     * @deprecated since 3.6
       * @return external_single_structure
       * @since 3.2
       */
          return self::get_messagearea_message_structure();
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_get_most_recent_message_is_deprecated() {
 +        return true;
 +    }
 +
      /**
       * The get profile parameters.
       *
 +     * @deprecated since 3.6
       * @return external_function_parameters
       * @since 3.2
       */
      /**
       * Get the profile information for a contact.
       *
 +     * @deprecated since 3.6
       * @param int $currentuserid The current user's id
       * @param int $otheruserid The id of the user whose profile we are viewing
       * @return stdClass
              'currentuserid' => $currentuserid,
              'otheruserid' => $otheruserid
          );
-         self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params);
+         $params = self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params);
          self::validate_context($systemcontext);
  
-         if (($USER->id != $currentuserid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
-         $profile = \core_message\api::get_profile($currentuserid, $otheruserid);
+         $profile = \core_message\api::get_profile($params['currentuserid'], $params['otheruserid']);
          $profile = new \core_message\output\messagearea\profile($profile);
  
          $renderer = $PAGE->get_renderer('core_message');
      /**
       * The get profile return structure.
       *
 +     * @deprecated since 3.6
       * @return external_single_structure
       * @since 3.2
       */
          );
      }
  
 +    /**
 +     * Marking the method as deprecated.
 +     *
 +     * @return bool
 +     */
 +    public static function data_for_messagearea_get_profile_is_deprecated() {
 +        return true;
 +    }
 +
      /**
       * Get contacts parameters description.
       *
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
-         if (\core_message\api::can_mark_all_messages_as_read($userid, $conversationid)) {
-             \core_message\api::mark_all_messages_as_read($userid, $conversationid);
+         if (\core_message\api::can_mark_all_messages_as_read($params['userid'], $params['conversationid'])) {
+             \core_message\api::mark_all_messages_as_read($params['userid'], $params['conversationid']);
          } else {
              throw new moodle_exception('accessdenied', 'admin');
          }
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
-         if (!$conversationid = \core_message\api::get_conversation_between_users([$userid, $otheruserid])) {
+         if (!$conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']])) {
              return [];
          }
  
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
-         foreach ($conversationids as $conversationid) {
+         foreach ($params['conversationids'] as $conversationid) {
              if (\core_message\api::can_delete_conversation($user->id, $conversationid)) {
                  \core_message\api::delete_conversation_by_id($user->id, $conversationid);
              } else {
          $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
          core_user::require_active_user($user);
  
-         if (\core_message\api::can_delete_message($user->id, $messageid)) {
-             $status = \core_message\api::delete_message($user->id, $messageid);
+         if (\core_message\api::can_delete_message($user->id, $params['messageid'])) {
+             $status = \core_message\api::delete_message($user->id, $params['messageid']);
          } else {
              throw new moodle_exception('You do not have permission to delete this message');
          }
  
          $user = self::validate_preferences_permissions($params['userid']);
  
-         $processor = get_message_processor($name);
+         $processor = get_message_processor($params['name']);
          $preferences = [];
          $form = new stdClass();
  
-         foreach ($formvalues as $formvalue) {
+         foreach ($params['formvalues'] as $formvalue) {
              // Curly braces to ensure interpretation is consistent between
              // php 5 and php 7.
              $form->{$formvalue['name']} = $formvalue['value'];
          $processor->process_form($form, $preferences);
  
          if (!empty($preferences)) {
-             set_user_preferences($preferences, $userid);
+             set_user_preferences($preferences, $params['userid']);
          }
      }
  
          core_user::require_active_user($user);
          self::validate_context(context_user::instance($params['userid']));
  
-         $processor = get_message_processor($name);
+         $processor = get_message_processor($params['name']);
  
          $processoroutput = new \core_message\output\processor($processor, $user);
          $renderer = $PAGE->get_renderer('core_message');
          $systemcontext = context_system::instance();
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }
  
          $systemcontext = context_system::instance();
          self::validate_context($systemcontext);
  
-         if (($USER->id != $userid) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+         if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
              throw new moodle_exception('You do not have permission to perform this action.');
          }