Merge branch 'MDL-69632-master-adminserversettings' of git://github.com/mudrd8mz...
authorSara Arjona <sara@moodle.com>
Mon, 7 Sep 2020 11:43:52 +0000 (13:43 +0200)
committerSara Arjona <sara@moodle.com>
Mon, 7 Sep 2020 11:43:52 +0000 (13:43 +0200)
34 files changed:
admin/tool/dataprivacy/lang/en/deprecated.txt [deleted file]
admin/tool/dataprivacy/lang/en/tool_dataprivacy.php
blocks/myoverview/lang/en/block_myoverview.php
blocks/myoverview/lang/en/deprecated.txt
filter/activitynames/filter.php
filter/activitynames/tests/filter_test.php
lang/en/badges.php
lang/en/deprecated.txt
lang/en/message.php
lang/en/moodle.php
lib/db/services.php
message/amd/build/message_repository.min.js
message/amd/build/message_repository.min.js.map
message/amd/build/toggle_contact_button.min.js
message/amd/build/toggle_contact_button.min.js.map
message/amd/src/message_repository.js
message/amd/src/toggle_contact_button.js
message/classes/api.php
message/classes/helper.php
message/classes/output/messagearea/contact.php [deleted file]
message/classes/output/messagearea/contacts.php [deleted file]
message/classes/output/messagearea/message.php [deleted file]
message/classes/output/messagearea/message_area.php [deleted file]
message/classes/output/messagearea/messages.php [deleted file]
message/classes/output/messagearea/profile.php [deleted file]
message/classes/output/messagearea/user_search_results.php [deleted file]
message/externallib.php
message/lib.php
message/tests/api_test.php
message/tests/events_test.php
message/tests/externallib_test.php
message/tests/messagelib_test.php
message/upgrade.txt
version.php

diff --git a/admin/tool/dataprivacy/lang/en/deprecated.txt b/admin/tool/dataprivacy/lang/en/deprecated.txt
deleted file mode 100644 (file)
index c400ae8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-statuspreprocessing,tool_dataprivacy
index 54d9c5b..46d7af2 100644 (file)
@@ -344,6 +344,3 @@ $string['role_help'] = 'The role which the override should apply to.';
 $string['duplicaterole'] = 'Role already specified';
 $string['purposeoverview'] = 'A purpose describes the intended use and retention policy for stored data. The basis for storing and retaining that data is also described in the purpose.';
 $string['roleoverrideoverview'] = 'The default retention policy can be overridden for specific user roles, allowing you to specify a longer, or a shorter, retention policy. A user is only expired when all of their roles have expired.';
-
-// Deprecated since Moodle 3.6.
-$string['statuspreprocessing'] = 'Pre-processing';
index 9763156..491b555 100644 (file)
@@ -86,24 +86,6 @@ $string['hiddencourses'] = 'Removed from view';
 $string['show'] = 'Restore to view';
 $string['privacy:request:preference:set'] = 'The value of the setting \'{$a->name}\' was \'{$a->value}\'';
 
-// Deprecated since Moodle 3.6.
-$string['defaulttab'] = 'Default tab';
-$string['defaulttab_desc'] = 'The tab that will be displayed when a user first views their course overview. When returning to their course overview, the user\'s active tab is remembered.';
-$string['morecourses'] = 'More courses';
-$string['nocoursesinprogress'] = 'No in progress courses';
-$string['nocoursesfuture'] = 'No future courses';
-$string['nocoursespast'] = 'No past courses';
-$string['noevents'] = 'No upcoming activities due';
-$string['next30days'] = 'Next 30 days';
-$string['next7days'] = 'Next 7 days';
-$string['recentlyoverdue'] = 'Recently overdue';
-$string['sortbycourses'] = 'Sort by courses';
-$string['sortbydates'] = 'Sort by dates';
-$string['timeline'] = 'Timeline';
-$string['viewcoursename'] = 'View course {$a}';
-$string['privacy:metadata:overviewlasttab'] = 'This stores the last tab selected by the user on the overview block.';
-$string['viewcourse'] = 'View course';
-
 // Deprecated since Moodle 3.7.
 $string['complete'] = 'complete';
 $string['nocourses'] = 'No courses';
index fb6f86c..c70ee8b 100644 (file)
@@ -1,17 +1,2 @@
-defaulttab,block_myoverview
-defaulttab_desc,block_myoverview
-morecourses,block_myoverview
-nocoursesinprogress,block_myoverview
-nocoursesfuture,block_myoverview
-nocoursespast,block_myoverview
-noevents,block_myoverview
-next30days,block_myoverview
-next7days,block_myoverview
-recentlyoverdue,block_myoverview
-sortbycourses,block_myoverview
-sortbydates,block_myoverview
-timeline,block_myoverview
-viewcoursename,block_myoverview
-privacy:metadata:overviewlasttab,block_myoverview
 nocourses,block_myoverview
-complete,block_myoverview
\ No newline at end of file
+complete,block_myoverview
index d9ce6f7..d6d3079 100644 (file)
@@ -31,83 +31,24 @@ defined('MOODLE_INTERNAL') || die();
  * Activity name filtering
  */
 class filter_activitynames extends moodle_text_filter {
-    // Trivial-cache - keyed on $cachedcourseid and $cacheduserid.
-    static $activitylist = null;
-    static $cachedcourseid;
-    static $cacheduserid;
 
     function filter($text, array $options = array()) {
-        global $USER; // Since 2.7 we can finally start using globals in filters.
-
         $coursectx = $this->context->get_course_context(false);
         if (!$coursectx) {
             return $text;
         }
         $courseid = $coursectx->instanceid;
 
-        // Initialise/invalidate our trivial cache if dealing with a different course.
-        if (!isset(self::$cachedcourseid) || self::$cachedcourseid !== (int)$courseid) {
-            self::$activitylist = null;
-        }
-        self::$cachedcourseid = (int)$courseid;
-        // And the same for user id.
-        if (!isset(self::$cacheduserid) || self::$cacheduserid !== (int)$USER->id) {
-            self::$activitylist = null;
-        }
-        self::$cacheduserid = (int)$USER->id;
-
-        /// It may be cached
-
-        if (is_null(self::$activitylist)) {
-            self::$activitylist = array();
-
-            $modinfo = get_fast_modinfo($courseid);
-            if (!empty($modinfo->cms)) {
-                self::$activitylist = array(); // We will store all the created filters here.
-
-                // Create array of visible activities sorted by the name length (we are only interested in properties name and url).
-                $sortedactivities = array();
-                foreach ($modinfo->cms as $cm) {
-                    // Use normal access control and visibility, but exclude labels and hidden activities.
-                    if ($cm->visible and $cm->has_view() and $cm->uservisible) {
-                        $sortedactivities[] = (object)array(
-                            'name' => $cm->name,
-                            'url' => $cm->url,
-                            'id' => $cm->id,
-                            'namelen' => -strlen($cm->name), // Negative value for reverse sorting.
-                        );
-                    }
-                }
-                // Sort activities by the length of the activity name in reverse order.
-                core_collator::asort_objects_by_property($sortedactivities, 'namelen', core_collator::SORT_NUMERIC);
-
-                foreach ($sortedactivities as $cm) {
-                    $title = s(trim(strip_tags($cm->name)));
-                    $currentname = trim($cm->name);
-                    $entitisedname  = s($currentname);
-                    // Avoid empty or unlinkable activity names.
-                    if (!empty($title)) {
-                        $href_tag_begin = html_writer::start_tag('a',
-                                array('class' => 'autolink', 'title' => $title,
-                                    'href' => $cm->url));
-                        self::$activitylist[$cm->id] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
-                        if ($currentname != $entitisedname) {
-                            // If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545.
-                            self::$activitylist[$cm->id.'-e'] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
-                        }
-                    }
-                }
-            }
-        }
+        $activitylist = $this->get_cached_activity_list($courseid);
 
         $filterslist = array();
-        if (self::$activitylist) {
+        if (!empty($activitylist)) {
             $cmid = $this->context->instanceid;
-            if ($this->context->contextlevel == CONTEXT_MODULE && isset(self::$activitylist[$cmid])) {
+            if ($this->context->contextlevel == CONTEXT_MODULE && isset($activitylist[$cmid])) {
                 // remove filterobjects for the current module
-                $filterslist = array_values(array_diff_key(self::$activitylist, array($cmid => 1, $cmid.'-e' => 1)));
+                $filterslist = array_values(array_diff_key($activitylist, array($cmid => 1, $cmid.'-e' => 1)));
             } else {
-                $filterslist = array_values(self::$activitylist);
+                $filterslist = array_values($activitylist);
             }
         }
 
@@ -117,4 +58,76 @@ class filter_activitynames extends moodle_text_filter {
             return $text;
         }
     }
+
+    /**
+     * Get all the cached activity list for a course
+     *
+     * @param int $courseid id of the course
+     * @return filterobject[] the activities
+     */
+    protected function get_cached_activity_list($courseid) {
+        global $USER;
+        $cached = cache::make_from_params(cache_store::MODE_REQUEST, 'filter', 'activitynames');
+
+        // Return cached activity list.
+        if ($cached->get('cachecourseid') == $courseid && $cached->get('cacheuserid') == $USER->id) {
+            return $cached->get('activitylist');
+        }
+
+        // Not cached yet, get activity list and set cache.
+        $activitylist = $this->get_activity_list($courseid);
+        $cached->set('cacheuserid', $USER->id);
+        $cached->set('cachecourseid', $courseid);
+        $cached->set('activitylist', $activitylist);
+        return $activitylist;
+    }
+
+    /**
+     * Get all the activity list for a course
+     *
+     * @param int $courseid id of the course
+     * @return filterobject[] the activities
+     */
+    protected function get_activity_list($courseid) {
+        $activitylist = array();
+
+        $modinfo = get_fast_modinfo($courseid);
+        if (!empty($modinfo->cms)) {
+            $activitylist = array(); // We will store all the created filters here.
+
+            // Create array of visible activities sorted by the name length (we are only interested in properties name and url).
+            $sortedactivities = array();
+            foreach ($modinfo->cms as $cm) {
+                // Use normal access control and visibility, but exclude labels and hidden activities.
+                if ($cm->visible and $cm->has_view() and $cm->uservisible) {
+                    $sortedactivities[] = (object)array(
+                        'name' => $cm->name,
+                        'url' => $cm->url,
+                        'id' => $cm->id,
+                        'namelen' => -strlen($cm->name), // Negative value for reverse sorting.
+                    );
+                }
+            }
+            // Sort activities by the length of the activity name in reverse order.
+            core_collator::asort_objects_by_property($sortedactivities, 'namelen', core_collator::SORT_NUMERIC);
+
+            foreach ($sortedactivities as $cm) {
+                $title = s(trim(strip_tags($cm->name)));
+                $currentname = trim($cm->name);
+                $entitisedname  = s($currentname);
+                // Avoid empty or unlinkable activity names.
+                if (!empty($title)) {
+                    $hreftagbegin = html_writer::start_tag('a',
+                        array('class' => 'autolink', 'title' => $title,
+                            'href' => $cm->url));
+                    $activitylist[$cm->id] = new filterobject($currentname, $hreftagbegin, '</a>', false, true);
+                    if ($currentname != $entitisedname) {
+                        // If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545.
+                        $activitylist[$cm->id.'-e'] = new filterobject($entitisedname, $hreftagbegin, '</a>', false, true);
+                    }
+                }
+            }
+        }
+        return $activitylist;
+    }
 }
index b21c924..98776b7 100644 (file)
@@ -102,4 +102,56 @@ class filter_activitynames_filter_testcase extends advanced_testcase {
         $this->assertEquals($page->cmid, $matches[2][0]);
         $this->assertEquals($page->name, $matches[3][0]);
     }
+
+    public function test_cache() {
+        $this->resetAfterTest(true);
+
+        // Create a test courses.
+        $course1 = $this->getDataGenerator()->create_course();
+        $course2 = $this->getDataGenerator()->create_course();
+        $context1 = context_course::instance($course1->id);
+        $context2 = context_course::instance($course2->id);
+
+        // Create page 1.
+        $page1 = $this->getDataGenerator()->create_module('page',
+            ['course' => $course1->id, 'name' => 'Test 1']);
+        // Format text with page 1 in HTML.
+        $html = '<p>Please read the two pages Test 1 and Test 2.</p>';
+        $filtered1 = format_text($html, FORMAT_HTML, array('context' => $context1));
+        // Find all the activity links in the result.
+        $matches = [];
+        preg_match_all('~<a class="autolink" title="([^"]*)" href="[^"]*/mod/page/view.php\?id=([0-9]+)">([^<]*)</a>~',
+            $filtered1, $matches);
+        // There should be 1 link.
+        $this->assertCount(1, $matches[1]);
+        $this->assertEquals($page1->name, $matches[1][0]);
+
+        // Create page 2.
+        $page2 = $this->getDataGenerator()->create_module('page',
+        ['course' => $course1->id, 'name' => 'Test 2']);
+        // Filter the text again.
+        $filtered2 = format_text($html, FORMAT_HTML, array('context' => $context1));
+        // The filter result does not change due to caching.
+        $this->assertEquals($filtered1, $filtered2);
+
+        // Change context, so that cache for course 1 is cleared.
+        $filtered3 = format_text($html, FORMAT_HTML, array('context' => $context2));
+        $this->assertNotEquals($filtered1, $filtered3);
+        $matches = [];
+        preg_match_all('~<a class="autolink" title="([^"]*)" href="[^"]*/mod/page/view.php\?id=([0-9]+)">([^<]*)</a>~',
+            $filtered3, $matches);
+        // There should be no links.
+        $this->assertCount(0, $matches[1]);
+
+        // Filter the text for course 1.
+        $filtered4 = format_text($html, FORMAT_HTML, array('context' => $context1));
+        // Find all the activity links in the result.
+        $matches = [];
+        preg_match_all('~<a class="autolink" title="([^"]*)" href="[^"]*/mod/page/view.php\?id=([0-9]+)">([^<]*)</a>~',
+            $filtered4, $matches);
+        // There should be 2 links.
+        $this->assertCount(2, $matches[1]);
+        $this->assertEquals($page1->name, $matches[1][0]);
+        $this->assertEquals($page2->name, $matches[1][1]);
+    }
 }
index 62e4b4f..a98db31 100644 (file)
@@ -572,13 +572,6 @@ $string['version_help'] = 'The version field may be used to keep track of the ba
 $string['warnexpired'] = ' (This badge has expired!)';
 $string['year'] = 'Year(s)';
 
-// Deprecated since Moodle 3.6.
-$string['error:invalidbadgeurl'] = 'Invalid issuer URL format. The URL should have a prefix http:// or https://.';
-$string['backpackbadges'] = 'You have {$a->totalbadges} badge(s) displayed from {$a->totalcollections} collection(s). <a href="mybackpack.php">Change backpack settings</a>.';
-$string['error:nogroups'] = '<p>There are no public collections of badges available in your backpack. </p> <p>Only public collections are shown. <a href="https://backpack.openbadges.org">Visit your backpack</a> to create some public collections.</p>';
-$string['nobackpackbadges'] = 'There are no badges in the collections you have selected. <a href="mybackpack.php">Add more collections</a>.';
-$string['nobackpackcollections'] = 'No badge collections have been selected. <a href="mybackpack.php">Add collections</a>.';
-
 // Deprecated since Moodle 3.9.
 $string['editsettings'] = 'Edit settings';
 $string['sitebackpackverify'] = 'Backpack connection';
index 949af22..f5887d5 100644 (file)
@@ -5,28 +5,8 @@ myfilesmanage,core
 mypreferences,core_grades
 myprofile,core
 viewallmyentries,core_blog
-formattexttype,core
-currentlyselectedusers,core
-emailuserhasnone,core
-emaildisplayhidden,core
-sitemessage,core
-coursemessage,core
-addedrecip,core
-addedrecips,core
 messagecontactrequestsnotification,core_message
 messagecontactrequestsnotificationsubject,core_message
-messagingdisabled,core_message
-messagedselectedcountusersfailed,core
-backtoparticipants,core
-keepsearching,core
-allfieldsrequired,core
-previewhtml,core
-messagedselecteduserfailed,core
-eventmessagecontactblocked,core_message
-eventmessagecontactunblocked,core_message
-userisblockingyou,core_message
-userisblockingyounoncontact,core_message
-error:invalidbadgeurl,core_badges
 nomessages,core_message
 searchallavailablecourses_desc,core_admin
 search:mycourse,core_search
@@ -41,10 +21,6 @@ undockall,core_block
 undockblock,core_block
 undockitem,core_block
 canceledit,core_message
-backpackbadges,core_badges
-nobackpackbadges,core_badges
-nobackpackcollections,core_badges
-error:nogroups,core_badges
 purgedefinitionsuccess,core_cache
 purgestoresuccess,core_cache
 eventrolecapabilitiesupdated,core_role
index 61ed582..77a5b18 100644 (file)
@@ -262,8 +262,6 @@ $string['unreadnewgroupconversationmessage'] = 'New message from {$a->name} in {
 $string['unreadnewmessage'] = 'New message from {$a}';
 $string['useentertosend'] = 'Use enter to send';
 $string['usercantbemessaged'] = 'You can\'t message {$a} due to their message preferences. Try adding them as a contact.';
-$string['userisblockingyou'] = 'This user has blocked you from sending messages to them';
-$string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.';
 $string['userwouldliketocontactyou'] = '{$a} would like to contact you';
 $string['viewfullnotification'] = 'View full notification';
 $string['viewmessageswith'] = 'View messages with {$a}';
@@ -275,13 +273,6 @@ $string['you'] = 'You:';
 $string['youhaveblockeduser'] = 'You have blocked this user.';
 $string['yourcontactrequestpending'] = 'Your contact request is pending with {$a}';
 
-// Deprecated since Moodle 3.6.
-$string['eventmessagecontactblocked'] = 'Message contact blocked';
-$string['eventmessagecontactunblocked'] = 'Message contact unblocked';
-$string['messagingdisabled'] = 'Messaging is disabled on this site, emails will be sent instead';
-$string['userisblockingyou'] = 'This user has blocked you from sending messages to them.';
-$string['userisblockingyounoncontact'] = '{$a} only accepts messages from their contacts.';
-
 // Deprecated since Moodle 3.7.
 $string['nomessages'] = 'No messages';
 $string['outputdisabled'] = 'Output disabled';
index 9d7065e..2d8bd72 100644 (file)
@@ -2283,22 +2283,6 @@ $string['yourwordforx'] = 'Your word for \'{$a}\'';
 $string['zippingbackup'] = 'Zipping backup';
 $string['deprecatedeventname'] = '{$a} (no longer in use)';
 
-// Deprecated since Moodle 3.6.
-$string['addedrecip'] = 'Added {$a} new recipient';
-$string['addedrecips'] = 'Added {$a} new recipients';
-$string['allfieldsrequired'] = 'All fields are required';
-$string['backtoparticipants'] = 'Back to participants list';
-$string['currentlyselectedusers'] = 'Currently selected users';
-$string['coursemessage'] = 'Message course users';
-$string['emaildisplayhidden'] = 'Email hidden';
-$string['emailuserhasnone'] = 'There is no email address for the user.';
-$string['formattexttype'] = 'Formatting';
-$string['keepsearching'] = 'Keep searching';
-$string['messagedselectedcountusersfailed'] = 'A problem occurred and {$a} messages have not been sent.';
-$string['messagedselecteduserfailed'] = 'The message was not sent to user {$a->fullname}.';
-$string['previewhtml'] = 'HTML format preview';
-$string['sitemessage'] = 'Message users';
-
 // Deprecated since Moodle 3.9.
 $string['participantscount'] = 'Number of participants: {$a}';
 $string['userfilterplaceholder'] = 'Search keyword or select filter';
index abc93f6..94f0c0d 100644 (file)
@@ -1104,26 +1104,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_block_contacts' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'block_contacts',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Block contacts',
-        'type' => 'write',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
-    'core_message_create_contacts' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'create_contacts',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Add contacts to the contact list',
-        'type' => 'write',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
     'core_message_get_contact_requests' => array(
         'classname' => 'core_message_external',
         'methodname' => 'get_contact_requests',
@@ -1178,17 +1158,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_delete_conversation' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'delete_conversation',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Deletes a conversation.',
-        'type' => 'write',
-        'capabilities' => 'moodle/site:deleteownmessage',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
     'core_message_delete_conversations_by_id' => array(
         'classname' => 'core_message_external',
         'methodname' => 'delete_conversations_by_id',
@@ -1226,24 +1195,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_data_for_messagearea_search_users' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_search_users',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for searching for people',
-        'type' => 'read',
-        'ajax' => true,
-    ),
-    'core_message_data_for_messagearea_search_users_in_course' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_search_users_in_course',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for searching for people in a course',
-        'type' => 'read',
-        'ajax' => true,
-    ),
     'core_message_message_search_users' => array(
         'classname' => 'core_message_external',
         'methodname' => 'message_search_users',
@@ -1253,63 +1204,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_data_for_messagearea_conversations' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_conversations',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for the conversation list',
-        'type' => 'read',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
-    'core_message_data_for_messagearea_contacts' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_contacts',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for the contact list',
-        'type' => 'read',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
-    'core_message_data_for_messagearea_messages' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_messages',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for the messages',
-        'type' => 'read',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
-    'core_message_data_for_messagearea_get_most_recent_message' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_get_most_recent_message',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for the most recent message',
-        'type' => 'read',
-        'ajax' => true,
-    ),
-    'core_message_data_for_messagearea_get_profile' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'data_for_messagearea_get_profile',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the template data for the users\'s profile',
-        'type' => 'read',
-        'ajax' => true,
-    ),
-    'core_message_get_contacts' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'get_contacts',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Retrieve the contact list',
-        'type' => 'read',
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
     'core_message_get_user_contacts' => array(
         'classname' => 'core_message_external',
         'methodname' => 'get_user_contacts',
@@ -1419,16 +1313,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_mark_all_messages_as_read' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'mark_all_messages_as_read',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                          Mark all messages as read for a given user',
-        'type' => 'write',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
     'core_message_mark_all_conversation_messages_as_read' => array(
         'classname' => 'core_message_external',
         'methodname' => 'mark_all_conversation_messages_as_read',
@@ -1519,16 +1403,6 @@ $functions = array(
         'ajax' => true,
         'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
     ),
-    'core_message_unblock_contacts' => array(
-        'classname' => 'core_message_external',
-        'methodname' => 'unblock_contacts',
-        'classpath' => 'message/externallib.php',
-        'description' => '** DEPRECATED ** Please do not call this function any more.
-                         Unblock contacts',
-        'type' => 'write',
-        'ajax' => true,
-        'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
-    ),
     'core_message_get_user_notification_preferences' => array(
         'classname' => 'core_message_external',
         'methodname' => 'get_user_notification_preferences',
index 12a1412..62651a7 100644 (file)
Binary files a/message/amd/build/message_repository.min.js and b/message/amd/build/message_repository.min.js differ
index f2f9710..053d670 100644 (file)
Binary files a/message/amd/build/message_repository.min.js.map and b/message/amd/build/message_repository.min.js.map differ
index ebfd3cd..1294576 100644 (file)
Binary files a/message/amd/build/toggle_contact_button.min.js and b/message/amd/build/toggle_contact_button.min.js differ
index 0466155..6f2d7ef 100644 (file)
Binary files a/message/amd/build/toggle_contact_button.min.js.map and b/message/amd/build/toggle_contact_button.min.js.map differ
index 56b5925..d034a70 100644 (file)
@@ -36,48 +36,6 @@ define(
 
     var CONVERSATION_TYPES = Constants.CONVERSATION_TYPES;
 
-    /**
-     * Retrieve a list of messages from the server.
-     *
-     * @param {object} args The request arguments:
-     * @return {object} jQuery promise
-     */
-    var query = function(args) {
-        // Normalise the arguments to use limit/offset rather than limitnum/limitfrom.
-        if (typeof args.limit === 'undefined') {
-            args.limit = 0;
-        }
-
-        if (typeof args.offset === 'undefined') {
-            args.offset = 0;
-        }
-
-        if (typeof args.type === 'undefined') {
-            args.type = null;
-        }
-
-        if (typeof args.favouritesonly === 'undefined') {
-            args.favouritesonly = false;
-        }
-
-        args.limitfrom = args.offset;
-        args.limitnum = args.limit;
-
-        delete args.limit;
-        delete args.offset;
-
-        var request = {
-            methodname: 'core_message_data_for_messagearea_conversations',
-            args: args
-        };
-
-        var promise = Ajax.call([request])[0];
-
-        promise.fail(Notification.exception);
-
-        return promise;
-    };
-
     /**
      * Count the number of unread conversations (one or more messages from a user)
      * for a given user.
@@ -98,25 +56,6 @@ define(
         return promise;
     };
 
-    /**
-     * Mark all of unread messages for a user as read.
-     *
-     * @param {object} args The request arguments:
-     * @return {object} jQuery promise
-     */
-    var markAllAsRead = function(args) {
-        var request = {
-            methodname: 'core_message_mark_all_messages_as_read',
-            args: args
-        };
-
-        var promise = Ajax.call([request])[0];
-
-        promise.fail(Notification.exception);
-
-        return promise;
-    };
-
     /**
      * Get contacts for given user.
      *
@@ -146,25 +85,6 @@ define(
         return Ajax.call([request])[0];
     };
 
-    /**
-     * Request profile information as a user for a given user.
-     *
-     * @param {int} userId The requesting user
-     * @param {int} profileUserId The id of the user who's profile is being requested
-     * @return {object} jQuery promise
-     */
-    var getProfile = function(userId, profileUserId) {
-        var request = {
-            methodname: 'core_message_data_for_messagearea_get_profile',
-            args: {
-                currentuserid: userId,
-                otheruserid: profileUserId
-            }
-        };
-
-        return Ajax.call([request])[0];
-    };
-
     /**
      * Block a user.
      *
@@ -1139,11 +1059,8 @@ define(
     };
 
     return {
-        query: query,
         countUnreadConversations: countUnreadConversations,
-        markAllAsRead: markAllAsRead,
         getContacts: getContacts,
-        getProfile: getProfile,
         blockUser: blockUser,
         unblockUser: unblockUser,
         createContactRequest: createContactRequest,
index aa22a42..bf5349f 100644 (file)
@@ -67,6 +67,17 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
         return element.attr('data-userid');
     };
 
+    /**
+     * Get the id for the logged in user.
+     *
+     * @method getUserId
+     * @param {object} element jQuery object for the button
+     * @return {int}
+     */
+    var getCurrentUserId = function(element) {
+        return element.attr('data-currentuserid');
+    };
+
     /**
      * Check if this element is currently loading.
      *
@@ -117,9 +128,10 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
         }
 
         var request = {
-            methodname: 'core_message_create_contacts',
+            methodname: 'core_message_create_contact_request',
             args: {
-                userids: [getUserId(element)],
+                userid: getCurrentUserId(element),
+                requesteduserid: getUserId(element),
             }
         };
         sendRequest(element, request).done(function() {
index 86708bc..4d758b1 100644 (file)
@@ -167,138 +167,17 @@ class api {
     }
 
     /**
-     * Handles searching for user in a particular course in the message area.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_search_users_in_course.
-     * Followup: MDL-63261
-     *
-     * @param int $userid The user id doing the searching
-     * @param int $courseid The id of the course we are searching in
-     * @param string $search The string the user is searching
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @return array
+     * @deprecated since 3.6
      */
-    public static function search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) {
-        global $DB;
-
-        // Get all the users in the course.
-        list($esql, $params) = get_enrolled_sql(\context_course::instance($courseid), '', 0, true);
-        $sql = "SELECT u.*, mub.id as isblocked
-                  FROM {user} u
-                  JOIN ($esql) je
-                    ON je.id = u.id
-             LEFT JOIN {message_users_blocked} mub
-                    ON (mub.blockeduserid = u.id AND mub.userid = :userid)
-                 WHERE u.deleted = 0";
-        // Add more conditions.
-        $fullname = $DB->sql_fullname();
-        $sql .= " AND u.id != :userid2
-                  AND " . $DB->sql_like($fullname, ':search', false) . "
-             ORDER BY " . $DB->sql_fullname();
-        $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params);
-
-        // Convert all the user records into contacts.
-        $contacts = array();
-        if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) {
-            foreach ($users as $user) {
-                $user->blocked = $user->isblocked ? 1 : 0;
-                $contacts[] = helper::create_contact($user);
-            }
-        }
-
-        return $contacts;
+    public static function search_users_in_course() {
+        throw new \coding_exception('\core_message\api::search_users_in_course has been removed.');
     }
 
     /**
-     * Handles searching for user in the message area.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_search_users.
-     * Followup: MDL-63261
-     *
-     * @param int $userid The user id doing the searching
-     * @param string $search The string the user is searching
-     * @param int $limitnum
-     * @return array
+     * @deprecated since 3.6
      */
-    public static function search_users($userid, $search, $limitnum = 0) {
-        global $CFG, $DB;
-
-        // Used to search for contacts.
-        $fullname = $DB->sql_fullname();
-        $ufields = \user_picture::fields('u', array('lastaccess'));
-
-        // Users not to include.
-        $excludeusers = array($userid, $CFG->siteguest);
-        list($exclude, $excludeparams) = $DB->get_in_or_equal($excludeusers, SQL_PARAMS_NAMED, 'param', false);
-
-        // Ok, let's search for contacts first.
-        $contacts = array();
-        $sql = "SELECT $ufields, mub.id as isuserblocked
-                  FROM {user} u
-                  JOIN {message_contacts} mc
-                    ON u.id = mc.contactid
-             LEFT JOIN {message_users_blocked} mub
-                    ON (mub.userid = :userid2 AND mub.blockeduserid = u.id)
-                 WHERE mc.userid = :userid
-                   AND u.deleted = 0
-                   AND u.confirmed = 1
-                   AND " . $DB->sql_like($fullname, ':search', false) . "
-                   AND u.id $exclude
-              ORDER BY " . $DB->sql_fullname();
-        if ($users = $DB->get_records_sql($sql, array('userid' => $userid, 'userid2' => $userid,
-                'search' => '%' . $search . '%') + $excludeparams, 0, $limitnum)) {
-            foreach ($users as $user) {
-                $user->blocked = $user->isuserblocked ? 1 : 0;
-                $contacts[] = helper::create_contact($user);
-            }
-        }
-
-        // Now, let's get the courses.
-        // Make sure to limit searches to enrolled courses.
-        $enrolledcourses = enrol_get_my_courses(array('id', 'cacherev'));
-        $courses = array();
-        // Really we want the user to be able to view the participants if they have the capability
-        // 'moodle/course:viewparticipants' or 'moodle/course:enrolreview', but since the search_courses function
-        // only takes required parameters we can't. However, the chance of a user having 'moodle/course:enrolreview' but
-        // *not* 'moodle/course:viewparticipants' are pretty much zero, so it is not worth addressing.
-        if ($arrcourses = \core_course_category::search_courses(array('search' => $search), array('limit' => $limitnum),
-                array('moodle/course:viewparticipants'))) {
-            foreach ($arrcourses as $course) {
-                if (isset($enrolledcourses[$course->id])) {
-                    $data = new \stdClass();
-                    $data->id = $course->id;
-                    $data->shortname = $course->shortname;
-                    $data->fullname = $course->fullname;
-                    $courses[] = $data;
-                }
-            }
-        }
-
-        // Let's get those non-contacts. Toast them gears boi.
-        // Note - you can only block contacts, so these users will not be blocked, so no need to get that
-        // extra detail from the database.
-        $noncontacts = array();
-        $sql = "SELECT $ufields
-                  FROM {user} u
-                 WHERE u.deleted = 0
-                   AND u.confirmed = 1
-                   AND " . $DB->sql_like($fullname, ':search', false) . "
-                   AND u.id $exclude
-                   AND u.id NOT IN (SELECT contactid
-                                      FROM {message_contacts}
-                                     WHERE userid = :userid)
-              ORDER BY " . $DB->sql_fullname();
-        if ($users = $DB->get_records_sql($sql,  array('userid' => $userid, 'search' => '%' . $search . '%') + $excludeparams,
-                0, $limitnum)) {
-            foreach ($users as $user) {
-                $noncontacts[] = helper::create_contact($user);
-            }
-        }
-
-        return array($contacts, $courses, $noncontacts);
+    public static function search_users() {
+        throw new \coding_exception('\core_message\api::search_users has been removed.');
     }
 
     /**
@@ -1070,55 +949,10 @@ class api {
     }
 
     /**
-     * Returns the contacts to display in the contacts area.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_contacts.
-     * Followup: MDL-63261
-     *
-     * @param int $userid The user id
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @return array
+     * @deprecated since 3.6
      */
-    public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) {
-        global $DB;
-
-        $contactids = [];
-        $sql = "SELECT mc.*
-                  FROM {message_contacts} mc
-                 WHERE mc.userid = ? OR mc.contactid = ?
-              ORDER BY timecreated DESC";
-        if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) {
-            foreach ($contacts as $contact) {
-                if ($userid == $contact->userid) {
-                    $contactids[] = $contact->contactid;
-                } else {
-                    $contactids[] = $contact->userid;
-                }
-            }
-        }
-
-        if (!empty($contactids)) {
-            list($insql, $inparams) = $DB->get_in_or_equal($contactids);
-
-            $sql = "SELECT u.*, mub.id as isblocked
-                      FROM {user} u
-                 LEFT JOIN {message_users_blocked} mub
-                        ON u.id = mub.blockeduserid
-                     WHERE u.id $insql";
-            if ($contacts = $DB->get_records_sql($sql, $inparams)) {
-                $arrcontacts = [];
-                foreach ($contacts as $contact) {
-                    $contact->blocked = $contact->isblocked ? 1 : 0;
-                    $arrcontacts[] = helper::create_contact($contact);
-                }
-
-                return $arrcontacts;
-            }
-        }
-
-        return [];
+    public static function get_contacts() {
+        throw new \coding_exception('\core_message\api::get_contacts has been removed.');
     }
 
     /**
@@ -1170,6 +1004,8 @@ class api {
      * Returns the an array of the users the given user is in a conversation
      * with who are a contact and the number of unread messages.
      *
+     * @deprecated since 3.10
+     * TODO: MDL-69643
      * @param int $userid The user id
      * @param int $limitfrom
      * @param int $limitnum
@@ -1178,6 +1014,9 @@ class api {
     public static function get_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) {
         global $DB;
 
+        debugging('\core_message\api::get_contacts_with_unread_message_count is deprecated and no longer used',
+            DEBUG_DEVELOPER);
+
         $userfields = \user_picture::fields('u', array('lastaccess'));
         $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount
                               FROM {message_contacts} mc
@@ -1206,6 +1045,8 @@ class api {
      * Returns the an array of the users the given user is in a conversation
      * with who are not a contact and the number of unread messages.
      *
+     * @deprecated since 3.10
+     * TODO: MDL-69643
      * @param int $userid The user id
      * @param int $limitfrom
      * @param int $limitnum
@@ -1214,6 +1055,9 @@ class api {
     public static function get_non_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) {
         global $DB;
 
+        debugging('\core_message\api::get_non_contacts_with_unread_message_count is deprecated and no longer used',
+            DEBUG_DEVELOPER);
+
         $userfields = \user_picture::fields('u', array('lastaccess'));
         $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount
                               FROM {user} u
@@ -1240,52 +1084,10 @@ class api {
     }
 
     /**
-     * Returns the messages to display in the message area.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_messages.
-     * Followup: MDL-63261
-     *
-     * @param int $userid the current user
-     * @param int $otheruserid the other user
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @param string $sort
-     * @param int $timefrom the time from the message being sent
-     * @param int $timeto the time up until the message being sent
-     * @return array
+     * @deprecated since 3.6
      */
-    public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0,
-            $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
-
-        if (!empty($timefrom)) {
-            // Get the conversation between userid and otheruserid.
-            $userids = [$userid, $otheruserid];
-            if (!$conversationid = self::get_conversation_between_users($userids)) {
-                // This method was always used for individual conversations.
-                $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids);
-                $conversationid = $conversation->id;
-            }
-
-            // Check the cache to see if we even need to do a DB query.
-            $cache = \cache::make('core', 'message_time_last_message_between_users');
-            $key = helper::get_last_message_time_created_cache_key($conversationid);
-            $lastcreated = $cache->get($key);
-
-            // The last known message time is earlier than the one being requested so we can
-            // just return an empty result set rather than having to query the DB.
-            if ($lastcreated && $lastcreated < $timefrom) {
-                return [];
-            }
-        }
-
-        $arrmessages = array();
-        if ($messages = helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum,
-                                             $sort, $timefrom, $timeto)) {
-            $arrmessages = helper::create_messages($userid, $messages);
-        }
-
-        return $arrmessages;
+    public static function get_messages() {
+        throw new \coding_exception('\core_message\api::get_messages has been removed.');
     }
 
     /**
@@ -1321,26 +1123,10 @@ class api {
     }
 
     /**
-     * Returns the most recent message between two users.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_get_most_recent_message.
-     * Followup: MDL-63261
-     *
-     * @param int $userid the current user
-     * @param int $otheruserid the other user
-     * @return \stdClass|null
+     * @deprecated since 3.6
      */
-    public static function get_most_recent_message($userid, $otheruserid) {
-        // We want two messages here so we get an accurate 'blocktime' value.
-        if ($messages = helper::get_messages($userid, $otheruserid, 0, 0, 2, 'timecreated DESC')) {
-            // Swap the order so we now have them in historical order.
-            $messages = array_reverse($messages);
-            $arrmessages = helper::create_messages($userid, $messages);
-            return array_pop($arrmessages);
-        }
-
-        return null;
+    public static function get_most_recent_message() {
+        throw new \coding_exception('\core_message\api::get_most_recent_message has been removed.');
     }
 
     /**
@@ -1366,58 +1152,10 @@ class api {
     }
 
     /**
-     * Returns the profile information for a contact for a user.
-     *
-     * TODO: This function should be removed once the related web service goes through final deprecation.
-     * The related web service is data_for_messagearea_get_profile.
-     * Followup: MDL-63261
-     *
-     * @param int $userid The user id
-     * @param int $otheruserid The id of the user whose profile we want to view.
-     * @return \stdClass
+     * @deprecated since 3.6
      */
-    public static function get_profile($userid, $otheruserid) {
-        global $CFG, $PAGE;
-
-        require_once($CFG->dirroot . '/user/lib.php');
-
-        $user = \core_user::get_user($otheruserid, '*', MUST_EXIST);
-
-        // Create the data we are going to pass to the renderable.
-        $data = new \stdClass();
-        $data->userid = $otheruserid;
-        $data->fullname = fullname($user);
-        $data->city = '';
-        $data->country = '';
-        $data->email = '';
-        $data->isonline = null;
-        // Get the user picture data - messaging has always shown these to the user.
-        $userpicture = new \user_picture($user);
-        $userpicture->size = 1; // Size f1.
-        $data->profileimageurl = $userpicture->get_url($PAGE)->out(false);
-        $userpicture->size = 0; // Size f2.
-        $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
-
-        $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess'));
-        if ($userfields) {
-            if (isset($userfields['city'])) {
-                $data->city = $userfields['city'];
-            }
-            if (isset($userfields['country'])) {
-                $data->country = $userfields['country'];
-            }
-            if (isset($userfields['email'])) {
-                $data->email = $userfields['email'];
-            }
-            if (isset($userfields['lastaccess'])) {
-                $data->isonline = helper::is_online($userfields['lastaccess']);
-            }
-        }
-
-        $data->isblocked = self::is_blocked($userid, $otheruserid);
-        $data->iscontact = self::is_contact($userid, $otheruserid);
-
-        return $data;
+    public static function get_profile() {
+        throw new \coding_exception('\core_message\api::get_profile has been removed.');
     }
 
     /**
@@ -1456,30 +1194,11 @@ class api {
     }
 
     /**
-     * Deletes a conversation.
-     *
-     * This function does not verify any permissions.
-     *
      * @deprecated since 3.6
-     * @param int $userid The user id of who we want to delete the messages for (this may be done by the admin
-     *  but will still seem as if it was by the user)
-     * @param int $otheruserid The id of the other user in the conversation
-     * @return bool
      */
-    public static function delete_conversation($userid, $otheruserid) {
-        debugging('\core_message\api::delete_conversation() is deprecated, please use ' .
-            '\core_message\api::delete_conversation_by_id() instead.', DEBUG_DEVELOPER);
-
-        $conversationid = self::get_conversation_between_users([$userid, $otheruserid]);
-
-        // If there is no conversation, there is nothing to do.
-        if (!$conversationid) {
-            return true;
-        }
-
-        self::delete_conversation_by_id($userid, $conversationid);
-
-        return true;
+    public static function delete_conversation() {
+        throw new \coding_exception('\core_message\api::delete_conversation() is deprecated, please use ' .
+            '\core_message\api::delete_conversation_by_id() instead.');
     }
 
     /**
@@ -2028,80 +1747,17 @@ class api {
     }
 
     /**
-     * Checks if the recipient is allowing messages from users that aren't a
-     * contact. If not then it checks to make sure the sender is in the
-     * recipient's contacts.
-     *
      * @deprecated since 3.6
-     * @param \stdClass $recipient The user object.
-     * @param \stdClass|null $sender The user object.
-     * @return bool true if $sender is blocked, false otherwise.
      */
-    public static function is_user_non_contact_blocked($recipient, $sender = null) {
-        debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER);
-
-        global $USER, $CFG;
-
-        if (is_null($sender)) {
-            // The message is from the logged in user, unless otherwise specified.
-            $sender = $USER;
-        }
-
-        $privacypreference = self::get_user_privacy_messaging_preference($recipient->id);
-        switch ($privacypreference) {
-            case self::MESSAGE_PRIVACY_SITE:
-                if (!empty($CFG->messagingallusers)) {
-                    // Users can be messaged without being contacts or members of the same course.
-                    break;
-                }
-                // When the $CFG->messagingallusers privacy setting is disabled, continue with the next
-                // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER.
-            case self::MESSAGE_PRIVACY_COURSEMEMBER:
-                // Confirm the sender and the recipient are both members of the same course.
-                if (enrol_sharing_course($recipient, $sender)) {
-                    // All good, the recipient and the sender are members of the same course.
-                    return false;
-                }
-            case self::MESSAGE_PRIVACY_ONLYCONTACTS:
-                // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise.
-                return !self::is_contact($sender->id, $recipient->id);
-        }
-
-        return false;
+    public static function is_user_non_contact_blocked() {
+        throw new \coding_exception('\core_message\api::is_user_non_contact_blocked() is deprecated');
     }
 
     /**
-     * Checks if the recipient has specifically blocked the sending user.
-     *
-     * Note: This function will always return false if the sender has the
-     * readallmessages capability at the system context level.
-     *
      * @deprecated since 3.6
-     * @param int $recipientid User ID of the recipient.
-     * @param int $senderid User ID of the sender.
-     * @return bool true if $sender is blocked, false otherwise.
      */
-    public static function is_user_blocked($recipientid, $senderid = null) {
-        debugging('\core_message\api::is_user_blocked is deprecated and should not be used.',
-            DEBUG_DEVELOPER);
-
-        global $USER;
-
-        if (is_null($senderid)) {
-            // The message is from the logged in user, unless otherwise specified.
-            $senderid = $USER->id;
-        }
-
-        $systemcontext = \context_system::instance();
-        if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) {
-            return false;
-        }
-
-        if (self::is_blocked($recipientid, $senderid)) {
-            return true;
-        }
-
-        return false;
+    public static function is_user_blocked() {
+        throw new \coding_exception('\core_message\api::is_user_blocked is deprecated and should not be used.');
     }
 
     /**
@@ -2465,20 +2121,11 @@ class api {
     }
 
     /**
-     * Creates a conversation between two users.
-     *
      * @deprecated since 3.6
-     * @param array $userids
-     * @return int The id of the conversation
      */
-    public static function create_conversation_between_users(array $userids) {
-        debugging('\core_message\api::create_conversation_between_users is deprecated, please use ' .
-            '\core_message\api::create_conversation instead.', DEBUG_DEVELOPER);
-
-        // This method was always used for individual conversations.
-        $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids);
-
-        return $conversation->id;
+    public static function create_conversation_between_users() {
+        throw new \coding_exception('\core_message\api::create_conversation_between_users is deprecated, please use ' .
+            '\core_message\api::create_conversation instead.');
     }
 
     /**
index c6472a4..286b36c 100644 (file)
@@ -37,82 +37,10 @@ require_once($CFG->dirroot . '/message/lib.php');
 class helper {
 
     /**
-     * Helper function to retrieve the messages between two users
-     *
-     * TODO: This function should be removed once the related web services go through final deprecation.
-     * The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message.
-     * Followup: MDL-63261
-     *
-     * @param int $userid the current user
-     * @param int $otheruserid the other user
-     * @param int $timedeleted the time the message was deleted
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @param string $sort
-     * @param int $timefrom the time from the message being sent
-     * @param int $timeto the time up until the message being sent
-     * @return array of messages
+     * @deprecated since 3.6
      */
-    public static function get_messages($userid, $otheruserid, $timedeleted = 0, $limitfrom = 0, $limitnum = 0,
-                                        $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
-        global $DB;
-
-        $hash = self::get_conversation_hash([$userid, $otheruserid]);
-
-        $sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
-                       m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
-                       mc.contextid, muaread.timecreated AS timeread
-                  FROM {message_conversations} mc
-            INNER JOIN {messages} m
-                    ON m.conversationid = mc.id
-             LEFT JOIN {message_user_actions} muaread
-                    ON (muaread.messageid = m.id
-                   AND muaread.userid = :userid1
-                   AND muaread.action = :readaction)";
-        $params = ['userid1' => $userid, 'readaction' => api::MESSAGE_ACTION_READ, 'convhash' => $hash];
-
-        if (empty($timedeleted)) {
-            $sql .= " LEFT JOIN {message_user_actions} mua
-                             ON (mua.messageid = m.id
-                            AND mua.userid = :userid2
-                            AND mua.action = :deleteaction
-                            AND mua.timecreated is NOT NULL)";
-        } else {
-            $sql .= " INNER JOIN {message_user_actions} mua
-                              ON (mua.messageid = m.id
-                             AND mua.userid = :userid2
-                             AND mua.action = :deleteaction
-                             AND mua.timecreated = :timedeleted)";
-            $params['timedeleted'] = $timedeleted;
-        }
-
-        $params['userid2'] = $userid;
-        $params['deleteaction'] = api::MESSAGE_ACTION_DELETED;
-
-        $sql .= " WHERE mc.convhash = :convhash";
-
-        if (!empty($timefrom)) {
-            $sql .= " AND m.timecreated >= :timefrom";
-            $params['timefrom'] = $timefrom;
-        }
-
-        if (!empty($timeto)) {
-            $sql .= " AND m.timecreated <= :timeto";
-            $params['timeto'] = $timeto;
-        }
-
-        if (empty($timedeleted)) {
-            $sql .= " AND mua.id is NULL";
-        }
-
-        $sql .= " ORDER BY m.$sort";
-
-        $messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
-        foreach ($messages as &$message) {
-            $message->useridto = ($message->useridfrom == $userid) ? $otheruserid : $userid;
-        }
-
-        return $messages;
+    public static function get_messages() {
+        throw new \coding_exception('\core_message\helper::get_messages has been removed.');
     }
 
     /**
@@ -234,55 +162,10 @@ class helper {
     }
 
     /**
-     * Helper function to return an array of messages.
-     *
-     * TODO: This function should be removed once the related web services go through final deprecation.
-     * The related web services are data_for_messagearea_messages AND data_for_messagearea_get_most_recent_message.
-     * Followup: MDL-63261
-     *
-     * @param int $userid
-     * @param array $messages
-     * @return array
+     * @deprecated since 3.6
      */
-    public static function create_messages($userid, $messages) {
-        // Store the messages.
-        $arrmessages = array();
-
-        // We always view messages from oldest to newest, ensure we have it in that order.
-        $lastmessage = end($messages);
-        $firstmessage = reset($messages);
-        if ($lastmessage->timecreated < $firstmessage->timecreated) {
-            $messages = array_reverse($messages);
-        }
-
-        // Keeps track of the last day, month and year combo we were viewing.
-        $day = '';
-        $month = '';
-        $year = '';
-        foreach ($messages as $message) {
-            // Check if we are now viewing a different block period.
-            $displayblocktime = false;
-            $date = usergetdate($message->timecreated);
-            if ($day != $date['mday'] || $month != $date['month'] || $year != $date['year']) {
-                $day = $date['mday'];
-                $month = $date['month'];
-                $year = $date['year'];
-                $displayblocktime = true;
-            }
-            // Store the message to pass to the renderable.
-            $msg = new \stdClass();
-            $msg->id = $message->id;
-            $msg->text = message_format_message_text($message);
-            $msg->currentuserid = $userid;
-            $msg->useridfrom = $message->useridfrom;
-            $msg->useridto = $message->useridto;
-            $msg->displayblocktime = $displayblocktime;
-            $msg->timecreated = $message->timecreated;
-            $msg->timeread = $message->timeread;
-            $arrmessages[] = $msg;
-        }
-
-        return $arrmessages;
+    public static function create_messages() {
+        throw new \coding_exception('\core_message\helper::create_messages has been removed.');
     }
 
     /**
@@ -428,7 +311,9 @@ class helper {
      * @return array
      */
     public static function togglecontact_link_params($user, $iscontact = false) {
+        global $USER;
         $params = array(
+            'data-currentuserid' => $USER->id,
             'data-userid' => $user->id,
             'data-is-contact' => $iscontact,
             'id' => 'toggle-contact-button',
@@ -639,47 +524,11 @@ class helper {
 
         return $members;
     }
-
     /**
-     * Backwards compatibility formatter, transforming the new output of get_conversations() into the old format.
-     *
-     * TODO: This function should be removed once the related web services go through final deprecation.
-     * The related web services are data_for_messagearea_conversations.
-     * Followup: MDL-63261
-     *
-     * @param array $conversations the array of conversations, which must come from get_conversations().
-     * @return array the array of conversations, formatted in the legacy style.
+     * @deprecated since 3.6
      */
-    public static function get_conversations_legacy_formatter(array $conversations) : array {
-        // Transform new data format back into the old format, just for BC during the deprecation life cycle.
-        $tmp = [];
-        foreach ($conversations as $id => $conv) {
-            // Only individual conversations were supported in legacy messaging.
-            if ($conv->type != \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
-                continue;
-            }
-            $data = new \stdClass();
-            // The logic for the 'other user' is as follows:
-            // If a conversation is of type 'individual', the other user is always the member who is not the current user.
-            // If the conversation is of type 'group', the other user is always the sender of the most recent message.
-            // The get_conversations method already follows this logic, so we just need the first member.
-            $otheruser = reset($conv->members);
-            $data->userid = $otheruser->id;
-            $data->useridfrom = $conv->messages[0]->useridfrom ?? null;
-            $data->fullname = $conv->members[$otheruser->id]->fullname;
-            $data->profileimageurl = $conv->members[$otheruser->id]->profileimageurl;
-            $data->profileimageurlsmall = $conv->members[$otheruser->id]->profileimageurlsmall;
-            $data->ismessaging = isset($conv->messages[0]->text) ? true : false;
-            $data->lastmessage = $conv->messages[0]->text ? clean_param($conv->messages[0]->text, PARAM_NOTAGS) : null;
-            $data->lastmessagedate = $conv->messages[0]->timecreated ?? null;
-            $data->messageid = $conv->messages[0]->id ?? null;
-            $data->isonline = $conv->members[$otheruser->id]->isonline ?? null;
-            $data->isblocked = $conv->members[$otheruser->id]->isblocked ?? null;
-            $data->isread = $conv->isread;
-            $data->unreadcount = $conv->unreadcount;
-            $tmp[$data->userid] = $data;
-        }
-        return $tmp;
+    public static function get_conversations_legacy_formatter() {
+        throw new \coding_exception('\core_message\helper::get_conversations_legacy_formatter has been removed.');
     }
 
     /**
diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php
deleted file mode 100644 (file)
index ab01237..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare a contact for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class to prepare a contact for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class contact implements templatable, renderable {
-
-    /**
-     * @var int Maximum length of message to show in panel.
-     */
-    const MAX_MSG_LENGTH = 60;
-
-    /**
-     * @var int The userid.
-     */
-    public $userid;
-
-    /**
-     * @var int The id of the user who sent the last message.
-     */
-    public $useridfrom;
-
-    /**
-     * @var string The fullname.
-     */
-    public $fullname;
-
-    /**
-     * @var string The profile image url.
-     */
-    public $profileimageurl;
-
-    /**
-     * @var string The small profile image url.
-     */
-    public $profileimageurlsmall;
-
-    /**
-     * @var int The message id.
-     */
-    public $messageid;
-
-    /**
-     * @var bool Are we messaging the user?
-     */
-    public $ismessaging;
-
-    /**
-     * @var string The last message sent.
-     */
-    public $lastmessage;
-
-    /**
-     * @var int The last message sent timestamp.
-     */
-    public $lastmessagedate;
-
-    /**
-     * @var bool Is the user online?
-     */
-    public $isonline;
-
-    /**
-     * @var bool Is the user blocked?
-     */
-    public $isblocked;
-
-    /**
-     * @var bool Is the message read?
-     */
-    public $isread;
-
-    /**
-     * @var int The number of unread messages.
-     */
-    public $unreadcount;
-
-    /**
-     * @var int The id of the conversation to which to message belongs.
-     */
-    public $conversationid;
-
-    /**
-     * Constructor.
-     *
-     * @param \stdClass $contact
-     */
-    public function __construct($contact) {
-        $this->userid = $contact->userid;
-        $this->useridfrom = $contact->useridfrom;
-        $this->fullname = $contact->fullname;
-        $this->profileimageurl = $contact->profileimageurl;
-        $this->profileimageurlsmall = $contact->profileimageurlsmall;
-        $this->messageid = $contact->messageid;
-        $this->ismessaging = $contact->ismessaging;
-        $this->lastmessage = $contact->lastmessage;
-        $this->lastmessagedate = $contact->lastmessagedate;
-        $this->isonline = $contact->isonline;
-        $this->isblocked = $contact->isblocked;
-        $this->isread = $contact->isread;
-        $this->unreadcount = $contact->unreadcount;
-        $this->conversationid = $contact->conversationid ?? null;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        $contact = new \stdClass();
-        $contact->userid = $this->userid;
-        $contact->fullname = $this->fullname;
-        $contact->profileimageurl = $this->profileimageurl;
-        $contact->profileimageurlsmall = $this->profileimageurlsmall;
-        $contact->messageid = $this->messageid;
-        $contact->ismessaging = $this->ismessaging;
-        $contact->sentfromcurrentuser = false;
-        if ($this->lastmessage) {
-            if ($this->userid !== $this->useridfrom) {
-                $contact->sentfromcurrentuser = true;
-            }
-            $contact->lastmessage = shorten_text($this->lastmessage, self::MAX_MSG_LENGTH);
-        } else {
-            $contact->lastmessage = null;
-        }
-        $contact->lastmessagedate = $this->lastmessagedate;
-        $contact->showonlinestatus = is_null($this->isonline) ? false : true;
-        $contact->isonline = $this->isonline;
-        $contact->isblocked = $this->isblocked;
-        $contact->isread = $this->isread;
-        $contact->unreadcount = $this->unreadcount;
-        $contact->conversationid = $this->conversationid;
-
-        return $contact;
-    }
-}
diff --git a/message/classes/output/messagearea/contacts.php b/message/classes/output/messagearea/contacts.php
deleted file mode 100644 (file)
index 785d9a9..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare the contacts for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class to prepare the contacts for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class contacts implements templatable, renderable {
-
-    /**
-     * @var int The id of the user that has been selected.
-     */
-    public $contactuserid;
-
-    /**
-     * @var array The contacts.
-     */
-    public $contacts;
-
-    /**
-     * Constructor.
-     *
-     * @param int|null $contactuserid The id of the user that has been selected
-     * @param array $contacts
-     */
-    public function __construct($contactuserid, $contacts) {
-        $this->contactuserid = $contactuserid;
-        $this->contacts = $contacts;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        $data = new \stdClass();
-        $data->contacts = array();
-        $userids = array();
-        foreach ($this->contacts as $contact) {
-            $contact = new contact($contact);
-            $contactdata = $contact->export_for_template($output);
-            $userids[$contactdata->userid] = $contactdata->userid;
-            // Check if the contact was selected.
-            if ($this->contactuserid == $contactdata->userid) {
-                $contactdata->selected = true;
-            }
-            $data->contacts[] = $contactdata;
-        }
-        // Check if the other user is not part of the contacts. We may be sending a message to someone
-        // we have not had a conversation with, so we want to add a new item to the contacts array.
-        if ($this->contactuserid && !isset($userids[$this->contactuserid])) {
-            $user = \core_user::get_user($this->contactuserid);
-            // Set an empty message so that we know we are messaging the user, and not viewing their profile.
-            $user->smallmessage = '';
-            $user->useridfrom = $user->id;
-            $contact = \core_message\helper::create_contact($user);
-            $contact = new contact($contact);
-            $contactdata = $contact->export_for_template($output);
-            $contactdata->selected = true;
-            // Put the contact at the front.
-            array_unshift($data->contacts, $contactdata);
-        }
-
-        return $data;
-    }
-}
diff --git a/message/classes/output/messagearea/message.php b/message/classes/output/messagearea/message.php
deleted file mode 100644 (file)
index 93177e0..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare a message for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class to prepare a message for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class message implements templatable, renderable {
-
-    /**
-     * @var int The message id.
-     */
-    public $id;
-
-    /**
-     * @var int The current userid.
-     */
-    public $currentuserid;
-
-    /**
-     * @var int The userid to.
-     */
-    public $useridto;
-
-    /**
-     * @var int The userid from.
-     */
-    public $useridfrom;
-
-    /**
-     * @var string The message text.
-     */
-    public $text;
-
-    /**
-     * @var bool Are we displaying the time?
-     */
-    public $displayblocktime;
-
-    /**
-     * @var int The time created of the message.
-     */
-    public $timecreated;
-
-    /**
-     * @var int The time the message was read.
-     */
-    public $timeread;
-
-    /**
-     * Constructor.
-     *
-     * @param \stdClass $message
-     */
-    public function __construct($message) {
-        $this->id = $message->id;
-        $this->currentuserid = $message->currentuserid;
-        $this->useridto = $message->useridto;
-        $this->useridfrom = $message->useridfrom;
-        $this->text = $message->text;
-        $this->displayblocktime = $message->displayblocktime;
-        $this->timecreated = $message->timecreated;
-        $this->timeread = $message->timeread;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        $message = new \stdClass();
-        $message->id = $this->id;
-        $message->useridto = $this->useridto;
-        $message->useridfrom = $this->useridfrom;
-        $message->text = $this->text;
-        $message->displayblocktime = $this->displayblocktime;
-        $message->blocktime = userdate($this->timecreated, get_string('strftimedaydate'));
-        $message->position = 'left';
-        if ($this->currentuserid == $this->useridfrom) {
-            $message->position = 'right';
-        }
-        $message->timesent = userdate($this->timecreated, get_string('strftimetime'));
-        $message->timecreated = $this->timecreated;
-        $message->isread = !empty($this->timeread) ? 1 : 0;
-
-        return $message;
-    }
-}
diff --git a/message/classes/output/messagearea/message_area.php b/message/classes/output/messagearea/message_area.php
deleted file mode 100644 (file)
index 9d2e05d..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare the message area for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class to prepare the message area for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class message_area implements templatable, renderable {
-
-    /**
-     * @var int The user id.
-     */
-    public $userid;
-
-    /**
-     * @var int The other user id.
-     */
-    public $otheruserid;
-
-    /**
-     * @var array The contacts for the users.
-     */
-    public $contacts;
-
-    /**
-     * @var array The messages for the user.
-     */
-    public $messages;
-
-    /**
-     * @var bool Was a specific conversation requested.
-     */
-    public $requestedconversation;
-
-    /**
-     * @var int The minimum time to poll for messages.
-     */
-    public $pollmin;
-
-    /**
-     * @var int The maximum time to poll for messages.
-     */
-    public $pollmax;
-
-    /**
-     * @var int The time used once we have reached the maximum polling time.
-     */
-    public $polltimeout;
-
-    /**
-     * @var bool Are we creating a new message and show the contacts section first?
-     */
-    public $contactsfirst;
-
-    /**
-     * Constructor.
-     *
-     * @param int $userid The ID of the user whose contacts and messages we are viewing
-     * @param int|null $otheruserid The id of the user we are viewing, null if none
-     * @param array $contacts
-     * @param array|null $messages
-     * @param bool $requestedconversation
-     * @param bool $contactsfirst Whether we are viewing the contacts first.
-     * @param int $pollmin
-     * @param int $pollmax
-     * @param int $polltimeout
-     */
-    public function __construct($userid, $otheruserid, $contacts, $messages, $requestedconversation, $contactsfirst, $pollmin,
-            $pollmax, $polltimeout) {
-        $this->userid = $userid;
-        // Setting the other user to null when showing contacts will remove any contact from being selected.
-        $this->otheruserid = (!$contactsfirst) ? $otheruserid : null;
-        $this->contacts = $contacts;
-        $this->messages = $messages;
-        $this->requestedconversation = $requestedconversation;
-        $this->pollmin = $pollmin;
-        $this->pollmax = $pollmax;
-        $this->polltimeout = $polltimeout;
-        $this->contactsfirst = $contactsfirst;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        $data = new \stdClass();
-        $data->userid = $this->userid;
-        $contacts = new contacts($this->otheruserid, $this->contacts);
-        $data->contacts = $contacts->export_for_template($output);
-        if ($this->contactsfirst) {
-            // Don't show any messages if we are creating a new message.
-            $messages = new messages($this->userid, null, array());
-        } else {
-            $messages = new messages($this->userid, $this->otheruserid, $this->messages);
-        }
-        $data->messages = $messages->export_for_template($output);
-        $data->isconversation = ($this->contactsfirst) ? false : true;
-        $data->requestedconversation = $this->requestedconversation;
-        $data->pollmin = $this->pollmin;
-        $data->pollmax = $this->pollmax;
-        $data->polltimeout = $this->polltimeout;
-        $data->contactsfirst = $this->contactsfirst;
-
-        return $data;
-    }
-}
diff --git a/message/classes/output/messagearea/messages.php b/message/classes/output/messagearea/messages.php
deleted file mode 100644 (file)
index ce8e75c..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare the messages for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use core_message\api;
-use renderable;
-use templatable;
-
-/**
- * Class to prepare the messages for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class messages implements templatable, renderable {
-
-    /**
-     * @var array The messages.
-     */
-    public $messages;
-
-    /**
-     * @var int The current user id.
-     */
-    public $currentuserid;
-
-    /**
-     * @var int The other user id.
-     */
-    public $otheruserid;
-
-    /**
-     * @var \stdClass The other user.
-     */
-    public $otheruser;
-
-    /**
-     * Constructor.
-     *
-     * @param int $currentuserid The current user we are wanting to view messages for
-     * @param int $otheruserid The other user we are wanting to view messages for
-     * @param array $messages
-     */
-    public function __construct($currentuserid, $otheruserid, $messages) {
-        $ufields = 'id, ' . get_all_user_name_fields(true) . ', lastaccess';
-
-        $this->currentuserid = $currentuserid;
-        if ($otheruserid) {
-            $this->otheruserid = $otheruserid;
-            $this->otheruser = \core_user::get_user($otheruserid, $ufields, MUST_EXIST);
-        }
-        $this->messages = $messages;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        global $USER;
-
-        $data = new \stdClass();
-        $data->iscurrentuser = $USER->id == $this->currentuserid;
-        $data->currentuserid = $this->currentuserid;
-        if ($this->otheruserid) {
-            $data->otheruserid = $this->otheruserid;
-            $data->otheruserfullname = fullname($this->otheruser);
-        }
-        $data->isonline = null;
-        if ($this->otheruserid) {
-            if (\core_message\helper::show_online_status($this->otheruser)) {
-                $data->isonline = \core_message\helper::is_online($this->otheruser->lastaccess);
-            }
-        }
-        $data->showonlinestatus = is_null($data->isonline) ? false : true;
-
-        $data->messages = array();
-        foreach ($this->messages as $message) {
-            $message = new message($message);
-            $data->messages[] = $message->export_for_template($output);
-        }
-
-        $blockeduserid = $this->otheruserid ?? $USER->id;
-        $data->isblocked = api::is_blocked($this->currentuserid, $blockeduserid);
-
-        return $data;
-    }
-}
diff --git a/message/classes/output/messagearea/profile.php b/message/classes/output/messagearea/profile.php
deleted file mode 100644 (file)
index 151bba1..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to prepare a profile for display.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class to prepare a profile for display.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class profile implements templatable, renderable {
-
-    /**
-     * @var int The id of the user we are going to view.
-     */
-    public $userid;
-
-    /**
-     * @var string The fullname.
-     */
-    public $fullname;
-
-    /**
-     * @var string The city.
-     */
-    public $city;
-
-    /**
-     * @var string The country.
-     */
-    public $country;
-
-    /**
-     * @var string The email.
-     */
-    public $email;
-
-    /**
-     * @var string The profile image url.
-     */
-    public $profileimageurl;
-
-    /**
-     * @var string The small profile image url.
-     */
-    public $profileimageurlsmall;
-
-    /**
-     * @var bool Is the user online?
-     */
-    public $isonline;
-
-    /**
-     * @var bool Is the user blocked?
-     */
-    public $isblocked;
-
-    /**
-     * @var bool Is the user a contact?
-     */
-    public $iscontact;
-
-    /**
-     * Constructor.
-     *
-     * @param \stdClass $profile
-     */
-    public function __construct($profile) {
-        $this->userid = $profile->userid;
-        $this->fullname = $profile->fullname;
-        $this->isonline = $profile->isonline;
-        $this->email = $profile->email;
-        $this->country = $profile->country;
-        $this->city = $profile->city;
-        $this->profileimageurl = $profile->profileimageurl;
-        $this->profileimageurlsmall = $profile->profileimageurlsmall;
-        $this->isblocked = $profile->isblocked;
-        $this->iscontact = $profile->iscontact;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        $data = new \stdClass();
-        $data->userid = $this->userid;
-        $data->fullname = $this->fullname;
-        $data->showonlinestatus = is_null($this->isonline) ? false : true;
-        $data->isonline = $this->isonline;
-        $data->email = $this->email;
-        if (!empty($this->country)) {
-            $data->country = get_string($this->country, 'countries');
-        } else {
-            $data->country = '';
-        }
-        $data->city = $this->city;
-        $data->profileimageurl = $this->profileimageurl;
-        $data->profileimageurlsmall = $this->profileimageurlsmall;
-        $data->isblocked = $this->isblocked;
-        $data->iscontact = $this->iscontact;
-
-        return $data;
-    }
-}
diff --git a/message/classes/output/messagearea/user_search_results.php b/message/classes/output/messagearea/user_search_results.php
deleted file mode 100644 (file)
index ac66358..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains class used to display user search results.
- *
- * TODO: This file should be removed once the related web services go through final deprecation.
- * Followup: MDL-63261
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-namespace core_message\output\messagearea;
-
-defined('MOODLE_INTERNAL') || die();
-
-use renderable;
-use templatable;
-
-/**
- * Class used to display user search results.
- *
- * @package   core_message
- * @copyright 2016 Mark Nelson <markn@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class user_search_results implements templatable, renderable {
-
-    /**
-     * @var array The list of contacts.
-     */
-    public $contacts;
-
-    /**
-     * @var array The list of courses.
-     */
-    public $courses;
-
-    /**
-     * @var array The list of non-contacts.
-     */
-    public $noncontacts;
-
-    /**
-     * Constructor.
-     *
-     * @param array $contacts list of contacts.
-     * @param array $courses list of courses.
-     * @param array $noncontacts list of nonconcat users.
-     */
-    public function __construct($contacts, $courses = array(), $noncontacts = array()) {
-        $this->contacts = $contacts;
-        $this->courses = $courses;
-        $this->noncontacts = $noncontacts;
-    }
-
-    public function export_for_template(\renderer_base $output) {
-        // Set the defaults for the data we are going to export.
-        $data = new \stdClass();
-        $data->hascontacts = false;
-        $data->contacts = array();
-        $data->hascourses = false;
-        $data->courses = array();
-        $data->hasnoncontacts = false;
-        $data->noncontacts = array();
-
-        // Check if there are any contacts.
-        if (!empty($this->contacts)) {
-            $data->hascontacts = true;
-            foreach ($this->contacts as $contact) {
-                $contact = new contact($contact);
-                $data->contacts[] = $contact->export_for_template($output);
-            }
-        }
-
-        // Check if there are any courses.
-        if (!empty($this->courses)) {
-            $data->hascourses = true;
-            $data->courses = [];
-            foreach ($this->courses as $course) {
-                $coursecontext = \context_course::instance($course->id);
-                $course->shortname = external_format_string($course->shortname, $coursecontext->id, true);
-                $course->fullname = external_format_string($course->fullname, $coursecontext->id, true);
-                $data->courses[] = $course;
-            }
-        }
-
-        // Check if there are any non-contacts.
-        if (!empty($this->noncontacts)) {
-            $data->hasnoncontacts = true;
-            foreach ($this->noncontacts as $noncontact) {
-                $noncontact = new contact($noncontact);
-                $data->noncontacts[] = $noncontact->export_for_template($output);
-            }
-        }
-
-        return $data;
-    }
-}
\ No newline at end of file
index d942821..0358c40 100644 (file)
@@ -268,94 +268,6 @@ class core_message_external extends external_api {
         );
     }
 
-    /**
-     * Create contacts parameters description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_function_parameters
-     * @since Moodle 2.5
-     */
-    public static function create_contacts_parameters() {
-        return new external_function_parameters(
-            array(
-                'userids' => new external_multiple_structure(
-                    new external_value(PARAM_INT, 'User ID'),
-                    'List of user IDs'
-                ),
-                'userid' => new external_value(PARAM_INT, 'The id of the user we are creating the contacts for, 0 for the
-                    current user', VALUE_DEFAULT, 0)
-            )
-        );
-    }
-
-    /**
-     * Create contacts.
-     *
-     * @deprecated since Moodle 3.6
-     * TODO: MDL-63261
-     * @param array $userids array of user IDs.
-     * @param int $userid The id of the user we are creating the contacts for
-     * @return external_description
-     * @since Moodle 2.5
-     */
-    public static function create_contacts($userids, $userid = 0) {
-        global $CFG, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        if (empty($userid)) {
-            $userid = $USER->id;
-        }
-
-        // Validate context.
-        $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 != $params['userid']) && !has_capability($capability, $context)) {
-            throw new required_capability_exception($context, $capability, 'nopermissions', '');
-        }
-
-        $warnings = array();
-        foreach ($params['userids'] as $id) {
-            if (!\core_message\api::create_contact_request($params['userid'], $id)) {
-                $warnings[] = array(
-                    'item' => 'user',
-                    'itemid' => $id,
-                    'warningcode' => 'contactnotcreated',
-                    'message' => 'The contact could not be created'
-                );
-            }
-        }
-        return $warnings;
-    }
-
-    /**
-     * Create contacts return description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_description
-     * @since Moodle 2.5
-     */
-    public static function create_contacts_returns() {
-        return new external_warnings();
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function create_contacts_is_deprecated() {
-        return true;
-    }
-
     /**
      * Delete contacts parameters description.
      *
@@ -659,173 +571,6 @@ class core_message_external extends external_api {
         return new external_warnings();
     }
 
-    /**
-     * Block contacts parameters description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_function_parameters
-     * @since Moodle 2.5
-     */
-    public static function block_contacts_parameters() {
-        return new external_function_parameters(
-            array(
-                'userids' => new external_multiple_structure(
-                    new external_value(PARAM_INT, 'User ID'),
-                    'List of user IDs'
-                ),
-                'userid' => new external_value(PARAM_INT, 'The id of the user we are blocking the contacts for, 0 for the
-                    current user', VALUE_DEFAULT, 0)
-            )
-        );
-    }
-
-    /**
-     * Block contacts.
-     *
-     * @deprecated since Moodle 3.6
-     * TODO: MDL-63261
-     * @param array $userids array of user IDs.
-     * @param int $userid The id of the user we are blocking the contacts for
-     * @return external_description
-     * @since Moodle 2.5
-     */
-    public static function block_contacts($userids, $userid = 0) {
-        global $CFG, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        if (empty($userid)) {
-            $userid = $USER->id;
-        }
-
-        // Validate context.
-        $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 != $params['userid']) && !has_capability($capability, $context)) {
-            throw new required_capability_exception($context, $capability, 'nopermissions', '');
-        }
-
-        $warnings = array();
-        foreach ($params['userids'] as $id) {
-            if (!\core_message\api::block_user($params['userid'], $id)) {
-                $warnings[] = array(
-                    'item' => 'user',
-                    'itemid' => $id,
-                    'warningcode' => 'contactnotblocked',
-                    'message' => 'The contact could not be blocked'
-                );
-            }
-        }
-        return $warnings;
-    }
-
-    /**
-     * Block contacts return description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_description
-     * @since Moodle 2.5
-     */
-    public static function block_contacts_returns() {
-        return new external_warnings();
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function block_contacts_is_deprecated() {
-        return true;
-    }
-
-    /**
-     * Unblock contacts parameters description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_function_parameters
-     * @since Moodle 2.5
-     */
-    public static function unblock_contacts_parameters() {
-        return new external_function_parameters(
-            array(
-                'userids' => new external_multiple_structure(
-                    new external_value(PARAM_INT, 'User ID'),
-                    'List of user IDs'
-                ),
-                'userid' => new external_value(PARAM_INT, 'The id of the user we are unblocking the contacts for, 0 for the
-                    current user', VALUE_DEFAULT, 0)
-            )
-        );
-    }
-
-    /**
-     * Unblock contacts.
-     *
-     * @param array $userids array of user IDs.
-     * @param int $userid The id of the user we are unblocking the contacts for
-     * @return null
-     * @since Moodle 2.5
-     */
-    public static function unblock_contacts($userids, $userid = 0) {
-        global $CFG, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        if (empty($userid)) {
-            $userid = $USER->id;
-        }
-
-        // Validate context.
-        $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 != $params['userid']) && !has_capability($capability, $context)) {
-            throw new required_capability_exception($context, $capability, 'nopermissions', '');
-        }
-
-        foreach ($params['userids'] as $id) {
-            core_message\api::unblock_user($params['userid'], $id);
-        }
-
-        return null;
-    }
-
-    /**
-     * Unblock contacts return description.
-     *
-     * @deprecated since Moodle 3.6
-     * @return external_description
-     * @since Moodle 2.5
-     */
-    public static function unblock_contacts_returns() {
-        return null;
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function unblock_contacts_is_deprecated() {
-        return true;
-    }
-
     /**
      * Returns contact requests parameters description.
      *
@@ -1347,327 +1092,102 @@ class core_message_external extends external_api {
     }
 
     /**
-     * Return the structure of a message area message.
-     *
-     * @return external_single_structure
-     * @since Moodle 3.2
-     */
-    private static function get_messagearea_message_structure() {
-        return new external_single_structure(
-            array(
-                'id' => new external_value(PARAM_INT, 'The id of the message'),
-                'useridfrom' => new external_value(PARAM_INT, 'The id of the user who sent the message'),
-                'useridto' => new external_value(PARAM_INT, 'The id of the user who received the message'),
-                'text' => new external_value(PARAM_RAW, 'The text of the message'),
-                'displayblocktime' => new external_value(PARAM_BOOL, 'Should we display the block time?'),
-                'blocktime' => new external_value(PARAM_NOTAGS, 'The time to display above the message'),
-                'position' => new external_value(PARAM_ALPHA, 'The position of the text'),
-                'timesent' => new external_value(PARAM_NOTAGS, 'The time the message was sent'),
-                'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the message'),
-                'isread' => new external_value(PARAM_INT, 'Determines if the message was read or not'),
-            )
-        );
-    }
-
-    /**
-     * Get messagearea search users in course parameters.
-     *
-     * @deprecated since 3.6
+     * Get messagearea message search users parameters.
      *
      * @return external_function_parameters
-     * @since 3.2
+     * @since 3.6
      */
-    public static function data_for_messagearea_search_users_in_course_parameters() {
+    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'),
-                'courseid' => new external_value(PARAM_INT, 'The id of the course'),
                 '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)
+                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0),
             )
         );
     }
 
     /**
-     * Get messagearea search users in course results.
-     *
-     * @deprecated since 3.6
+     * Get search users results.
      *
      * @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
      * @param int $limitfrom
      * @param int $limitnum
-     * @return stdClass
+     * @return array
      * @throws moodle_exception
-     * @since 3.2
+     * @since 3.6
      */
-    public static function data_for_messagearea_search_users_in_course($userid, $courseid, $search, $limitfrom = 0,
-                                                                       $limitnum = 0) {
-        global $CFG, $PAGE, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
+    public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) {
+        global $USER;
 
         $systemcontext = context_system::instance();
 
         $params = array(
             'userid' => $userid,
-            'courseid' => $courseid,
             'search' => $search,
             'limitfrom' => $limitfrom,
             'limitnum' => $limitnum
         );
-        $params = self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params);
+        $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.');
         }
 
-        $users = \core_message\api::search_users_in_course(
+        list($contacts, $noncontacts) = \core_message\api::message_search_users(
             $params['userid'],
-            $params['courseid'],
             $params['search'],
             $params['limitfrom'],
-            $params['limitnum']
-        );
-        $results = new \core_message\output\messagearea\user_search_results($users);
+            $params['limitnum']);
 
-        $renderer = $PAGE->get_renderer('core_message');
-        return $results->export_for_template($renderer);
+        return array('contacts' => $contacts, 'noncontacts' => $noncontacts);
     }
 
     /**
-     * Get messagearea search users in course returns.
-     *
-     * @deprecated since 3.6
+     * Get messagearea message search users returns.
      *
      * @return external_single_structure
      * @since 3.2
      */
-    public static function data_for_messagearea_search_users_in_course_returns() {
+    public static function message_search_users_returns() {
         return new external_single_structure(
             array(
                 'contacts' => new external_multiple_structure(
-                    self::get_messagearea_contact_structure()
+                    self::get_conversation_member_structure()
                 ),
+                'noncontacts' => new external_multiple_structure(
+                    self::get_conversation_member_structure()
+                )
             )
         );
     }
 
     /**
-     * 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
+     * Get messagearea search messages parameters.
      *
      * @return external_function_parameters
      * @since 3.2
      */
-    public static function data_for_messagearea_search_users_parameters() {
+    public static function data_for_messagearea_search_messages_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 messagearea search users results.
-     *
-     * @deprecated since 3.6
+     * Get messagearea search messages results.
      *
      * @param int $userid The id of the user who is performing the search
      * @param string $search The string being searched
-     * @param int $limitnum
-     * @return stdClass
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function data_for_messagearea_search_users($userid, $search, $limitnum = 0) {
-        global $CFG, $PAGE, $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,
-            'limitnum' => $limitnum
-        );
-        $params = self::validate_parameters(self::data_for_messagearea_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, $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');
-        return $search->export_for_template($renderer);
-    }
-
-    /**
-     * Get messagearea search users returns.
-     *
-     * @deprecated since 3.6
-     *
-     * @return external_single_structure
-     * @since 3.2
-     */
-    public static function data_for_messagearea_search_users_returns() {
-        return new external_single_structure(
-            array(
-                'contacts' => new external_multiple_structure(
-                    self::get_messagearea_contact_structure()
-                ),
-                'courses' => new external_multiple_structure(
-                    new external_single_structure(
-                        array(
-                            'id' => new external_value(PARAM_INT, 'The course id'),
-                            'shortname' => new external_value(PARAM_TEXT, 'The course shortname'),
-                            'fullname' => new external_value(PARAM_TEXT, 'The course fullname'),
-                        )
-                    )
-                ),
-                'noncontacts' => new external_multiple_structure(
-                    self::get_messagearea_contact_structure()
-                )
-            )
-        );
-    }
-
-    /**
-     * 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 $USER;
-
-        $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()
-                ),
-                'noncontacts' => new external_multiple_structure(
-                    self::get_conversation_member_structure()
-                )
-            )
-        );
-    }
-
-    /**
-     * Get messagearea search messages parameters.
-     *
-     * @return external_function_parameters
-     * @since 3.2
-     */
-    public static function data_for_messagearea_search_messages_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 messagearea search messages 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 $limitfrom
      * @param int $limitnum
      * @return stdClass
      * @throws moodle_exception
@@ -2135,41 +1655,41 @@ class core_message_external extends external_api {
     }
 
     /**
-     * The messagearea conversations parameters.
+     * The conversation messages parameters.
      *
-     * @deprecated since 3.6
      * @return external_function_parameters
-     * @since 3.2
+     * @since 3.6
      */
-    public static function data_for_messagearea_conversations_parameters() {
+    public static function get_conversation_messages_parameters() {
         return new external_function_parameters(
             array(
-                'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'),
+                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
+                'convid' => new external_value(PARAM_INT, 'The conversation id'),
                 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
-                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0)
+                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0),
+                'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false),
+                'timefrom' => new external_value(PARAM_INT,
+                    'The timestamp from which the messages were created', VALUE_DEFAULT, 0),
             )
         );
     }
 
     /**
-     * Get messagearea conversations.
-     *
-     * NOTE FOR FINAL DEPRECATION:
-     * When removing this method, please also consider removal of get_conversations_legacy_formatter()
-     * from the \core_message\helper class. This helper method was used solely to format the new get_conversations() return data
-     * into the old format used here, and in message/index.php. If we no longer need either of these, then that method can be
-     * removed.
+     * Get conversation messages.
      *
-     * @deprecated since 3.6
-     * @param int $userid The id of the user who we are viewing conversations for
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @return stdClass
+     * @param  int $currentuserid The current user's id.
+     * @param  int $convid The conversation id.
+     * @param  int $limitfrom Return a subset of records, starting at this point (optional).
+     * @param  int $limitnum Return a subset comprising this many records in total (optional, required if $limitfrom is set).
+     * @param  bool $newest True for getting first newest messages, false otherwise.
+     * @param  int  $timefrom The time from the conversation messages to get.
+     * @return array The messages and members who have sent some of these messages.
      * @throws moodle_exception
-     * @since 3.2
+     * @since 3.6
      */
-    public static function data_for_messagearea_conversations($userid, $limitfrom = 0, $limitnum = 0) {
-        global $CFG, $PAGE, $USER;
+    public static function get_conversation_messages(int $currentuserid, int $convid, int $limitfrom = 0, int $limitnum = 0,
+                                                         bool $newest = false, int $timefrom = 0) {
+        global $CFG, $USER;
 
         // Check if messaging is enabled.
         if (empty($CFG->messaging)) {
@@ -2179,353 +1699,61 @@ class core_message_external extends external_api {
         $systemcontext = context_system::instance();
 
         $params = array(
-            'userid' => $userid,
+            'currentuserid' => $currentuserid,
+            'convid' => $convid,
             'limitfrom' => $limitfrom,
-            'limitnum' => $limitnum
+            'limitnum' => $limitnum,
+            'newest' => $newest,
+            'timefrom' => $timefrom,
         );
-        $params = self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params);
+        $params = self::validate_parameters(self::get_conversation_messages_parameters(), $params);
         self::validate_context($systemcontext);
 
-        if (($USER->id != $params['userid']) && !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.');
         }
 
-        $conversations = \core_message\api::get_conversations($params['userid'], $params['limitfrom'], $params['limitnum']);
+        // Check that the user belongs to the conversation.
+        if (!\core_message\api::is_user_in_conversation($params['currentuserid'], $params['convid'])) {
+            throw new moodle_exception('User is not part of conversation.');
+        }
 
-        // 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);
+        $sort = $newest ? 'timecreated DESC' : 'timecreated ASC';
 
-        $conversations = new \core_message\output\messagearea\contacts(null, $conversations);
+        // We need to enforce a one second delay on messages to avoid race conditions of current
+        // messages still being sent.
+        //
+        // There is a chance that we could request messages before the current time's
+        // second has elapsed and while other messages are being sent in that same second. In which
+        // 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($params['timefrom']) ? 0 : time() - 1;
 
-        $renderer = $PAGE->get_renderer('core_message');
-        return $conversations->export_for_template($renderer);
+        // No requesting messages from the current time, as stated above.
+        if ($params['timefrom'] == time()) {
+            $messages = [];
+        } else {
+            $messages = \core_message\api::get_conversation_messages(
+                $params['currentuserid'],
+                $params['convid'],
+                $params['limitfrom'],
+                $params['limitnum'],
+                $sort,
+                $params['timefrom'],
+                $timeto);
+        }
+
+        return $messages;
     }
 
     /**
-     * The messagearea conversations return structure.
+     * The messagearea messages return structure.
      *
-     * @deprecated since 3.6
      * @return external_single_structure
-     * @since 3.2
+     * @since 3.6
      */
-    public static function data_for_messagearea_conversations_returns() {
-        return new external_single_structure(
-            array(
-                'contacts' => new external_multiple_structure(
-                    self::get_messagearea_contact_structure()
-                )
-            )
-        );
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function data_for_messagearea_conversations_is_deprecated() {
-        return true;
-    }
-
-    /**
-     * The messagearea contacts return parameters.
-     *
-     * @deprecated since 3.6
-     * @return external_function_parameters
-     * @since 3.2
-     */
-    public static function data_for_messagearea_contacts_parameters() {
-        return self::data_for_messagearea_conversations_parameters();
-    }
-
-    /**
-     * 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
-     * @return stdClass
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function data_for_messagearea_contacts($userid, $limitfrom = 0, $limitnum = 0) {
-        global $CFG, $PAGE, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        $systemcontext = context_system::instance();
-
-        $params = array(
-            'userid' => $userid,
-            'limitfrom' => $limitfrom,
-            'limitnum' => $limitnum
-        );
-        $params = self::validate_parameters(self::data_for_messagearea_contacts_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.');
-        }
-
-        $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');
-        return $contacts->export_for_template($renderer);
-    }
-
-    /**
-     * The messagearea contacts return structure.
-     *
-     * @deprecated since 3.6
-     * @return external_single_structure
-     * @since 3.2
-     */
-    public static function data_for_messagearea_contacts_returns() {
-        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
-     */
-    public static function data_for_messagearea_messages_parameters() {
-        return new external_function_parameters(
-            array(
-                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
-                'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'),
-                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
-                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0),
-                'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false),
-                'timefrom' => new external_value(PARAM_INT,
-                    'The timestamp from which the messages were created', VALUE_DEFAULT, 0),
-            )
-        );
-    }
-
-    /**
-     * 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
-     * @param int $limitnum
-     * @param boolean $newest
-     * @return stdClass
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0,
-                                                         $newest = false, $timefrom = 0) {
-        global $CFG, $PAGE, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        $systemcontext = context_system::instance();
-
-        $params = array(
-            'currentuserid' => $currentuserid,
-            'otheruserid' => $otheruserid,
-            'limitfrom' => $limitfrom,
-            'limitnum' => $limitnum,
-            'newest' => $newest,
-            'timefrom' => $timefrom,
-        );
-        $params = self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params);
-        self::validate_context($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 ($params['newest']) {
-            $sort = 'timecreated DESC';
-        } else {
-            $sort = 'timecreated ASC';
-        }
-
-        // We need to enforce a one second delay on messages to avoid race conditions of current
-        // messages still being sent.
-        //
-        // There is a chance that we could request messages before the current time's
-        // second has elapsed and while other messages are being sent in that same second. In which
-        // 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($params['timefrom'])) {
-            $timeto = time() - 1;
-        } else {
-            $timeto = 0;
-        }
-
-        // No requesting messages from the current time, as stated above.
-        if ($params['timefrom'] == time()) {
-            $messages = [];
-        } else {
-            $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($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
-     */
-    public static function data_for_messagearea_messages_returns() {
-        return new external_single_structure(
-            array(
-                'iscurrentuser' => new external_value(PARAM_BOOL, 'Is the currently logged in user the user we are viewing
-                    the messages on behalf of?'),
-                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
-                'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'),
-                'otheruserfullname' => new external_value(PARAM_NOTAGS, 'The other user\'s fullname'),
-                'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'),
-                'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'),
-                'messages' => new external_multiple_structure(
-                    self::get_messagearea_message_structure()
-                ),
-                'isblocked' => new external_value(PARAM_BOOL, 'Is this user blocked by the current user?', VALUE_DEFAULT, false),
-            )
-        );
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function data_for_messagearea_messages_is_deprecated() {
-        return true;
-    }
-
-    /**
-     * The conversation messages parameters.
-     *
-     * @return external_function_parameters
-     * @since 3.6
-     */
-    public static function get_conversation_messages_parameters() {
-        return new external_function_parameters(
-            array(
-                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
-                'convid' => new external_value(PARAM_INT, 'The conversation id'),
-                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
-                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0),
-                'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false),
-                'timefrom' => new external_value(PARAM_INT,
-                    'The timestamp from which the messages were created', VALUE_DEFAULT, 0),
-            )
-        );
-    }
-
-    /**
-     * Get conversation messages.
-     *
-     * @param  int $currentuserid The current user's id.
-     * @param  int $convid The conversation id.
-     * @param  int $limitfrom Return a subset of records, starting at this point (optional).
-     * @param  int $limitnum Return a subset comprising this many records in total (optional, required if $limitfrom is set).
-     * @param  bool $newest True for getting first newest messages, false otherwise.
-     * @param  int  $timefrom The time from the conversation messages to get.
-     * @return array The messages and members who have sent some of these messages.
-     * @throws moodle_exception
-     * @since 3.6
-     */
-    public static function get_conversation_messages(int $currentuserid, int $convid, int $limitfrom = 0, int $limitnum = 0,
-                                                         bool $newest = false, int $timefrom = 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(
-            'currentuserid' => $currentuserid,
-            'convid' => $convid,
-            'limitfrom' => $limitfrom,
-            'limitnum' => $limitnum,
-            'newest' => $newest,
-            'timefrom' => $timefrom,
-        );
-        $params = self::validate_parameters(self::get_conversation_messages_parameters(), $params);
-        self::validate_context($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.');
-        }
-
-        // Check that the user belongs to the conversation.
-        if (!\core_message\api::is_user_in_conversation($params['currentuserid'], $params['convid'])) {
-            throw new moodle_exception('User is not part of conversation.');
-        }
-
-        $sort = $newest ? 'timecreated DESC' : 'timecreated ASC';
-
-        // We need to enforce a one second delay on messages to avoid race conditions of current
-        // messages still being sent.
-        //
-        // There is a chance that we could request messages before the current time's
-        // second has elapsed and while other messages are being sent in that same second. In which
-        // 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($params['timefrom']) ? 0 : time() - 1;
-
-        // No requesting messages from the current time, as stated above.
-        if ($params['timefrom'] == time()) {
-            $messages = [];
-        } else {
-            $messages = \core_message\api::get_conversation_messages(
-                $params['currentuserid'],
-                $params['convid'],
-                $params['limitfrom'],
-                $params['limitnum'],
-                $sort,
-                $params['timefrom'],
-                $timeto);
-        }
-
-        return $messages;
-    }
-
-    /**
-     * The messagearea messages return structure.
-     *
-     * @return external_single_structure
-     * @since 3.6
-     */
-    public static function get_conversation_messages_returns() {
+    public static function get_conversation_messages_returns() {
         return new external_single_structure(
             array(
                 'id' => new external_value(PARAM_INT, 'The conversation id'),
@@ -2540,379 +1768,65 @@ class core_message_external extends external_api {
     }
 
     /**
-     * The user contacts return parameters.
-     *
-     * @return external_function_parameters
-     */
-    public static function get_user_contacts_parameters() {
-        return new external_function_parameters(
-            array(
-                'userid' => new external_value(PARAM_INT, 'The id of the user who we retrieving the contacts for'),
-                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
-                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0)
-            )
-        );
-    }
-
-    /**
-     * Get user contacts.
-     *
-     * @param int $userid The id of the user who we are viewing conversations for
-     * @param int $limitfrom
-     * @param int $limitnum
-     * @return array
-     * @throws moodle_exception
-     */
-    public static function get_user_contacts(int $userid, int $limitfrom = 0, int $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,
-            'limitfrom' => $limitfrom,
-            'limitnum' => $limitnum
-        );
-        $params = self::validate_parameters(self::get_user_contacts_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.');
-        }
-
-        return \core_message\api::get_user_contacts($params['userid'], $params['limitfrom'], $params['limitnum']);
-    }
-
-    /**
-     * The user contacts return structure.
-     *
-     * @return external_multiple_structure
-     */
-    public static function get_user_contacts_returns() {
-        return new external_multiple_structure(
-            self::get_conversation_member_structure()
-        );
-    }
-
-    /**
-     * The get most recent message return parameters.
-     *
-     * @deprecated since 3.6
-     * @return external_function_parameters
-     * @since 3.2
-     */
-    public static function data_for_messagearea_get_most_recent_message_parameters() {
-        return new external_function_parameters(
-            array(
-                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
-                'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'),
-            )
-        );
-    }
-
-    /**
-     * 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
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function data_for_messagearea_get_most_recent_message($currentuserid, $otheruserid) {
-        global $CFG, $PAGE, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        $systemcontext = context_system::instance();
-
-        $params = array(
-            'currentuserid' => $currentuserid,
-            'otheruserid' => $otheruserid
-        );
-        $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params);
-        self::validate_context($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($params['currentuserid'], $params['otheruserid']);
-        $message = new \core_message\output\messagearea\message($message);
-
-        $renderer = $PAGE->get_renderer('core_message');
-        return $message->export_for_template($renderer);
-    }
-
-    /**
-     * The get most recent message return structure.
-     *
-     * @deprecated since 3.6
-     * @return external_single_structure
-     * @since 3.2
-     */
-    public static function data_for_messagearea_get_most_recent_message_returns() {
-        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
-     */
-    public static function data_for_messagearea_get_profile_parameters() {
-        return new external_function_parameters(
-            array(
-                'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'),
-                'otheruserid' => new external_value(PARAM_INT, 'The id of the user whose profile we want to view'),
-            )
-        );
-    }
-
-    /**
-     * 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
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function data_for_messagearea_get_profile($currentuserid, $otheruserid) {
-        global $CFG, $PAGE, $USER;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        $systemcontext = context_system::instance();
-
-        $params = array(
-            'currentuserid' => $currentuserid,
-            'otheruserid' => $otheruserid
-        );
-        $params = self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params);
-        self::validate_context($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($params['currentuserid'], $params['otheruserid']);
-        $profile = new \core_message\output\messagearea\profile($profile);
-
-        $renderer = $PAGE->get_renderer('core_message');
-        return $profile->export_for_template($renderer);
-    }
-
-    /**
-     * The get profile return structure.
-     *
-     * @deprecated since 3.6
-     * @return external_single_structure
-     * @since 3.2
-     */
-    public static function data_for_messagearea_get_profile_returns() {
-        return new external_single_structure(
-            array(
-                'userid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'),
-                'email' => new external_value(core_user::get_property_type('email'), 'An email address'),
-                'country' => new external_value(PARAM_TEXT, 'Home country of the user'),
-                'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user'),
-                'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'),
-                'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'),
-                'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'),
-                'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'),
-                'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'),
-                'isblocked' => new external_value(PARAM_BOOL, 'Is the user blocked?'),
-                'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?')
-            )
-        );
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function data_for_messagearea_get_profile_is_deprecated() {
-        return true;
-    }
-
-    /**
-     * Get contacts parameters description.
+     * The user contacts return parameters.
      *
-     * @deprecated since 3.6
      * @return external_function_parameters
-     * @since Moodle 2.5
      */
-    public static function get_contacts_parameters() {
-        return new external_function_parameters(array());
+    public static function get_user_contacts_parameters() {
+        return new external_function_parameters(
+            array(
+                'userid' => new external_value(PARAM_INT, 'The id of the user who we retrieving the contacts for'),
+                'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0),
+                'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0)
+            )
+        );
     }
 
     /**
-     * Get contacts.
+     * Get user contacts.
      *
-     * @deprecated since 3.6
-     * @return external_description
-     * @since Moodle 2.5
+     * @param int $userid The id of the user who we are viewing conversations for
+     * @param int $limitfrom
+     * @param int $limitnum
+     * @return array
+     * @throws moodle_exception
      */
-    public static function get_contacts() {
-        global $CFG, $PAGE, $USER;
+    public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) {
+        global $CFG, $USER;
 
         // Check if messaging is enabled.
         if (empty($CFG->messaging)) {
             throw new moodle_exception('disabled', 'message');
         }
 
-        require_once($CFG->dirroot . '/user/lib.php');
-
-        $allcontacts = array('online' => [], 'offline' => [], 'strangers' => []);
-        $contacts = \core_message\api::get_contacts_with_unread_message_count($USER->id);
-        foreach ($contacts as $contact) {
-            // Set the mode.
-            $mode = 'offline';
-            if (\core_message\helper::is_online($contact->lastaccess)) {
-                $mode = 'online';
-            }
-
-            $newcontact = array(
-                'id' => $contact->id,
-                'fullname' => fullname($contact),
-                'unread' => $contact->messagecount
-            );
-
-            $userpicture = new user_picture($contact);
-            $userpicture->size = 1; // Size f1.
-            $newcontact['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
-            $userpicture->size = 0; // Size f2.
-            $newcontact['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false);
-
-            $allcontacts[$mode][$contact->id] = $newcontact;
-        }
-
-        $strangers = \core_message\api::get_non_contacts_with_unread_message_count($USER->id);
-        foreach ($strangers as $contact) {
-            $newcontact = array(
-                'id' => $contact->id,
-                'fullname' => fullname($contact),
-                'unread' => $contact->messagecount
-            );
-
-            $userpicture = new user_picture($contact);
-            $userpicture->size = 1; // Size f1.
-            $newcontact['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);
-            $userpicture->size = 0; // Size f2.
-            $newcontact['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false);
-
-            $allcontacts['strangers'][$contact->id] = $newcontact;
-        }
+        $systemcontext = context_system::instance();
 
-        // Add noreply user and support user to the list, if they don't exist.
-        $supportuser = core_user::get_support_user();
-        if (!isset($strangers[$supportuser->id]) && !$supportuser->deleted) {
-            $supportuser->messagecount = message_count_unread_messages($USER, $supportuser);
-            if ($supportuser->messagecount > 0) {
-                $supportuser->fullname = fullname($supportuser);
-                $supportuser->unread = $supportuser->messagecount;
-                $allcontacts['strangers'][$supportuser->id] = $supportuser;
-            }
-        }
+        $params = array(
+            'userid' => $userid,
+            'limitfrom' => $limitfrom,
+            'limitnum' => $limitnum
+        );
+        $params = self::validate_parameters(self::get_user_contacts_parameters(), $params);
+        self::validate_context($systemcontext);
 
-        $noreplyuser = core_user::get_noreply_user();
-        if (!isset($strangers[$noreplyuser->id]) && !$noreplyuser->deleted) {
-            $noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser);
-            if ($noreplyuser->messagecount > 0) {
-                $noreplyuser->fullname = fullname($noreplyuser);
-                $noreplyuser->unread = $noreplyuser->messagecount;
-                $allcontacts['strangers'][$noreplyuser->id] = $noreplyuser;
-            }
+        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
+            throw new moodle_exception('You do not have permission to perform this action.');
         }
 
-        return $allcontacts;
+        return \core_message\api::get_user_contacts($params['userid'], $params['limitfrom'], $params['limitnum']);
     }
 
     /**
-     * Get contacts return description.
+     * The user contacts return structure.
      *
-     * @deprecated since 3.6
-     * @return external_description
-     * @since Moodle 2.5
+     * @return external_multiple_structure
      */
-    public static function get_contacts_returns() {
-        return new external_single_structure(
-            array(
-                'online' => new external_multiple_structure(
-                    new external_single_structure(
-                        array(
-                            'id' => new external_value(PARAM_INT, 'User ID'),
-                            'fullname' => new external_value(PARAM_NOTAGS, 'User full name'),
-                            'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL),
-                            'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL),
-                            'unread' => new external_value(PARAM_INT, 'Unread message count')
-                        )
-                    ),
-                    'List of online contacts'
-                ),
-                'offline' => new external_multiple_structure(
-                    new external_single_structure(
-                        array(
-                            'id' => new external_value(PARAM_INT, 'User ID'),
-                            'fullname' => new external_value(PARAM_NOTAGS, 'User full name'),
-                            'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL),
-                            'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL),
-                            'unread' => new external_value(PARAM_INT, 'Unread message count')
-                        )
-                    ),
-                    'List of offline contacts'
-                ),
-                'strangers' => new external_multiple_structure(
-                    new external_single_structure(
-                        array(
-                            'id' => new external_value(PARAM_INT, 'User ID'),
-                            'fullname' => new external_value(PARAM_NOTAGS, 'User full name'),
-                            'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL),
-                            'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL),
-                            'unread' => new external_value(PARAM_INT, 'Unread message count')
-                        )
-                    ),
-                    'List of users that are not in the user\'s contact list but have sent a message'
-                )
-            )
+    public static function get_user_contacts_returns() {
+        return new external_multiple_structure(
+            self::get_conversation_member_structure()
         );
     }
 
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function get_contacts_is_deprecated() {
-        return true;
-    }
-
     /**
      * Search contacts parameters description.
      *
@@ -3679,108 +2593,6 @@ class core_message_external extends external_api {
         );
     }
 
-    /**
-     * Mark all messages as read parameters description.
-     *
-     * @deprecated since 3.6
-     * @return external_function_parameters
-     * @since 3.2
-     */
-    public static function mark_all_messages_as_read_parameters() {
-        return new external_function_parameters(
-            array(
-                'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED),
-                'useridfrom' => new external_value(
-                    PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user',
-                    VALUE_DEFAULT, 0),
-            )
-        );
-    }
-
-    /**
-     * Mark all messages as read function.
-     *
-     * @deprecated since 3.6
-     * @throws invalid_parameter_exception
-     * @throws moodle_exception
-     * @param  int      $useridto       the user id who received the message
-     * @param  int      $useridfrom     the user id who send the message. -10 or -20 for no-reply or support user
-     * @return external_description
-     * @since  3.2
-     */
-    public static function mark_all_messages_as_read($useridto, $useridfrom) {
-        global $USER, $CFG;
-
-        // Check if messaging is enabled.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        $params = self::validate_parameters(
-            self::mark_all_messages_as_read_parameters(),
-            array(
-                'useridto' => $useridto,
-                'useridfrom' => $useridfrom,
-            )
-        );
-
-        $context = context_system::instance();
-        self::validate_context($context);
-
-        $useridto = $params['useridto'];
-        $useridfrom = $params['useridfrom'];
-
-        if (!empty($useridto)) {
-            if (core_user::is_real_user($useridto)) {
-                $userto = core_user::get_user($useridto, '*', MUST_EXIST);
-            } else {
-                throw new moodle_exception('invaliduser');
-            }
-        }
-
-        if (!empty($useridfrom)) {
-            // We use get_user here because the from user can be the noreply or support user.
-            $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST);
-        }
-
-        // Check if the current user is the sender/receiver or just a privileged user.
-        if ($useridto != $USER->id and $useridfrom != $USER->id and
-            // The deleteanymessage cap seems more reasonable here than readallmessages.
-             !has_capability('moodle/site:deleteanymessage', $context)) {
-            throw new moodle_exception('accessdenied', 'admin');
-        }
-
-        if ($useridfrom) {
-            if ($conversationid = \core_message\api::get_conversation_between_users([$useridto, $useridfrom])) {
-                \core_message\api::mark_all_messages_as_read($useridto, $conversationid);
-            }
-        } else {
-            \core_message\api::mark_all_messages_as_read($useridto);
-        }
-
-        return true;
-    }
-
-    /**
-     * Mark all messages as read return description.
-     *
-     * @deprecated since 3.6
-     * @return external_single_structure
-     * @since 3.2
-     */
-    public static function mark_all_messages_as_read_returns() {
-        return new external_value(PARAM_BOOL, 'True if the messages were marked read, false otherwise');
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function mark_all_messages_as_read_is_deprecated() {
-        return true;
-    }
-
     /**
      * Mark all conversation messages as read parameters description.
      *
@@ -3841,101 +2653,6 @@ class core_message_external extends external_api {
         return null;
     }
 
-    /**
-     * Returns description of method parameters.
-     *
-     * @deprecated since 3.6
-     * @return external_function_parameters
-     * @since 3.2
-     */
-    public static function delete_conversation_parameters() {
-        return new external_function_parameters(
-            array(
-                'userid' => new external_value(PARAM_INT, 'The user id of who we want to delete the conversation for'),
-                'otheruserid' => new external_value(PARAM_INT, 'The user id of the other user in the conversation'),
-            )
-        );
-    }
-
-    /**
-     * Deletes a conversation.
-     *
-     * @deprecated since 3.6
-     * @param int $userid The user id of who we want to delete the conversation for
-     * @param int $otheruserid The user id of the other user in the conversation
-     * @return array
-     * @throws moodle_exception
-     * @since 3.2
-     */
-    public static function delete_conversation($userid, $otheruserid) {
-        global $CFG;
-
-        // Check if private messaging between users is allowed.
-        if (empty($CFG->messaging)) {
-            throw new moodle_exception('disabled', 'message');
-        }
-
-        // Warnings array, it can be empty at the end but is mandatory.
-        $warnings = array();
-
-        // Validate params.
-        $params = array(
-            'userid' => $userid,
-            'otheruserid' => $otheruserid,
-        );
-        $params = self::validate_parameters(self::delete_conversation_parameters(), $params);
-
-        // Validate context.
-        $context = context_system::instance();
-        self::validate_context($context);
-
-        $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
-        core_user::require_active_user($user);
-
-        if (!$conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']])) {
-            return [];
-        }
-
-        if (\core_message\api::can_delete_conversation($user->id, $conversationid)) {
-            \core_message\api::delete_conversation_by_id($user->id, $conversationid);
-            $status = true;
-        } else {
-            throw new moodle_exception('You do not have permission to delete messages');
-        }
-
-        $results = array(
-            'status' => $status,
-            'warnings' => $warnings
-        );
-
-        return $results;
-    }
-
-    /**
-     * Returns description of method result value.
-     *
-     * @deprecated since 3.6
-     * @return external_description
-     * @since 3.2
-     */
-    public static function delete_conversation_returns() {
-        return new external_single_structure(
-            array(
-                'status' => new external_value(PARAM_BOOL, 'True if the conversation was deleted, false otherwise'),
-                'warnings' => new external_warnings()
-            )
-        );
-    }
-
-    /**
-     * Marking the method as deprecated.
-     *
-     * @return bool
-     */
-    public static function delete_conversation_is_deprecated() {
-        return true;
-    }
-
     /**
      * Returns description of method parameters.
      *
index b3cb81d..406465c 100644 (file)
@@ -65,6 +65,8 @@ define('MESSAGE_DEFAULT_TIMEOUT_POLL_IN_SECONDS', 5 * MINSECS);
 /**
  * Returns the count of unread messages for user. Either from a specific user or from all users.
  *
+ * @deprecated since 3.10
+ * TODO: MDL-69643
  * @param object $user1 the first user. Defaults to $USER
  * @param object $user2 the second user. If null this function will count all of user 1's unread messages.
  * @return int the count of $user1's unread messages
@@ -72,6 +74,9 @@ define('MESSAGE_DEFAULT_TIMEOUT_POLL_IN_SECONDS', 5 * MINSECS);
 function message_count_unread_messages($user1=null, $user2=null) {
     global $USER, $DB;
 
+    debugging('message_count_unread_messages is deprecated and no longer used',
+        DEBUG_DEVELOPER);
+
     if (empty($user1)) {
         $user1 = $USER;
     }
index bbcdd43..917ab4e 100644 (file)
@@ -54,7 +54,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         \core_message\api::mark_all_notifications_as_read($recipient->id);
         \core_message\api::mark_all_messages_as_read($recipient->id);
+
         $this->assertEquals(message_count_unread_messages($recipient), 0);
+        $this->assertDebuggingCalled();
     }
 
     public function test_mark_all_read_for_user_touser_with_fromuser() {
@@ -80,6 +82,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         \core_message\api::mark_all_messages_as_read($recipient->id, $conversationid);
 
         $this->assertEquals(message_count_unread_messages($recipient), 3);
+        $this->assertDebuggingCalled();
     }
 
     public function test_mark_all_read_for_user_touser_with_type() {
@@ -95,9 +98,11 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         \core_message\api::mark_all_notifications_as_read($recipient->id);
         $this->assertEquals(message_count_unread_messages($recipient), 3);
+        $this->assertDebuggingCalled();
 
         \core_message\api::mark_all_messages_as_read($recipient->id);
         $this->assertEquals(message_count_unread_messages($recipient), 0);
+        $this->assertDebuggingCalled();
     }
 
     /**
@@ -122,190 +127,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertEquals(1, \core_message\api::count_blocked_users());
     }
 
-    /**
-     * Tests searching users in a course.
-     */
-    public function test_search_users_in_course() {
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Second user is going to have their last access set to now, so they are online.
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'Two';
-        $user2->lastaccess = time();
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        // Block the second user.
-        \core_message\api::block_user($user1->id, $user2->id);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        // Create a course.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course';
-        $course1->shortname = 'One';
-        $course1 = $this->getDataGenerator()->create_course($course1);
-
-        // Enrol the searcher and one user in the course.
-        $this->getDataGenerator()->enrol_user($user1->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($user2->id, $course1->id);
-
-        // Perform a search.
-        $results = \core_message\api::search_users_in_course($user1->id, $course1->id, 'User');
-
-        $this->assertEquals(1, count($results));
-
-        $user = $results[0];
-        $this->assertEquals($user2->id, $user->userid);
-        $this->assertEquals(fullname($user2), $user->fullname);
-        $this->assertFalse($user->ismessaging);
-        $this->assertNull($user->lastmessage);
-        $this->assertNull($user->messageid);
-        $this->assertNull($user->isonline);
-        $this->assertFalse($user->isread);
-        $this->assertTrue($user->isblocked);
-        $this->assertNull($user->unreadcount);
-    }
-
-    /**
-     * Tests searching users.
-     */
-    public function test_search_users() {
-        global $DB;
-
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        // Set as the user performing the search.
-        $this->setUser($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User search';
-        $user2->lastname = 'Two';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User search';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'Four';
-        $user4 = self::getDataGenerator()->create_user($user4);
-
-        $user5 = new stdClass();
-        $user5->firstname = 'User search';
-        $user5->lastname = 'Five';
-        $user5 = self::getDataGenerator()->create_user($user5);
-
-        $user6 = new stdClass();
-        $user6->firstname = 'User';
-        $user6->lastname = 'Six';
-        $user6 = self::getDataGenerator()->create_user($user6);
-
-        // Create some courses.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course search';
-        $course1->shortname = 'One';
-        $course1 = $this->getDataGenerator()->create_course($course1);
-
-        $course2 = new stdClass();
-        $course2->fullname = 'Course';
-        $course2->shortname = 'Two';
-        $course2 = $this->getDataGenerator()->create_course($course2);
-
-        $course3 = new stdClass();
-        $course3->fullname = 'Course';
-        $course3->shortname = 'Three search';
-        $course3 = $this->getDataGenerator()->create_course($course3);
-
-        $course4 = new stdClass();
-        $course4->fullname = 'Course Four';
-        $course4->shortname = 'CF100';
-        $course4 = $this->getDataGenerator()->create_course($course4);
-
-        $course5 = new stdClass();
-        $course5->fullname = 'Course';
-        $course5->shortname = 'Five search';
-        $course5 = $this->getDataGenerator()->create_course($course5);
-
-        $role = $DB->get_record('role', ['shortname' => 'student']);
-        $this->getDataGenerator()->enrol_user($user1->id, $course1->id, $role->id);
-        $this->getDataGenerator()->enrol_user($user1->id, $course2->id, $role->id);
-        $this->getDataGenerator()->enrol_user($user1->id, $course3->id, $role->id);
-        $this->getDataGenerator()->enrol_user($user1->id, $course5->id, $role->id);
-
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-
-        // Remove the viewparticipants capability from one of the courses.
-        $course5context = context_course::instance($course5->id);
-        assign_capability('moodle/course:viewparticipants', CAP_PROHIBIT, $role->id, $course5context->id);
-
-        // Perform a search $CFG->messagingallusers setting enabled.
-        set_config('messagingallusers', 1);
-        list($contacts, $courses, $noncontacts) = \core_message\api::search_users($user1->id, 'search');
-
-        // Check that we retrieved the correct contacts.
-        $this->assertEquals(2, count($contacts));
-        $this->assertEquals($user3->id, $contacts[0]->userid);
-        $this->assertEquals($user2->id, $contacts[1]->userid);
-
-        // Check that we retrieved the correct courses.
-        $this->assertEquals(2, count($courses));
-        $this->assertEquals($course3->id, $courses[0]->id);
-        $this->assertEquals($course1->id, $courses[1]->id);
-
-        // Check that we retrieved the correct non-contacts.
-        $this->assertEquals(1, count($noncontacts));
-        $this->assertEquals($user5->id, $noncontacts[0]->userid);
-    }
-
-    /**
-     * Tests searching users with empty result.
-     */
-    public function test_search_users_with_empty_result() {
-
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        // Set as the user performing the search.
-        $this->setUser($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'Two';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        // Perform a search $CFG->messagingallusers setting enabled.
-        set_config('messagingallusers', 1);
-        list($contacts, $courses, $noncontacts) = \core_message\api::search_users($user1->id, 'search');
-
-        // Check results are empty.
-        $this->assertEquals(0, count($contacts));
-        $this->assertEquals(0, count($courses));
-        $this->assertEquals(0, count($noncontacts));
-    }
-
     /**
      * Tests searching for users when site-wide messaging is disabled.
      *
@@ -2350,83 +2171,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         }
     }
 
-    /**
-     * Tests retrieving contacts.
-     */
-    public function test_get_contacts() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-
-        // Set as the user.
-        $this->setUser($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'A';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'B';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'C';
-        $user4 = self::getDataGenerator()->create_user($user4);
-
-        $user5 = new stdClass();
-        $user5->firstname = 'User';
-        $user5->lastname = 'D';
-        $user5 = self::getDataGenerator()->create_user($user5);
-
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-
-        // Retrieve the contacts.
-        $contacts = \core_message\api::get_contacts($user1->id);
-
-        // Confirm the data is correct.
-        $this->assertEquals(3, count($contacts));
-        usort($contacts, ['static', 'sort_contacts']);
-
-        $contact1 = $contacts[0];
-        $contact2 = $contacts[1];
-        $contact3 = $contacts[2];
-
-        $this->assertEquals($user2->id, $contact1->userid);
-        $this->assertEmpty($contact1->useridfrom);
-        $this->assertFalse($contact1->ismessaging);
-        $this->assertNull($contact1->lastmessage);
-        $this->assertNull($contact1->messageid);
-        $this->assertNull($contact1->isonline);
-        $this->assertFalse($contact1->isread);
-        $this->assertFalse($contact1->isblocked);
-        $this->assertNull($contact1->unreadcount);
-
-        $this->assertEquals($user3->id, $contact2->userid);
-        $this->assertEmpty($contact2->useridfrom);
-        $this->assertFalse($contact2->ismessaging);
-        $this->assertNull($contact2->lastmessage);
-        $this->assertNull($contact2->messageid);
-        $this->assertNull($contact2->isonline);
-        $this->assertFalse($contact2->isread);
-        $this->assertFalse($contact2->isblocked);
-        $this->assertNull($contact2->unreadcount);
-
-        $this->assertEquals($user4->id, $contact3->userid);
-        $this->assertEmpty($contact3->useridfrom);
-        $this->assertFalse($contact3->ismessaging);
-        $this->assertNull($contact3->lastmessage);
-        $this->assertNull($contact3->messageid);
-        $this->assertNull($contact3->isonline);
-        $this->assertFalse($contact3->isread);
-        $this->assertFalse($contact3->isblocked);
-        $this->assertNull($contact3->unreadcount);
-    }
-
     /**
      * Tests retrieving user contacts.
      */
@@ -2487,56 +2231,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertTrue($contact3->iscontact);
     }
 
-    /**
-     * Tests retrieving messages.
-     */
-    public function test_get_messages() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
-        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
-        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
-        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
-
-        // Retrieve the messages.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(4, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertEquals($user1->id, $message1->useridfrom);
-        $this->assertEquals($user2->id, $message1->useridto);
-        $this->assertTrue($message1->displayblocktime);
-        $this->assertContains('Yo!', $message1->text);
-
-        $this->assertEquals($user2->id, $message2->useridfrom);
-        $this->assertEquals($user1->id, $message2->useridto);
-        $this->assertFalse($message2->displayblocktime);
-        $this->assertContains('Sup mang?', $message2->text);
-
-        $this->assertEquals($user1->id, $message3->useridfrom);
-        $this->assertEquals($user2->id, $message3->useridto);
-        $this->assertFalse($message3->displayblocktime);
-        $this->assertContains('Writing PHPUnit tests!', $message3->text);
-
-        $this->assertEquals($user2->id, $message4->useridfrom);
-        $this->assertEquals($user1->id, $message4->useridto);
-        $this->assertFalse($message4->displayblocktime);
-        $this->assertContains('Word.', $message4->text);
-    }
-
     /**
      * Tests retrieving conversation messages.
      */
@@ -3009,33 +2703,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertEquals(1, count($members));
     }
 
-    /**
-     * Tests retrieving most recent message.
-     */
-    public function test_get_most_recent_message() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
-        $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
-        $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
-        $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
-
-        // Retrieve the most recent messages.
-        $message = \core_message\api::get_most_recent_message($user1->id, $user2->id);
-
-        // Check the results are correct.
-        $this->assertEquals($user2->id, $message->useridfrom);
-        $this->assertEquals($user1->id, $message->useridto);
-        $this->assertContains('Word.', $message->text);
-    }
-
     /**
      * Tests retrieving most recent conversation message.
      */
@@ -3069,62 +2736,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertContains('Word.', $message->text);
     }
 
-    /**
-     * Tests retrieving a user's profile.
-     */
-    public function test_get_profile() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-
-        $user2 = new stdClass();
-        $user2->country = 'AU';
-        $user2->city = 'Perth';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Get the profile.
-        $profile = \core_message\api::get_profile($user1->id, $user2->id);
-
-        $this->assertEquals($user2->id, $profile->userid);
-        $this->assertEmpty($profile->email);
-        $this->assertEmpty($profile->country);
-        $this->assertEmpty($profile->city);
-        $this->assertEquals(fullname($user2), $profile->fullname);
-        $this->assertNull($profile->isonline);
-        $this->assertFalse($profile->isblocked);
-        $this->assertFalse($profile->iscontact);
-    }
-
-    /**
-     * Tests retrieving a user's profile.
-     */
-    public function test_get_profile_as_admin() {
-        // The person doing the search.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-
-        $user2 = new stdClass();
-        $user2->country = 'AU';
-        $user2->city = 'Perth';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        // Get the profile.
-        $profile = \core_message\api::get_profile($user1->id, $user2->id);
-
-        $this->assertEquals($user2->id, $profile->userid);
-        $this->assertEquals($user2->email, $profile->email);
-        $this->assertEquals($user2->country, $profile->country);
-        $this->assertEquals($user2->city, $profile->city);
-        $this->assertEquals(fullname($user2), $profile->fullname);
-        $this->assertFalse($profile->isonline);
-        $this->assertFalse($profile->isblocked);
-        $this->assertFalse($profile->iscontact);
-    }
-
     /**
      * Tests checking if a user can mark all messages as read.
      */
@@ -3195,57 +2806,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertFalse(\core_message\api::can_delete_conversation($user2->id, $conversationid));
     }
 
-    /**
-     * Tests deleting a conversation.
-     */
-    public function test_delete_conversation() {
-        global $DB;
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $m1id = $this->send_fake_message($user1, $user2, 'Yo!', 0, $time + 1);
-        $m2id = $this->send_fake_message($user2, $user1, 'Sup mang?', 0, $time + 2);
-        $m3id = $this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
-        $m4id = $this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
-
-        // Delete the conversation as user 1.
-        \core_message\api::delete_conversation($user1->id, $user2->id);
-        $this->assertDebuggingCalled();
-
-        $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC');
-        $this->assertCount(4, $muas);
-        // Sort by id.
-        ksort($muas);
-
-        $mua1 = array_shift($muas);
-        $mua2 = array_shift($muas);
-        $mua3 = array_shift($muas);
-        $mua4 = array_shift($muas);
-
-        $this->assertEquals($user1->id, $mua1->userid);
-        $this->assertEquals($m1id, $mua1->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action);
-
-        $this->assertEquals($user1->id, $mua2->userid);
-        $this->assertEquals($m2id, $mua2->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action);
-
-        $this->assertEquals($user1->id, $mua3->userid);
-        $this->assertEquals($m3id, $mua3->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action);
-
-        $this->assertEquals($user1->id, $mua4->userid);
-        $this->assertEquals($m4id, $mua4->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action);
-    }
-
     /**
      * Tests deleting a conversation by conversation id.
      */
@@ -4157,99 +3717,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         );
     }
 
-    /**
-     * Tests that when blocking messages from non-contacts is enabled that
-     * non-contacts trying to send a message return false.
-     */
-    public function test_is_user_non_contact_blocked() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Set as the first user.
-        $this->setUser($user1);
-
-        // By default, user only can be messaged by contacts and members of any of his/her courses.
-        $this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2));
-        $this->assertDebuggingCalled();
-
-        // Enable all users privacy messaging and check now the default user's preference has been set to allow receiving
-        // messages from everybody.
-        set_config('messagingallusers', true);
-        // Check that the return result is now false because any site user can contact him/her.
-        $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
-        $this->assertDebuggingCalled();
-
-        // Set the second user's preference to not receive messages from non-contacts.
-        set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, $user2->id);
-        // Check that the return result is still true (because is even more restricted).
-        $this->assertTrue(\core_message\api::is_user_non_contact_blocked($user2));
-        $this->assertDebuggingCalled();
-
-        // Add the first user as a contact for the second user.
-        \core_message\api::add_contact($user2->id, $user1->id);
-
-        // Check that the return result is now false.
-        $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
-        $this->assertDebuggingCalled();
-
-        // Set the second user's preference to receive messages from course members.
-        set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER, $user2->id);
-        // Check that the return result is still false (because $user1 is still his/her contact).
-        $this->assertFalse(\core_message\api::is_user_non_contact_blocked($user2));
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests that we return true when a user is blocked, or false
-     * if they are not blocked.
-     */
-    public function test_is_user_blocked() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Set the user.
-        $this->setUser($user1);
-
-        // User shouldn't be blocked.
-        $this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
-        $this->assertDebuggingCalled();
-
-        // Block the user.
-        \core_message\api::block_user($user1->id, $user2->id);
-
-        // User should be blocked.
-        $this->assertTrue(\core_message\api::is_user_blocked($user1->id, $user2->id));
-        $this->assertDebuggingCalled();
-
-        // Unblock the user.
-        \core_message\api::unblock_user($user1->id, $user2->id);
-        $this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests that the admin is not blocked even if someone has chosen to block them.
-     */
-    public function test_is_user_blocked_as_admin() {
-        // Create a user.
-        $user1 = self::getDataGenerator()->create_user();
-
-        // Set the user.
-        $this->setUser($user1);
-
-        // Block the admin user.
-        \core_message\api::block_user($user1->id, 2);
-
-        // Now change to the admin user.
-        $this->setAdminUser();
-
-        // As the admin you should still be able to send messages to the user.
-        $this->assertFalse(\core_message\api::is_user_blocked($user1->id));
-        $this->assertDebuggingCalled();
-    }
-
     /*
      * Tes get_message_processor api.
      */
@@ -4339,131 +3806,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertEquals(1, $status);
     }
 
-    /**
-     * Test retrieving messages by providing a minimum timecreated value.
-     */
-    public function test_get_messages_time_from_only() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1);
-        $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2);
-        $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3);
-        $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4);
-
-        // Retrieve the messages from $time, which should be all of them.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(4, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertContains('Message 1', $message1->text);
-        $this->assertContains('Message 2', $message2->text);
-        $this->assertContains('Message 3', $message3->text);
-        $this->assertContains('Message 4', $message4->text);
-
-        // Retrieve the messages from $time + 3, which should only be the 2 last messages.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time + 3);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(2, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-
-        $this->assertContains('Message 3', $message1->text);
-        $this->assertContains('Message 4', $message2->text);
-    }
-
-    /**
-     * Test retrieving messages by providing a maximum timecreated value.
-     */
-    public function test_get_messages_time_to_only() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1);
-        $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2);
-        $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3);
-        $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4);
-
-        // Retrieve the messages up until $time + 4, which should be all of them.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', 0, $time + 4);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(4, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertContains('Message 1', $message1->text);
-        $this->assertContains('Message 2', $message2->text);
-        $this->assertContains('Message 3', $message3->text);
-        $this->assertContains('Message 4', $message4->text);
-
-        // Retrieve the messages up until $time + 2, which should be the first two.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', 0, $time + 2);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(2, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-
-        $this->assertContains('Message 1', $message1->text);
-        $this->assertContains('Message 2', $message2->text);
-    }
-
-    /**
-     * Test retrieving messages by providing a minimum and maximum timecreated value.
-     */
-    public function test_get_messages_time_from_and_to() {
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = 1;
-        $this->send_fake_message($user1, $user2, 'Message 1', 0, $time + 1);
-        $this->send_fake_message($user2, $user1, 'Message 2', 0, $time + 2);
-        $this->send_fake_message($user1, $user2, 'Message 3', 0, $time + 3);
-        $this->send_fake_message($user2, $user1, 'Message 4', 0, $time + 4);
-
-        // Retrieve the messages from $time + 2 up until $time + 3, which should be 2nd and 3rd message.
-        $messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 0, 'timecreated ASC', $time + 2, $time + 3);
-
-        // Confirm the message data is correct.
-        $this->assertEquals(2, count($messages));
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-
-        $this->assertContains('Message 2', $message1->text);
-        $this->assertContains('Message 3', $message2->text);
-    }
-
     /**
      * Test returning blocked users.
      */
@@ -4493,6 +3835,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
     /**
      * Test returning contacts with unread message count.
+     * MDL-69643
      */
     public function test_get_contacts_with_unread_message_count() {
         global $DB;
@@ -4522,6 +3865,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the contacts and the unread message count.
         $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(2, $messages);
@@ -4543,6 +3887,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the contacts and the unread message count.
         $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(2, $messages);
@@ -4566,6 +3911,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the contacts and the unread message count.
         $messages = \core_message\api::get_contacts_with_unread_message_count($user1->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(1, $messages);
@@ -4578,6 +3924,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         \core_message\api::mark_message_as_read($user1->id, $m);
 
         $messages = \core_message\api::get_contacts_with_unread_message_count($user1->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(1, $messages);
@@ -4600,6 +3947,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Check we get the correct message count.
         $messages = \core_message\api::get_contacts_with_unread_message_count($user2->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(1, $messages);
@@ -4612,6 +3960,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
     /**
      * Test returning non-contacts with unread message count.
+     * MDL-69643
      */
     public function test_get_non_contacts_with_unread_message_count() {
         global $DB;
@@ -4639,8 +3988,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         // Send a message that should never be included as the user is a contact.
         $this->send_fake_message($user4, $user2);
 
+
         // Get the non-contacts and the unread message count.
         $messages = \core_message\api::get_non_contacts_with_unread_message_count($user2->id);
+        $this->assertDebuggingCalled();
 
         // Check we get the correct message count.
         ksort($messages);
@@ -4660,6 +4011,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the non-contacts and the unread message count.
         $messages = \core_message\api::get_non_contacts_with_unread_message_count($user2->id);
+        $this->assertDebuggingCalled();
 
         // Check the marked message is not returned in the message count.
         ksort($messages);
@@ -4681,6 +4033,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the non-contacts and the unread message count.
         $messages = \core_message\api::get_non_contacts_with_unread_message_count($user1->id);
+        $this->assertDebuggingCalled();
 
         // Confirm the size is correct.
         $this->assertCount(1, $messages);
@@ -4694,6 +4047,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
 
         // Get the non-contacts and the unread message count.
         $messages = \core_message\api::get_non_contacts_with_unread_message_count($user1->id);
+        $this->assertDebuggingCalled();
 
         // Check the marked message is not returned in the message count.
         $this->assertCount(1, $messages);
@@ -4781,20 +4135,6 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $this->assertFalse(\core_message\api::get_conversation_between_users([$user1->id, $user2->id]));
     }
 
-    /**
-     * Test we can return a conversation that exists between users.
-     */
-    public function test_get_conversation_between_users_with_existing_conversation() {
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        $conversationid = \core_message\api::create_conversation_between_users([$user1->id, $user2->id]);
-        $this->assertDebuggingCalled();
-
-        $this->assertEquals($conversationid,
-            \core_message\api::get_conversation_between_users([$user1->id, $user2->id]));
-    }
-
     /**
      * Test count_conversation_members for non existing conversation.
      */
index 8960bed..00a6b19 100644 (file)
@@ -458,8 +458,8 @@ class core_message_events_testcase extends core_message_messagelib_testcase {
 
         // Trigger and capture the event.
         $sink = $this->redirectEvents();
-        \core_message\api::delete_conversation($user1->id, $user2->id);
-        $this->assertDebuggingCalled();
+        $conversationid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id]);
+        \core_message\api::delete_conversation_by_id($user1->id, $conversationid);
         $events = $sink->get_events();
 
         // Get the user actions for the messages deleted by that user.
index 9a61444..35f3150 100644 (file)
@@ -338,39 +338,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         core_message_external::send_instant_messages($messages);
     }
 
-    /**
-     * Test create_contacts.
-     *
-     * TODO: MDL-63261
-     */
-    public function test_create_contacts() {
-        $this->resetAfterTest(true);
-
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-        $user5 = self::getDataGenerator()->create_user();
-        $this->setUser($user1);
-
-        // Adding a contact who is already a contact.
-        $return = core_message_external::create_contacts(array($user2->id));
-        $return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
-        $this->assertEquals(array(), $return);
-
-        // Adding multiple contacts.
-        $return = core_message_external::create_contacts(array($user3->id, $user4->id));
-        $return = external_api::clean_returnvalue(core_message_external::create_contacts_returns(), $return);
-        $this->assertEquals(array(), $return);
-
-        // Note: We should add real user checks in api L:2656.
-
-        // Try to add a contact to another user, should throw an exception.
-        // All assertions must be added before this point.
-        $this->expectException('required_capability_exception');
-        core_message_external::create_contacts(array($user2->id), $user3->id);
-    }
-
     /**
      * Test delete_contacts.
      */
@@ -416,110 +383,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         core_message_external::delete_contacts(array($user2->id), $user3->id);
     }
 
-    /**
-     * Test block_contacts.
-     */
-    public function test_block_contacts() {
-        $this->resetAfterTest(true);
-
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-        $user5 = self::getDataGenerator()->create_user();
-        $this->setUser($user1);
-
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-        \core_message\api::add_contact($user1->id, $user5->id);
-
-        // Blocking a contact who is already a contact.
-        $return = core_message_external::block_contacts(array($user2->id));
-        $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
-        $this->assertEquals(array(array(
-            'item' => 'user',
-            'itemid' => $user2->id,
-            'warningcode' => 'contactnotblocked',
-            'message' => 'The contact could not be blocked'
-        )), $return);
-
-        // Blocking multiple contacts.
-        $return = core_message_external::block_contacts(array($user3->id, $user4->id));
-        $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
-        $this->assertEquals(array(
-            array(
-                'item' => 'user',
-                'itemid' => $user3->id,
-                'warningcode' => 'contactnotblocked',
-                'message' => 'The contact could not be blocked'
-            ),
-            array(
-                'item' => 'user',
-                'itemid' => $user4->id,
-                'warningcode' => 'contactnotblocked',
-                'message' => 'The contact could not be blocked'
-            )
-        ), $return);
-
-        // Blocking a non-existing user.
-        $return = core_message_external::block_contacts(array(99999));
-        $return = external_api::clean_returnvalue(core_message_external::block_contacts_returns(), $return);
-        $this->assertCount(1, $return);
-        $return = array_pop($return);
-        $this->assertEquals($return['warningcode'], 'contactnotblocked');
-        $this->assertEquals($return['itemid'], 99999);
-
-        // Try to block a contact of another user contact list, should throw an exception.
-        // All assertions must be added before this point.
-        $this->expectException('required_capability_exception');
-        core_message_external::block_contacts(array($user2->id), $user3->id);
-    }
-
-    /**
-     * Test unblock_contacts.
-     */
-    public function test_unblock_contacts() {
-        $this->resetAfterTest(true);
-
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-        $user5 = self::getDataGenerator()->create_user();
-        $user6 = self::getDataGenerator()->create_user();
-        $this->setUser($user1);
-
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-        \core_message\api::add_contact($user1->id, $user5->id);
-        \core_message\api::add_contact($user1->id, $user6->id);
-
-        // Removing a non-contact.
-        $return = core_message_external::unblock_contacts(array($user2->id));
-        $this->assertNull($return);
-
-        // Removing one contact.
-        $return = core_message_external::unblock_contacts(array($user3->id));
-        $this->assertNull($return);
-
-        // Removing multiple contacts.
-        $return = core_message_external::unblock_contacts(array($user4->id, $user5->id));
-        $this->assertNull($return);
-
-        // Removing contact from unexisting user.
-        $return = core_message_external::unblock_contacts(array(99999));
-        $this->assertNull($return);
-
-        // Removing mixed valid and invalid data.
-        $return = core_message_external::unblock_contacts(array($user6->id, 99999));
-        $this->assertNull($return);
-
-        // Try to unblock a contact of another user contact list, should throw an exception.
-        // All assertions must be added before this point.
-        $this->expectException('required_capability_exception');
-        core_message_external::unblock_contacts(array($user2->id), $user3->id);
-    }
-
     /**
      * Test getting contact requests.
      */
@@ -1323,70 +1186,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         core_message_external::unblock_user($user1->id, $user2->id);
     }
 
-    /**
-     * Test get_contacts.
-     */
-    public function test_get_contacts() {
-        $this->resetAfterTest(true);
-
-        $user1 = self::getDataGenerator()->create_user();
-        $user_stranger = self::getDataGenerator()->create_user();
-        $user_offline1 = self::getDataGenerator()->create_user();
-        $user_offline2 = self::getDataGenerator()->create_user();
-        $user_offline3 = self::getDataGenerator()->create_user();
-        $user_online = new stdClass();
-        $user_online->lastaccess = time();
-        $user_online = self::getDataGenerator()->create_user($user_online);
-        $user_blocked = self::getDataGenerator()->create_user();
-        $noreplyuser = core_user::get_user(core_user::NOREPLY_USER);
-
-        // Login as user1.
-        $this->setUser($user1);
-        \core_message\api::add_contact($user1->id, $user_offline1->id);
-        \core_message\api::add_contact($user1->id, $user_offline2->id);
-        \core_message\api::add_contact($user1->id, $user_offline3->id);
-        \core_message\api::add_contact($user1->id, $user_online->id);
-
-        // User_stranger sends a couple of messages to user1.
-        $this->send_message($user_stranger, $user1, 'Hello there!');
-        $this->send_message($user_stranger, $user1, 'How you goin?');
-        $this->send_message($user_stranger, $user1, 'Cya!');
-        $this->send_message($noreplyuser, $user1, 'I am not a real user');
-
-        // User_blocked sends a message to user1.
-        $this->send_message($user_blocked, $user1, 'Here, have some spam.');
-
-        // Retrieve the contacts of the user.
-        $this->setUser($user1);
-        $contacts = core_message_external::get_contacts();
-        $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts);
-        $this->assertCount(3, $contacts['offline']);
-        $this->assertCount(1, $contacts['online']);
-        $this->assertCount(3, $contacts['strangers']);
-        core_message_external::block_contacts(array($user_blocked->id));
-        $contacts = core_message_external::get_contacts();
-        $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts);
-        $this->assertCount(3, $contacts['offline']);
-        $this->assertCount(1, $contacts['online']);
-        $this->assertCount(2, $contacts['strangers']);
-
-        // Checking some of the fields returned.
-        $stranger = array_pop($contacts['strangers']);
-
-        $this->assertEquals(core_user::NOREPLY_USER, $stranger['id']);
-        $this->assertEquals(1, $stranger['unread']);
-
-        // Check that deleted users are not returned.
-        delete_user($user_offline1);
-        delete_user($user_stranger);
-        delete_user($user_online);
-        $contacts = core_message_external::get_contacts();
-        $contacts = external_api::clean_returnvalue(core_message_external::get_contacts_returns(), $contacts);
-        $this->assertCount(2, $contacts['offline']);
-        $this->assertCount(0, $contacts['online']);
-        $this->assertCount(1, $contacts['strangers']);
-    }
-
     /**
      * Test search_contacts.
      * @expectedException moodle_exception
@@ -1792,7 +1591,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         $this->assertCount(0, $blockedusers['users']);
 
         // Block the $userblocked and retrieve again the list.
-        core_message_external::block_contacts(array($userblocked->id));
+        \core_message\api::block_user($user1->id, $userblocked->id);
         $blockedusers = core_message_external::get_blocked_users($user1->id);
         $blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
         $this->assertCount(1, $blockedusers['users']);
@@ -2185,536 +1984,140 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
     }
 
     /**
-     * Tests searching users in a course.
+     * Tests searching for users when site-wide messaging is disabled.
+     *
+     * This test verifies that any contacts are returned, as well as any non-contacts whose profile we can view.
+     * If checks this by placing some users in the same course, where default caps would permit a user to view another user's
+     * profile.
      */
-    public function test_data_for_messagearea_search_users_in_course() {
-        $this->resetAfterTest(true);
+    public function test_message_search_users_messagingallusers_disabled() {
+        global $DB;
+        $this->resetAfterTest();
 
         // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Set the second user's status to online by setting their last access to now.
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'Two';
-        $user2->lastaccess = time();
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        // Block the second user.
-        \core_message\api::block_user($user1->id, $user2->id);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
+        $users = [];
+        foreach (range(1, 8) as $i) {
+            $user = new stdClass();
+            $user->firstname = ($i == 4) ? 'User' : 'User search'; // Ensure the fourth user won't match the search term.
+            $user->lastname = $i;
+            $user = $this->getDataGenerator()->create_user($user);
+            $users[$i] = $user;
+        }
 
-        // Create a course.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course';
-        $course1->shortname = 'One';
+        // Enrol a few users in the same course, but leave them as non-contacts.
         $course1 = $this->getDataGenerator()->create_course();
+        $course2 = $this->getDataGenerator()->create_course();
 
-        // Enrol the user we are doing the search for and one user in the course.
-        $this->getDataGenerator()->enrol_user($user1->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($user2->id, $course1->id);
-
-        // Perform a search.
-        $result = core_message_external::data_for_messagearea_search_users_in_course($user1->id, $course1->id, 'User');
-
-        // We need to execute the return values cleaning process to simulate the web service.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_in_course_returns(),
-            $result);
+        $this->setAdminUser();
+        $this->getDataGenerator()->enrol_user($users[1]->id, $course1->id);
+        $this->getDataGenerator()->enrol_user($users[6]->id, $course1->id);
+        $this->getDataGenerator()->enrol_user($users[7]->id, $course1->id);
 
-        // Check that we only retrieved a user that was enrolled, and that the user performing the search was not returned.
-        $users = $result['contacts'];
-        $this->assertCount(1, $users);
+        // Add some other users as contacts.
+        \core_message\api::add_contact($users[1]->id, $users[2]->id);
+        \core_message\api::add_contact($users[3]->id, $users[1]->id);
+        \core_message\api::add_contact($users[1]->id, $users[4]->id);
 
-        $user = $users[0];
-        $this->assertEquals($user2->id, $user['userid']);
-        $this->assertEquals(fullname($user2), $user['fullname']);
-        $this->assertFalse($user['ismessaging']);
-        $this->assertFalse($user['sentfromcurrentuser']);
-        $this->assertNull($user['lastmessage']);
-        $this->assertNull($user['messageid']);
-        $this->assertNull($user['isonline']);
-        $this->assertFalse($user['isread']);
-        $this->assertTrue($user['isblocked']);
-        $this->assertNull($user['unreadcount']);
-    }
+        // Enrol a user as a teacher in the course, and make the teacher role a course contact role.
+        $this->getDataGenerator()->enrol_user($users[8]->id, $course2->id, 'editingteacher');
+        $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
+        set_config('coursecontact', $teacherrole->id);
 
-    /**
-     * Tests searching users in course as another user.
-     */
-    public function test_data_for_messagearea_search_users_in_course_as_other_user() {
-        $this->resetAfterTest(true);
+        // Create individual conversations between some users, one contact and one non-contact.
+        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
+            [$users[1]->id, $users[2]->id]);
+        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
+            [$users[6]->id, $users[1]->id]);
 
-        // The person doing the search for another user.
-        $this->setAdminUser();
+        // Create a group conversation between 4 users, including a contact and a non-contact.
+        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
+            [$users[1]->id, $users[2]->id, $users[4]->id, $users[7]->id], 'Project chat');
 
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
+        // Set as the user performing the search.
+        $this->setUser($users[1]);
 
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'Two';
-        $user2 = self::getDataGenerator()->create_user($user2);
+        // Perform a search with $CFG->messagingallusers disabled.
+        set_config('messagingallusers', 0);
+        $result = core_message_external::message_search_users($users[1]->id, 'search');
+        $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
 
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
+        // Confirm that we returns contacts and non-contacts.
+        $this->assertArrayHasKey('contacts', $result);
+        $this->assertArrayHasKey('noncontacts', $result);
+        $contacts = $result['contacts'];
+        $noncontacts = $result['noncontacts'];
 
-        // Create a course.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course';
-        $course1->shortname = 'One';
-        $course1 = $this->getDataGenerator()->create_course();
+        // Check that we retrieved the correct contacts.
+        $this->assertCount(2, $contacts);
+        $this->assertEquals($users[2]->id, $contacts[0]['id']);
+        $this->assertEquals($users[3]->id, $contacts[1]['id']);
 
-        // Enrol the user we are doing the search for and one user in the course.
-        $this->getDataGenerator()->enrol_user($user1->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($user2->id, $course1->id);
+        // Verify the correct conversations were returned for the contacts.
+        $this->assertCount(2, $contacts[0]['conversations']);
+        // We can't rely on the ordering of conversations within the results, so sort by id first.
+        usort($contacts[0]['conversations'], function($a, $b) {
+            return $a['id'] < $b['id'];
+        });
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
 
-        // Perform a search.
-        $result = core_message_external::data_for_messagearea_search_users_in_course($user1->id, $course1->id, 'User');
+        $this->assertCount(0, $contacts[1]['conversations']);
 
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_in_course_returns(),
-            $result);
+        // Check that we retrieved the correct non-contacts.
+        // When site wide messaging is disabled, we expect to see only those users who we share a course with and whose profiles
+        // are visible in that course. This excludes users like course contacts.
+        $this->assertCount(3, $noncontacts);
+        // Self-conversation first.
+        $this->assertEquals($users[1]->id, $noncontacts[0]['id']);
+        $this->assertEquals($users[6]->id, $noncontacts[1]['id']);
+        $this->assertEquals($users[7]->id, $noncontacts[2]['id']);
 
-        // Check that we got the user enrolled, and that the user we are performing the search on behalf of was not returned.
-        $users = $result['contacts'];
-        $this->assertCount(1, $users);
+        // Verify the correct conversations were returned for the non-contacts.
+        $this->assertCount(1, $noncontacts[1]['conversations']);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $noncontacts[1]['conversations'][0]['type']);
 
-        $user = $users[0];
-        $this->assertEquals($user2->id, $user['userid']);
-        $this->assertEquals(fullname($user2), $user['fullname']);
-        $this->assertFalse($user['ismessaging']);
-        $this->assertFalse($user['sentfromcurrentuser']);
-        $this->assertNull($user['lastmessage']);
-        $this->assertNull($user['messageid']);
-        $this->assertFalse($user['isonline']);
-        $this->assertFalse($user['isread']);
-        $this->assertFalse($user['isblocked']);
-        $this->assertNull($user['unreadcount']);
+        $this->assertCount(1, $noncontacts[2]['conversations']);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $noncontacts[2]['conversations'][0]['type']);
     }
 
     /**
-     * Tests searching users in course as another user without the proper capabilities.
+     * Tests searching for users when site-wide messaging is enabled.
+     *
+     * This test verifies that any contacts are returned, as well as any non-contacts, regardless of whether the searching user
+     * can view their respective profile.
      */
-    public function test_data_for_messagearea_search_users_in_course_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
+    public function test_message_search_users_messagingallusers_enabled() {
+        global $DB;
+        $this->resetAfterTest();
 
         // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
+        $users = [];
+        foreach (range(1, 9) as $i) {
+            $user = new stdClass();
+            $user->firstname = ($i == 4) ? 'User' : 'User search'; // Ensure the fourth user won't match the search term.
+            $user->lastname = $i;
+            $user = $this->getDataGenerator()->create_user($user);
+            $users[$i] = $user;
+        }
 
-        // The person doing the search for another user.
-        $this->setUser($user1);
+        // Enrol a few users in the same course, but leave them as non-contacts.
+        $course1 = $this->getDataGenerator()->create_course();
+        $course2 = $this->getDataGenerator()->create_course();
 
-        // Create a course.
-        $course = $this->getDataGenerator()->create_course();
+        $this->setAdminUser();
+        $this->getDataGenerator()->enrol_user($users[1]->id, $course1->id);
+        $this->getDataGenerator()->enrol_user($users[6]->id, $course1->id);
+        $this->getDataGenerator()->enrol_user($users[7]->id, $course1->id);
 
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_users_in_course($user2->id, $course->id, 'User');
-        $this->assertDebuggingCalled();
-    }
+        // Add some other users as contacts.
+        \core_message\api::add_contact($users[1]->id, $users[2]->id);
+        \core_message\api::add_contact($users[3]->id, $users[1]->id);
+        \core_message\api::add_contact($users[1]->id, $users[4]->id);
 
-    /**
-     * Tests searching users in course with messaging disabled.
-     */
-    public function test_data_for_messagearea_search_users_in_course_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS..
-        $user = self::getDataGenerator()->create_user();
-        $course = $this->getDataGenerator()->create_course();
-
-        // The person doing the search for another user.
-        $this->setUser($user);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_users_in_course($user->id, $course->id, 'User');
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests searching users.
-     */
-    public function test_data_for_messagearea_search_users() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        // Set as the user performing the search.
-        $this->setUser($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User search';
-        $user2->lastname = 'Two';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User search';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'Four';
-        $user4 = self::getDataGenerator()->create_user($user4);
-
-        $user5 = new stdClass();
-        $user5->firstname = 'User search';
-        $user5->lastname = 'Five';
-        $user5 = self::getDataGenerator()->create_user($user5);
-
-        $user6 = new stdClass();
-        $user6->firstname = 'User';
-        $user6->lastname = 'Six';
-        $user6 = self::getDataGenerator()->create_user($user6);
-
-        // Create some courses.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course search';
-        $course1->shortname = 'One';
-        $course1 = $this->getDataGenerator()->create_course($course1);
-
-        $course2 = new stdClass();
-        $course2->fullname = 'Course';
-        $course2->shortname = 'Two';
-        $course2 = $this->getDataGenerator()->create_course($course2);
-
-        $course3 = new stdClass();
-        $course3->fullname = 'Course';
-        $course3->shortname = 'Three search';
-        $course3 = $this->getDataGenerator()->create_course($course3);
-
-        $course4 = new stdClass();
-        $course4->fullname = 'Course Four';
-        $course4->shortname = 'CF100';
-        $course4 = $this->getDataGenerator()->create_course($course4);
-
-        $this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'student');
-        $this->getDataGenerator()->enrol_user($user1->id, $course2->id, 'student');
-        $this->getDataGenerator()->enrol_user($user1->id, $course3->id, 'student');
-
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-
-        // Perform a search $CFG->messagingallusers setting enabled.
-        set_config('messagingallusers', 1);
-        $result = core_message_external::data_for_messagearea_search_users($user1->id, 'search');
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_returns(),
-            $result);
-
-        // Confirm that we returns contacts, courses and non-contacts.
-        $contacts = $result['contacts'];
-        $courses = $result['courses'];
-        $noncontacts = $result['noncontacts'];
-
-        // Check that we retrieved the correct contacts.
-        $this->assertCount(2, $contacts);
-        $this->assertEquals($user3->id, $contacts[0]['userid']);
-        $this->assertEquals($user2->id, $contacts[1]['userid']);
-
-        // Check that we retrieved the correct courses.
-        $this->assertCount(2, $courses);
-        $this->assertEquals($course3->id, $courses[0]['id']);
-        $this->assertEquals($course1->id, $courses[1]['id']);
-
-        // Check that we retrieved the correct non-contacts.
-        $this->assertCount(1, $noncontacts);
-        $this->assertEquals($user5->id, $noncontacts[0]['userid']);
-    }
-
-    /**
-     * Tests searching users as another user.
-     */
-    public function test_data_for_messagearea_search_users_as_other_user() {
-        $this->resetAfterTest(true);
-
-        // The person doing the search.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = new stdClass();
-        $user1->firstname = 'User';
-        $user1->lastname = 'One';
-        $user1 = self::getDataGenerator()->create_user($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User search';
-        $user2->lastname = 'Two';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User search';
-        $user3->lastname = 'Three';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'Four';
-        $user4 = self::getDataGenerator()->create_user($user4);
-
-        $user5 = new stdClass();
-        $user5->firstname = 'User search';
-        $user5->lastname = 'Five';
-        $user5 = self::getDataGenerator()->create_user($user5);
-
-        $user6 = new stdClass();
-        $user6->firstname = 'User';
-        $user6->lastname = 'Six';
-        $user6 = self::getDataGenerator()->create_user($user6);
-
-        // Create some courses.
-        $course1 = new stdClass();
-        $course1->fullname = 'Course search';
-        $course1->shortname = 'One';
-        $course1 = $this->getDataGenerator()->create_course($course1);
-
-        $course2 = new stdClass();
-        $course2->fullname = 'Course';
-        $course2->shortname = 'Two';
-        $course2 = $this->getDataGenerator()->create_course($course2);
-
-        $course3 = new stdClass();
-        $course3->fullname = 'Course';
-        $course3->shortname = 'Three search';
-        $course3 = $this->getDataGenerator()->create_course($course3);
-
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-
-        // Perform a search $CFG->messagingallusers setting enabled.
-        set_config('messagingallusers', 1);
-        $result = core_message_external::data_for_messagearea_search_users($user1->id, 'search');
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_users_returns(),
-            $result);
-
-        // Confirm that we returns contacts, courses and non-contacts.
-        $contacts = $result['contacts'];
-        $courses = $result['courses'];
-        $noncontacts = $result['noncontacts'];
-
-        // Check that we retrieved the correct contacts.
-        $this->assertCount(2, $contacts);
-        $this->assertEquals($user3->id, $contacts[0]['userid']);
-        $this->assertEquals($user2->id, $contacts[1]['userid']);
-
-        // Check that we retrieved the correct courses.
-        $this->assertCount(0, $courses);
-
-        // Check that we retrieved the correct non-contacts.
-        $this->assertCount(1, $noncontacts);
-        $this->assertEquals($user5->id, $noncontacts[0]['userid']);
-    }
-
-    /**
-     * Tests searching users as another user without the proper capabilities.
-     */
-    public function test_data_for_messagearea_search_users_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search for another user.
-        $this->setUser($user1);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_users($user2->id, 'User');
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests searching users with messaging disabled.
-     */
-    public function test_data_for_messagearea_search_users_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS.
-        $user = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_users($user->id, 'User');
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests searching for users when site-wide messaging is disabled.
-     *
-     * This test verifies that any contacts are returned, as well as any non-contacts whose profile we can view.
-     * If checks this by placing some users in the same course, where default caps would permit a user to view another user's
-     * profile.
-     */
-    public function test_message_search_users_messagingallusers_disabled() {
-        global $DB;
-        $this->resetAfterTest();
-
-        // Create some users.
-        $users = [];
-        foreach (range(1, 8) as $i) {
-            $user = new stdClass();
-            $user->firstname = ($i == 4) ? 'User' : 'User search'; // Ensure the fourth user won't match the search term.
-            $user->lastname = $i;
-            $user = $this->getDataGenerator()->create_user($user);
-            $users[$i] = $user;
-        }
-
-        // Enrol a few users in the same course, but leave them as non-contacts.
-        $course1 = $this->getDataGenerator()->create_course();
-        $course2 = $this->getDataGenerator()->create_course();
-
-        $this->setAdminUser();
-        $this->getDataGenerator()->enrol_user($users[1]->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($users[6]->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($users[7]->id, $course1->id);
-
-        // Add some other users as contacts.
-        \core_message\api::add_contact($users[1]->id, $users[2]->id);
-        \core_message\api::add_contact($users[3]->id, $users[1]->id);
-        \core_message\api::add_contact($users[1]->id, $users[4]->id);
-
-        // Enrol a user as a teacher in the course, and make the teacher role a course contact role.
-        $this->getDataGenerator()->enrol_user($users[8]->id, $course2->id, 'editingteacher');
-        $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
-        set_config('coursecontact', $teacherrole->id);
-
-        // Create individual conversations between some users, one contact and one non-contact.
-        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
-            [$users[1]->id, $users[2]->id]);
-        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
-            [$users[6]->id, $users[1]->id]);
-
-        // Create a group conversation between 4 users, including a contact and a non-contact.
-        \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
-            [$users[1]->id, $users[2]->id, $users[4]->id, $users[7]->id], 'Project chat');
-
-        // Set as the user performing the search.
-        $this->setUser($users[1]);
-
-        // Perform a search with $CFG->messagingallusers disabled.
-        set_config('messagingallusers', 0);
-        $result = core_message_external::message_search_users($users[1]->id, 'search');
-        $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
-
-        // Confirm that we returns contacts and non-contacts.
-        $this->assertArrayHasKey('contacts', $result);
-        $this->assertArrayHasKey('noncontacts', $result);
-        $contacts = $result['contacts'];
-        $noncontacts = $result['noncontacts'];
-
-        // Check that we retrieved the correct contacts.
-        $this->assertCount(2, $contacts);
-        $this->assertEquals($users[2]->id, $contacts[0]['id']);
-        $this->assertEquals($users[3]->id, $contacts[1]['id']);
-
-        // Verify the correct conversations were returned for the contacts.
-        $this->assertCount(2, $contacts[0]['conversations']);
-        // We can't rely on the ordering of conversations within the results, so sort by id first.
-        usort($contacts[0]['conversations'], function($a, $b) {
-            return $a['id'] < $b['id'];
-        });
-        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $contacts[0]['conversations'][0]['type']);
-        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $contacts[0]['conversations'][1]['type']);
-
-        $this->assertCount(0, $contacts[1]['conversations']);
-
-        // Check that we retrieved the correct non-contacts.
-        // When site wide messaging is disabled, we expect to see only those users who we share a course with and whose profiles
-        // are visible in that course. This excludes users like course contacts.
-        $this->assertCount(3, $noncontacts);
-        // Self-conversation first.
-        $this->assertEquals($users[1]->id, $noncontacts[0]['id']);
-        $this->assertEquals($users[6]->id, $noncontacts[1]['id']);
-        $this->assertEquals($users[7]->id, $noncontacts[2]['id']);
-
-        // Verify the correct conversations were returned for the non-contacts.
-        $this->assertCount(1, $noncontacts[1]['conversations']);
-        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $noncontacts[1]['conversations'][0]['type']);
-
-        $this->assertCount(1, $noncontacts[2]['conversations']);
-        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, $noncontacts[2]['conversations'][0]['type']);
-    }
-
-    /**
-     * Tests searching for users when site-wide messaging is enabled.
-     *
-     * This test verifies that any contacts are returned, as well as any non-contacts, regardless of whether the searching user
-     * can view their respective profile.
-     */
-    public function test_message_search_users_messagingallusers_enabled() {
-        global $DB;
-        $this->resetAfterTest();
-
-        // Create some users.
-        $users = [];
-        foreach (range(1, 9) as $i) {
-            $user = new stdClass();
-            $user->firstname = ($i == 4) ? 'User' : 'User search'; // Ensure the fourth user won't match the search term.
-            $user->lastname = $i;
-            $user = $this->getDataGenerator()->create_user($user);
-            $users[$i] = $user;
-        }
-
-        // Enrol a few users in the same course, but leave them as non-contacts.
-        $course1 = $this->getDataGenerator()->create_course();
-        $course2 = $this->getDataGenerator()->create_course();
-
-        $this->setAdminUser();
-        $this->getDataGenerator()->enrol_user($users[1]->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($users[6]->id, $course1->id);
-        $this->getDataGenerator()->enrol_user($users[7]->id, $course1->id);
-
-        // Add some other users as contacts.
-        \core_message\api::add_contact($users[1]->id, $users[2]->id);
-        \core_message\api::add_contact($users[3]->id, $users[1]->id);
-        \core_message\api::add_contact($users[1]->id, $users[4]->id);
-
-        // Enrol a user as a teacher in the course, and make the teacher role a course contact role.
-        $this->getDataGenerator()->enrol_user($users[9]->id, $course2->id, 'editingteacher');
-        $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
-        set_config('coursecontact', $teacherrole->id);
+        // Enrol a user as a teacher in the course, and make the teacher role a course contact role.
+        $this->getDataGenerator()->enrol_user($users[9]->id, $course2->id, 'editingteacher');
+        $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
+        set_config('coursecontact', $teacherrole->id);
 
         // Create individual conversations between some users, one contact and one non-contact.
         \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
@@ -2934,615 +2337,214 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
 
         // Add some other users as contacts.
         \core_message\api::add_contact($users[1]->id, $users[2]->id);
-        \core_message\api::add_contact($users[3]->id, $users[1]->id);
-        \core_message\api::add_contact($users[1]->id, $users[4]->id);
-
-        // Set as the user performing the search.
-        $this->setUser($users[1]);
-
-        // Grant the authenticated user role the capability 'user:viewdetails' at site context.
-        $authenticatedrole = $DB->get_record('role', ['shortname' => 'user'], '*', MUST_EXIST);
-        assign_capability('moodle/user:viewdetails', CAP_ALLOW, $authenticatedrole->id, context_system::instance());
-
-        // Perform a search with $CFG->messagingallusers disabled.
-        set_config('messagingallusers', 0);
-        $result = core_message_external::message_search_users($users[1]->id, 'search');
-        $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
-        $contacts = $result['contacts'];
-        $noncontacts = $result['noncontacts'];
-
-        // Check that we retrieved the correct contacts.
-        $this->assertCount(2, $contacts);
-        $this->assertEquals($users[2]->id, $contacts[0]['id']);
-        $this->assertEquals($users[3]->id, $contacts[1]['id']);
-
-        // Check that we retrieved the correct non-contacts.
-        // Site-wide messaging is disabled, so we expect to be able to search for any users whose profile we can view.
-        // Consider first conversations is self-conversation.
-        $this->assertCount(3, $noncontacts);
-        $this->assertEquals($users[1]->id, $noncontacts[0]['id']);
-        $this->assertEquals($users[6]->id, $noncontacts[1]['id']);
-        $this->assertEquals($users[7]->id, $noncontacts[2]['id']);
-    }
-
-    /**
-     * Tests searching users as another user without the 'moodle/user:viewdetails' capability.
-     */
-    public function test_message_search_users_without_cap() {
-        $this->resetAfterTest();
-
-        // Create some users.
-        $user1 = $this->getDataGenerator()->create_user();
-        $user2 = $this->getDataGenerator()->create_user();
-
-        // The person doing the search for another user.
-        $this->setUser($user1);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::message_search_users($user2->id, 'User');
-        $this->assertDebuggingCalled();
-    }
-
-    /**
-     * Tests searching users with messaging disabled.
-     */
-    public function test_message_search_users_messaging_disabled() {
-        $this->resetAfterTest();
-
-        // Create some skeleton data just so we can call the WS.
-        $user = $this->getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user);
-
-        // Disable messaging.
-        set_config('messaging', 0);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::message_search_users($user->id, 'User');
-    }
-
-    /**
-     * Tests searching messages.
-     */
-    public function test_messagearea_search_messages() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-        $convid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id]);
-
-        // Perform a search.
-        $result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(), $result);
-
-        // Confirm the data is correct.
-        $messages = $result['contacts'];
-        $this->assertCount(2, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-
-        $this->assertEquals($user2->id, $message1['userid']);
-        $this->assertEquals(fullname($user2), $message1['fullname']);
-        $this->assertTrue($message1['ismessaging']);
-        $this->assertFalse($message1['sentfromcurrentuser']);
-        $this->assertEquals('Word.', $message1['lastmessage']);
-        $this->assertNotEmpty($message1['messageid']);
-        $this->assertNull($message1['isonline']);
-        $this->assertFalse($message1['isread']);
-        $this->assertFalse($message1['isblocked']);
-        $this->assertNull($message1['unreadcount']);
-        $this->assertEquals($convid, $message1['conversationid']);
-
-        $this->assertEquals($user2->id, $message2['userid']);
-        $this->assertEquals(fullname($user2), $message2['fullname']);
-        $this->assertTrue($message2['ismessaging']);
-        $this->assertTrue($message2['sentfromcurrentuser']);
-        $this->assertEquals('Yo!', $message2['lastmessage']);
-        $this->assertNotEmpty($message2['messageid']);
-        $this->assertNull($message2['isonline']);
-        $this->assertTrue($message2['isread']);
-        $this->assertFalse($message2['isblocked']);
-        $this->assertNull($message2['unreadcount']);
-        $this->assertEquals($convid, $message2['conversationid']);
-    }
-
-    /**
-     * Tests searching messages as another user.
-     */
-    public function test_messagearea_search_messages_as_other_user() {
-        $this->resetAfterTest(true);
-
-        // The person doing the search.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Perform a search.
-        $result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
+        \core_message\api::add_contact($users[3]->id, $users[1]->id);
+        \core_message\api::add_contact($users[1]->id, $users[4]->id);
 
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(),
-            $result);
+        // Set as the user performing the search.
+        $this->setUser($users[1]);
 
-        // Confirm the data is correct.
-        $messages = $result['contacts'];
-        $this->assertCount(2, $messages);
+        // Grant the authenticated user role the capability 'user:viewdetails' at site context.
+        $authenticatedrole = $DB->get_record('role', ['shortname' => 'user'], '*', MUST_EXIST);
+        assign_capability('moodle/user:viewdetails', CAP_ALLOW, $authenticatedrole->id, context_system::instance());
 
-        $message1 = $messages[0];
-        $message2 = $messages[1];
+        // Perform a search with $CFG->messagingallusers disabled.
+        set_config('messagingallusers', 0);
+        $result = core_message_external::message_search_users($users[1]->id, 'search');
+        $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+        $contacts = $result['contacts'];
+        $noncontacts = $result['noncontacts'];
 
-        $this->assertEquals($user2->id, $message1['userid']);
-        $this->assertEquals(fullname($user2), $message1['fullname']);
-        $this->assertTrue($message1['ismessaging']);
-        $this->assertFalse($message1['sentfromcurrentuser']);
-        $this->assertEquals('Word.', $message1['lastmessage']);
-        $this->assertNotEmpty($message1['messageid']);
-        $this->assertFalse($message1['isonline']);
-        $this->assertFalse($message1['isread']);
-        $this->assertFalse($message1['isblocked']);
-        $this->assertNull($message1['unreadcount']);
+        // Check that we retrieved the correct contacts.
+        $this->assertCount(2, $contacts);
+        $this->assertEquals($users[2]->id, $contacts[0]['id']);
+        $this->assertEquals($users[3]->id, $contacts[1]['id']);
 
-        $this->assertEquals($user2->id, $message2['userid']);
-        $this->assertEquals(fullname($user2), $message2['fullname']);
-        $this->assertTrue($message2['ismessaging']);
-        $this->assertTrue($message2['sentfromcurrentuser']);
-        $this->assertEquals('Yo!', $message2['lastmessage']);
-        $this->assertNotEmpty($message2['messageid']);
-        $this->assertFalse($message2['isonline']);
-        $this->assertTrue($message2['isread']);
-        $this->assertFalse($message2['isblocked']);
-        $this->assertNull($message2['unreadcount']);
+        // Check that we retrieved the correct non-contacts.
+        // Site-wide messaging is disabled, so we expect to be able to search for any users whose profile we can view.
+        // Consider first conversations is self-conversation.
+        $this->assertCount(3, $noncontacts);
+        $this->assertEquals($users[1]->id, $noncontacts[0]['id']);
+        $this->assertEquals($users[6]->id, $noncontacts[1]['id']);
+        $this->assertEquals($users[7]->id, $noncontacts[2]['id']);
     }
 
     /**
-     * Tests searching messages as another user without the proper capabilities.
+     * Tests searching users as another user without the 'moodle/user:viewdetails' capability.
      */
-    public function test_messagearea_search_messages_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
+    public function test_message_search_users_without_cap() {
+        $this->resetAfterTest();
 
         // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
+        $user1 = $this->getDataGenerator()->create_user();
+        $user2 = $this->getDataGenerator()->create_user();
 
         // The person doing the search for another user.
         $this->setUser($user1);
 
         // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_messages($user2->id, 'Search');
+        core_message_external::message_search_users($user2->id, 'User');
+        $this->assertDebuggingCalled();
     }
 
     /**
-     * Tests searching messages with messaging disabled
+     * Tests searching users with messaging disabled.
      */
-    public function test_messagearea_search_messages_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
+    public function test_message_search_users_messaging_disabled() {
+        $this->resetAfterTest();
 
         // Create some skeleton data just so we can call the WS.
-        $user = self::getDataGenerator()->create_user();
+        $user = $this->getDataGenerator()->create_user();
 
-        // The person doing the search .
+        // The person doing the search.
         $this->setUser($user);
 
         // Disable messaging.
-        $CFG->messaging = 0;
+        set_config('messaging', 0);
 
         // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_search_messages($user->id, 'Search');
+        core_message_external::message_search_users($user->id, 'User');
     }
 
     /**
-     * Tests retrieving conversations.
+     * Tests searching messages.
      */
-    public function test_messagearea_conversations() {
+    public function test_messagearea_search_messages() {
         $this->resetAfterTest(true);
 
         // Create some users.
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
 
-        // The person retrieving the conversations.
+        // The person doing the search.
         $this->setUser($user1);
 
-        // Send some messages back and forth, have some different conversations with different users.
+        // Send some messages back and forth.
         $time = time();
         $this->send_message($user1, $user2, 'Yo!', 0, $time);
         $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
         $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $messageid1 = $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        $this->send_message($user1, $user3, 'Booyah', 0, $time + 4);
-        $this->send_message($user3, $user1, 'Whaaat?', 0, $time + 5);
-        $this->send_message($user1, $user3, 'Nothing.', 0, $time + 6);
-        $messageid2 = $this->send_message($user3, $user1, 'Cool.', 0, $time + 7);
-
-        $this->send_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 8);
-        $this->send_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 9);
-        $messageid3 = $this->send_message($user1, $user4, 'Dope.', 0, $time + 10);
+        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
+        $convid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id]);
 
-        // Retrieve the conversations.
-        $result = core_message_external::data_for_messagearea_conversations($user1->id);
+        // Perform a search.
+        $result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
 
         // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_conversations_returns(),
-            $result);
+        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(), $result);
 
         // Confirm the data is correct.
         $messages = $result['contacts'];
-        $this->assertCount(3, $messages);
+        $this->assertCount(2, $messages);
 
         $message1 = $messages[0];
         $message2 = $messages[1];
-        $message3 = $messages[2];
 
-        $this->assertEquals($user4->id, $message1['userid']);
+        $this->assertEquals($user2->id, $message1['userid']);
+        $this->assertEquals(fullname($user2), $message1['fullname']);
         $this->assertTrue($message1['ismessaging']);
-        $this->assertTrue($message1['sentfromcurrentuser']);
-        $this->assertEquals('Dope.', $message1['lastmessage']);
-        $this->assertEquals($messageid3, $message1['messageid']);
+        $this->assertFalse($message1['sentfromcurrentuser']);
+        $this->assertEquals('Word.', $message1['lastmessage']);
+        $this->assertNotEmpty($message1['messageid']);
         $this->assertNull($message1['isonline']);
         $this->assertFalse($message1['isread']);
         $this->assertFalse($message1['isblocked']);
-        $this->assertEquals(1, $message1['unreadcount']);
+        $this->assertNull($message1['unreadcount']);
+        $this->assertEquals($convid, $message1['conversationid']);
 
-        $this->assertEquals($user3->id, $message2['userid']);
+        $this->assertEquals($user2->id, $message2['userid']);
+        $this->assertEquals(fullname($user2), $message2['fullname']);
         $this->assertTrue($message2['ismessaging']);
-        $this->assertFalse($message2['sentfromcurrentuser']);
-        $this->assertEquals('Cool.', $message2['lastmessage']);
-        $this->assertEquals($messageid2, $message2['messageid']);
+        $this->assertTrue($message2['sentfromcurrentuser']);
+        $this->assertEquals('Yo!', $message2['lastmessage']);
+        $this->assertNotEmpty($message2['messageid']);
         $this->assertNull($message2['isonline']);
-        $this->assertFalse($message2['isread']);
-        $this->assertFalse($message2['isblocked']);
-        $this->assertEquals(2, $message2['unreadcount']);
-
-        $this->assertEquals($user2->id, $message3['userid']);
-        $this->assertTrue($message3['ismessaging']);
-        $this->assertFalse($message3['sentfromcurrentuser']);
-        $this->assertEquals('Word.', $message3['lastmessage']);
-        $this->assertEquals($messageid1, $message3['messageid']);
-        $this->assertNull($message3['isonline']);
-        $this->assertFalse($message3['isread']);
-        $this->assertFalse($message3['isblocked']);
-        $this->assertEquals(2, $message3['unreadcount']);
-    }
-
-    /**
-     * Tests retrieving conversations as another user.
-     */
-    public function test_messagearea_conversations_as_other_user() {
-        $this->resetAfterTest(true);
-
-        // Set as admin.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth, have some different conversations with different users.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $messageid1 = $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        $this->send_message($user1, $user3, 'Booyah', 0, $time + 4);
-        $this->send_message($user3, $user1, 'Whaaat?', 0, $time + 5);
-        $this->send_message($user1, $user3, 'Nothing.', 0, $time + 6);
-        $messageid2 = $this->send_message($user3, $user1, 'Cool.', 0, $time + 7);
-
-        $this->send_message($user1, $user4, 'Hey mate, you see the new messaging UI in Moodle?', 0, $time + 8);
-        $this->send_message($user4, $user1, 'Yah brah, it\'s pretty rad.', 0, $time + 9);
-        $messageid3 = $this->send_message($user1, $user4, 'Dope.', 0, $time + 10);
-
-        // Retrieve the conversations.
-        $result = core_message_external::data_for_messagearea_conversations($user1->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_conversations_returns(),
-            $result);
-
-        // Confirm the data is correct.
-        $messages = $result['contacts'];
-        $this->assertCount(3, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-
-        $this->assertEquals($user4->id, $message1['userid']);
-        $this->assertTrue($message1['ismessaging']);
-        $this->assertTrue($message1['sentfromcurrentuser']);
-        $this->assertEquals('Dope.', $message1['lastmessage']);
-        $this->assertEquals($messageid3, $message1['messageid']);
-        $this->assertFalse($message1['isonline']);
-        $this->assertFalse($message1['isread']);
-        $this->assertFalse($message1['isblocked']);
-        $this->assertEquals(1, $message1['unreadcount']);
-
-        $this->assertEquals($user3->id, $message2['userid']);
-        $this->assertTrue($message2['ismessaging']);
-        $this->assertFalse($message2['sentfromcurrentuser']);
-        $this->assertEquals('Cool.', $message2['lastmessage']);
-        $this->assertEquals($messageid2, $message2['messageid']);
-        $this->assertFalse($message2['isonline']);
-        $this->assertFalse($message2['isread']);
+        $this->assertTrue($message2['isread']);
         $this->assertFalse($message2['isblocked']);
-        $this->assertEquals(2, $message2['unreadcount']);
-
-        $this->assertEquals($user2->id, $message3['userid']);
-        $this->assertTrue($message3['ismessaging']);
-        $this->assertFalse($message3['sentfromcurrentuser']);
-        $this->assertEquals('Word.', $message3['lastmessage']);
-        $this->assertEquals($messageid1, $message3['messageid']);
-        $this->assertFalse($message3['isonline']);
-        $this->assertFalse($message3['isread']);
-        $this->assertFalse($message3['isblocked']);
-        $this->assertEquals(2, $message3['unreadcount']);
-    }
-
-    /**
-     * Tests retrieving conversations as another user without the proper capabilities.
-     */
-    public function test_messagearea_conversations_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person retrieving the conversations for another user.
-        $this->setUser($user1);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_conversations($user2->id);
-    }
-
-    /**
-     * Tests retrieving conversations with messaging disabled.
-     */
-    public function test_messagearea_conversations_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS.
-        $user = self::getDataGenerator()->create_user();
-
-        // The person retrieving the conversations.
-        $this->setUser($user);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_conversations($user->id);
-    }
-
-    /**
-     * Tests retrieving contacts.
-     */
-    public function test_messagearea_contacts() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-
-        // Set as the user.
-        $this->setUser($user1);
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'A';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'B';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'C';
-        $user4 = self::getDataGenerator()->create_user($user4);
-
-        $user5 = new stdClass();
-        $user5->firstname = 'User';
-        $user5->lastname = 'D';
-        $user5 = self::getDataGenerator()->create_user($user5);
-
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
-
-        // Retrieve the contacts.
-        $result = core_message_external::data_for_messagearea_contacts($user1->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_contacts_returns(),
-            $result);
-
-        // Confirm the data is correct.
-        $contacts = $result['contacts'];
-        usort($contacts, ['static', 'sort_contacts']);
-        $this->assertCount(3, $contacts);
-
-        $contact1 = $contacts[0];
-        $contact2 = $contacts[1];
-        $contact3 = $contacts[2];
-
-        $this->assertEquals($user2->id, $contact1['userid']);
-        $this->assertFalse($contact1['ismessaging']);
-        $this->assertFalse($contact1['sentfromcurrentuser']);
-        $this->assertNull($contact1['lastmessage']);
-        $this->assertNull($contact1['messageid']);
-        $this->assertNull($contact1['isonline']);
-        $this->assertFalse($contact1['isread']);
-        $this->assertFalse($contact1['isblocked']);
-        $this->assertNull($contact1['unreadcount']);
-
-        $this->assertEquals($user3->id, $contact2['userid']);
-        $this->assertFalse($contact2['ismessaging']);
-        $this->assertFalse($contact2['sentfromcurrentuser']);
-        $this->assertNull($contact2['lastmessage']);
-        $this->assertNull($contact2['messageid']);
-        $this->assertNull($contact2['isonline']);
-        $this->assertFalse($contact2['isread']);
-        $this->assertFalse($contact2['isblocked']);
-        $this->assertNull($contact2['unreadcount']);
-
-        $this->assertEquals($user4->id, $contact3['userid']);
-        $this->assertFalse($contact3['ismessaging']);
-        $this->assertFalse($contact3['sentfromcurrentuser']);
-        $this->assertNull($contact3['lastmessage']);
-        $this->assertNull($contact3['messageid']);
-        $this->assertNull($contact3['isonline']);
-        $this->assertFalse($contact3['isread']);
-        $this->assertFalse($contact3['isblocked']);
-        $this->assertNull($contact3['unreadcount']);
+        $this->assertNull($message2['unreadcount']);
+        $this->assertEquals($convid, $message2['conversationid']);
     }
 
     /**
-     * Tests retrieving contacts as another user.
+     * Tests searching messages as another user.
      */
-    public function test_messagearea_contacts_as_other_user() {
+    public function test_messagearea_search_messages_as_other_user() {
         $this->resetAfterTest(true);
 
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-
-        $user2 = new stdClass();
-        $user2->firstname = 'User';
-        $user2->lastname = 'A';
-        $user2 = self::getDataGenerator()->create_user($user2);
-
-        $user3 = new stdClass();
-        $user3->firstname = 'User';
-        $user3->lastname = 'B';
-        $user3 = self::getDataGenerator()->create_user($user3);
-
-        $user4 = new stdClass();
-        $user4->firstname = 'User';
-        $user4->lastname = 'C';
-        $user4 = self::getDataGenerator()->create_user($user4);
+        // The person doing the search.
+        $this->setAdminUser();
 
-        $user5 = new stdClass();
-        $user5->firstname = 'User';
-        $user5->lastname = 'D';
-        $user5 = self::getDataGenerator()->create_user($user5);
+        // Create some users.
+        $user1 = self::getDataGenerator()->create_user();
+        $user2 = self::getDataGenerator()->create_user();
 
-        // Add some users as contacts.
-        \core_message\api::add_contact($user1->id, $user2->id);
-        \core_message\api::add_contact($user1->id, $user3->id);
-        \core_message\api::add_contact($user1->id, $user4->id);
+        // Send some messages back and forth.
+        $time = time();
+        $this->send_message($user1, $user2, 'Yo!', 0, $time);
+        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
+        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
+        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
 
-        // Retrieve the contacts.
-        $result = core_message_external::data_for_messagearea_contacts($user1->id);
+        // Perform a search.
+        $result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
 
         // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_contacts_returns(),
+        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(),
             $result);
 
         // Confirm the data is correct.
-        $contacts = $result['contacts'];
-        usort($contacts, ['static', 'sort_contacts']);
-        $this->assertCount(3, $contacts);
+        $messages = $result['contacts'];
+        $this->assertCount(2, $messages);
+
+        $message1 = $messages[0];
+        $message2 = $messages[1];
+
+        $this->assertEquals($user2->id, $message1['userid']);
+        $this->assertEquals(fullname($user2), $message1['fullname']);
+        $this->assertTrue($message1['ismessaging']);
+        $this->assertFalse($message1['sentfromcurrentuser']);
+        $this->assertEquals('Word.', $message1['lastmessage']);
+        $this->assertNotEmpty($message1['messageid']);
+        $this->assertFalse($message1['isonline']);
+        $this->assertFalse($message1['isread']);
+        $this->assertFalse($message1['isblocked']);
+        $this->assertNull($message1['unreadcount']);
 
-        $contact1 = $contacts[0];
-        $contact2 = $contacts[1];
-        $contact3 = $contacts[2];
-
-        $this->assertEquals($user2->id, $contact1['userid']);
-        $this->assertFalse($contact1['ismessaging']);
-        $this->assertFalse($contact1['sentfromcurrentuser']);
-        $this->assertNull($contact1['lastmessage']);
-        $this->assertNull($contact1['messageid']);
-        $this->assertFalse($contact1['isonline']);
-        $this->assertFalse($contact1['isread']);
-        $this->assertFalse($contact1['isblocked']);
-        $this->assertNull($contact1['unreadcount']);
-
-        $this->assertEquals($user3->id, $contact2['userid']);
-        $this->assertFalse($contact2['ismessaging']);
-        $this->assertFalse($contact2['sentfromcurrentuser']);
-        $this->assertNull($contact2['lastmessage']);
-        $this->assertNull($contact2['messageid']);
-        $this->assertFalse($contact2['isonline']);
-        $this->assertFalse($contact2['isread']);
-        $this->assertFalse($contact2['isblocked']);
-        $this->assertNull($contact2['unreadcount']);
-
-        $this->assertEquals($user4->id, $contact3['userid']);
-        $this->assertFalse($contact3['ismessaging']);
-        $this->assertFalse($contact3['sentfromcurrentuser']);
-        $this->assertNull($contact3['lastmessage']);
-        $this->assertNull($contact3['messageid']);
-        $this->assertFalse($contact3['isonline']);
-        $this->assertFalse($contact3['isread']);
-        $this->assertFalse($contact3['isblocked']);
-        $this->assertNull($contact3['unreadcount']);
+        $this->assertEquals($user2->id, $message2['userid']);
+        $this->assertEquals(fullname($user2), $message2['fullname']);
+        $this->assertTrue($message2['ismessaging']);
+        $this->assertTrue($message2['sentfromcurrentuser']);
+        $this->assertEquals('Yo!', $message2['lastmessage']);
+        $this->assertNotEmpty($message2['messageid']);
+        $this->assertFalse($message2['isonline']);
+        $this->assertTrue($message2['isread']);
+        $this->assertFalse($message2['isblocked']);
+        $this->assertNull($message2['unreadcount']);
     }
 
     /**
-     * Tests retrieving contacts as another user without the proper capabilities.
+     * Tests searching messages as another user without the proper capabilities.
      */
-    public function test_messagearea_contacts_as_other_user_without_cap() {
+    public function test_messagearea_search_messages_as_other_user_without_cap() {
         $this->resetAfterTest(true);
 
         // Create some users.
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
 
-        // The person retrieving the contacts for another user.
+        // The person doing the search for another user.
         $this->setUser($user1);
 
-        // Perform the WS call and ensure an exception is thrown.
+        // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_contacts($user2->id);
+        core_message_external::data_for_messagearea_search_messages($user2->id, 'Search');
     }
 
     /**
-     * Tests retrieving contacts with messaging disabled.
+     * Tests searching messages with messaging disabled
      */
-    public function test_messagearea_contacts_messaging_disabled() {
+    public function test_messagearea_search_messages_messaging_disabled() {
         global $CFG;
 
         $this->resetAfterTest(true);
@@ -3550,15 +2552,15 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         // Create some skeleton data just so we can call the WS.
         $user = self::getDataGenerator()->create_user();
 
-        // The person retrieving the contacts.
+        // The person doing the search .
         $this->setUser($user);
 
         // Disable messaging.
         $CFG->messaging = 0;
 
-        // Perform the WS call and ensure we are shown that it is disabled.
+        // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_contacts($user->id);
+        core_message_external::data_for_messagearea_search_messages($user->id, 'Search');
     }
 
     /**
@@ -3680,282 +2682,72 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         $contact3 = array_shift($contacts);
 
         $this->assertEquals($user2->id, $contact1['id']);
-        $this->assertEquals(fullname($user2), $contact1['fullname']);
-        $this->assertTrue($contact1['iscontact']);
-
-        $this->assertEquals($user3->id, $contact2['id']);
-        $this->assertEquals(fullname($user3), $contact2['fullname']);
-        $this->assertTrue($contact2['iscontact']);
-
-        $this->assertEquals($user4->id, $contact3['id']);
-        $this->assertEquals(fullname($user4), $contact3['fullname']);
-        $this->assertTrue($contact3['iscontact']);
-    }
-
-    /**
-     * Tests retrieving contacts as another user without the proper capabilities.
-     */
-    public function test_get_user_contacts_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person retrieving the contacts for another user.
-        $this->setUser($user1);
-
-        // Perform the WS call and ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::get_user_contacts($user2->id);
-    }
-
-    /**
-     * Tests retrieving contacts with messaging disabled.
-     */
-    public function test_get_user_contacts_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS.
-        $user = self::getDataGenerator()->create_user();
-
-        // The person retrieving the contacts.
-        $this->setUser($user);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Perform the WS call and ensure we are shown that it is disabled.
-        $this->expectException('moodle_exception');
-        core_message_external::get_user_contacts($user->id);
-    }
-
-    /**
-     * Test getting contacts when there are no results.
-     */
-    public function test_get_user_contacts_no_results() {
-        $this->resetAfterTest();
-
-        $user1 = self::getDataGenerator()->create_user();
-
-        $this->setUser($user1);
-
-        $requests = core_message_external::get_user_contacts($user1->id);
-        $requests = external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(), $requests);
-
-        $this->assertEmpty($requests);
-    }
-
-    /**
-     * Tests retrieving messages.
-     */
-    public function test_messagearea_messages() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person asking for the messages.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Retrieve the messages.
-        $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(),
-            $result);
-
-        // Check the results are correct.
-        $this->assertTrue($result['iscurrentuser']);
-        $this->assertEquals($user1->id, $result['currentuserid']);
-        $this->assertEquals($user2->id, $result['otheruserid']);
-        $this->assertEquals(fullname($user2), $result['otheruserfullname']);
-        $this->assertNull($result['isonline']);
-
-        // Confirm the message data is correct.
-        $messages = $result['messages'];
-        $this->assertCount(4, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertEquals($user1->id, $message1['useridfrom']);
-        $this->assertEquals($user2->id, $message1['useridto']);
-        $this->assertTrue($message1['displayblocktime']);
-        $this->assertContains('Yo!', $message1['text']);
-
-        $this->assertEquals($user2->id, $message2['useridfrom']);
-        $this->assertEquals($user1->id, $message2['useridto']);
-        $this->assertFalse($message2['displayblocktime']);
-        $this->assertContains('Sup mang?', $message2['text']);
-
-        $this->assertEquals($user1->id, $message3['useridfrom']);
-        $this->assertEquals($user2->id, $message3['useridto']);
-        $this->assertFalse($message3['displayblocktime']);
-        $this->assertContains('Writing PHPUnit tests!', $message3['text']);
-
-        $this->assertEquals($user2->id, $message4['useridfrom']);
-        $this->assertEquals($user1->id, $message4['useridto']);
-        $this->assertFalse($message4['displayblocktime']);
-        $this->assertContains('Word.', $message4['text']);
-    }
-
-    /**
-     * Tests retrieving messages.
-     */
-    public function test_messagearea_messages_timefrom() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person asking for the messages.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Message 1', 0, $time - 4);
-        $this->send_message($user2, $user1, 'Message 2', 0, $time - 3);
-        $this->send_message($user1, $user2, 'Message 3', 0, $time - 2);
-        $this->send_message($user2, $user1, 'Message 4', 0, $time - 1);
-
-        // Retrieve the messages from $time - 3, which should be the 3 most recent messages.
-        $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id, 0, 0, false, $time - 3);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(),
-            $result);
-
-        // Confirm the message data is correct. We shouldn't get 'Message 1' back.
-        $messages = $result['messages'];
-        $this->assertCount(3, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-
-        $this->assertContains('Message 2', $message1['text']);
-        $this->assertContains('Message 3', $message2['text']);
-        $this->assertContains('Message 4', $message3['text']);
-    }
-
-    /**
-     * Tests retrieving messages as another user.
-     */
-    public function test_messagearea_messages_as_other_user() {
-        $this->resetAfterTest(true);
-
-        // Set as admin.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Retrieve the messages.
-        $result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_messages_returns(),
-            $result);
-
-        // Check the results are correct.
-        $this->assertFalse($result['iscurrentuser']);
-        $this->assertEquals($user1->id, $result['currentuserid']);
-        $this->assertEquals($user2->id, $result['otheruserid']);
-        $this->assertEquals(fullname($user2), $result['otheruserfullname']);
-        $this->assertFalse($result['isonline']);
-
-        // Confirm the message data is correct.
-        $messages = $result['messages'];
-        $this->assertCount(4, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertEquals($user1->id, $message1['useridfrom']);
-        $this->assertEquals($user2->id, $message1['useridto']);
-        $this->assertTrue($message1['displayblocktime']);
-        $this->assertContains('Yo!', $message1['text']);
-
-        $this->assertEquals($user2->id, $message2['useridfrom']);
-        $this->assertEquals($user1->id, $message2['useridto']);
-        $this->assertFalse($message2['displayblocktime']);
-        $this->assertContains('Sup mang?', $message2['text']);
+        $this->assertEquals(fullname($user2), $contact1['fullname']);
+        $this->assertTrue($contact1['iscontact']);
 
-        $this->assertEquals($user1->id, $message3['useridfrom']);
-        $this->assertEquals($user2->id, $message3['useridto']);
-        $this->assertFalse($message3['displayblocktime']);
-        $this->assertContains('Writing PHPUnit tests!', $message3['text']);
+        $this->assertEquals($user3->id, $contact2['id']);
+        $this->assertEquals(fullname($user3), $contact2['fullname']);
+        $this->assertTrue($contact2['iscontact']);
 
-        $this->assertEquals($user2->id, $message4['useridfrom']);
-        $this->assertEquals($user1->id, $message4['useridto']);
-        $this->assertFalse($message4['displayblocktime']);
-        $this->assertContains('Word.', $message4['text']);
+        $this->assertEquals($user4->id, $contact3['id']);
+        $this->assertEquals(fullname($user4), $contact3['fullname']);
+        $this->assertTrue($contact3['iscontact']);
     }
 
     /**
-     * Tests retrieving messages as another user without the proper capabilities.
+     * Tests retrieving contacts as another user without the proper capabilities.
      */
-    public function test_messagearea_messages_as_other_user_without_cap() {
+    public function test_get_user_contacts_as_other_user_without_cap() {
         $this->resetAfterTest(true);
 
         // Create some users.
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
 
-        // The person asking for the messages for another user.
+        // The person retrieving the contacts for another user.
         $this->setUser($user1);
 
-        // Ensure an exception is thrown.
+        // Perform the WS call and ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_messages($user2->id, $user3->id);
+        core_message_external::get_user_contacts($user2->id);
     }
 
     /**
-     * Tests retrieving messages with messaging disabled.
+     * Tests retrieving contacts with messaging disabled.
      */
-    public function test_messagearea_messages_messaging_disabled() {
+    public function test_get_user_contacts_messaging_disabled() {
         global $CFG;
 
         $this->resetAfterTest(true);
 
         // Create some skeleton data just so we can call the WS.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
+        $user = self::getDataGenerator()->create_user();
 
-        // The person asking for the messages for another user.
-        $this->setUser($user1);
+        // The person retrieving the contacts.
+        $this->setUser($user);
 
         // Disable messaging.
         $CFG->messaging = 0;
 
-        // Ensure an exception is thrown.
+        // Perform the WS call and ensure we are shown that it is disabled.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_messages($user1->id, $user2->id);
+        core_message_external::get_user_contacts($user->id);
+    }
+
+    /**
+     * Test getting contacts when there are no results.
+     */
+    public function test_get_user_contacts_no_results() {
+        $this->resetAfterTest();
+
+        $user1 = self::getDataGenerator()->create_user();
+
+        $this->setUser($user1);
+
+        $requests = core_message_external::get_user_contacts($user1->id);
+        $requests = external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(), $requests);
+
+        $this->assertEmpty($requests);
     }
 
     /**
@@ -4126,394 +2918,114 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         // Check the results are correct.
         $this->assertEquals($conversation->id, $result['id']);
 
-        // Confirm the members data is correct.
-        $members = $result['members'];
-        $this->assertCount(3, $members);
-        $membersid = [$members[0]['id'], $members[1]['id'], $members[2]['id']];
-        $this->assertContains($user1->id, $membersid);
-        $this->assertContains($user2->id, $membersid);
-        $this->assertContains($user3->id, $membersid);
-
-        // Confirm the message data is correct.
-        $messages = $result['messages'];
-        $this->assertCount(4, $messages);
-
-        $message1 = $messages[0];
-        $message2 = $messages[1];
-        $message3 = $messages[2];
-        $message4 = $messages[3];
-
-        $this->assertEquals($user1->id, $message1['useridfrom']);
-        $this->assertContains('Yo!', $message1['text']);
-
-        $this->assertEquals($user3->id, $message2['useridfrom']);
-        $this->assertContains('Sup mang?', $message2['text']);
-
-        $this->assertEquals($user2->id, $message3['useridfrom']);
-        $this->assertContains('Writing PHPUnit tests!', $message3['text']);
-
-        $this->assertEquals($user1->id, $message4['useridfrom']);
-        $this->assertContains('Word.', $message4['text']);
-    }
-
-    /**
-     * Tests get_conversation_messages for retrieving messages as another user without the proper capabilities.
-     */
-    public function test_get_conversation_messages_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-
-        // Create group conversation.
-        $conversation = \core_message\api::create_conversation(
-            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
-            [$user1->id, $user2->id, $user3->id, $user4->id]
-        );
-
-        // The person asking for the messages for another user.
-        $this->setUser($user1);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::get_conversation_messages($user2->id, $conversation->id);
-    }
-
-    /**
-     * Tests get_conversation_messages for retrieving messages as another user not in the conversation.
-     */
-    public function test_get_conversation_messages_as_user_not_in_conversation() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user(); // Not in group.
-
-        // Create group conversation.
-        $conversation = \core_message\api::create_conversation(
-            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
-            [$user1->id, $user2->id]
-        );
-
-        // The person asking for the messages for a conversation he does not belong to.
-        $this->setUser($user3);
-
-        // Ensure an exception is thrown.
-        $this->expectExceptionMessage('User is not part of conversation.');
-        core_message_external::get_conversation_messages($user3->id, $conversation->id);
-    }
-
-    /**
-     * Tests get_conversation_messages for retrieving messages with messaging disabled.
-     */
-    public function test_get_conversation_messages_messaging_disabled() {
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-        $user4 = self::getDataGenerator()->create_user();
-
-        // Create group conversation.
-        $conversation = \core_message\api::create_conversation(
-            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
-            [$user1->id, $user2->id, $user3->id, $user4->id]
-        );
-
-        // The person asking for the messages for another user.
-        $this->setUser($user1);
-
-        // Disable messaging.
-        set_config('messaging', 0);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::get_conversation_messages($user1->id, $conversation->id);
-    }
-
-    /**
-     * Tests retrieving most recent message.
-     */
-    public function test_messagearea_get_most_recent_message() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person doing the search.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Get the most recent message.
-        $result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_most_recent_message_returns(),
-            $result);
-
-        // Check the results are correct.
-        $this->assertEquals($user2->id, $result['useridfrom']);
-        $this->assertEquals($user1->id, $result['useridto']);
-        $this->assertContains('Word.', $result['text']);
-    }
-
-    /**
-     * Tests retrieving most recent message as another user.
-     */
-    public function test_messagearea_get_most_recent_message_as_other_user() {
-        $this->resetAfterTest(true);
-
-        // The person doing the search.
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Get the most recent message.
-        $result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_most_recent_message_returns(),
-            $result);
-
-        // Check the results are correct.
-        $this->assertEquals($user2->id, $result['useridfrom']);
-        $this->assertEquals($user1->id, $result['useridto']);
-        $this->assertContains('Word.', $result['text']);
-    }
-
-    /**
-     * Tests retrieving most recent message as another user without the proper capabilities.
-     */
-    public function test_messagearea_get_most_recent_message_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-
-        // The person asking for the most recent message for another user.
-        $this->setUser($user1);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_get_most_recent_message($user2->id, $user3->id);
-    }
-
-    /**
-     * Tests retrieving most recent message with messaging disabled.
-     */
-    public function test_messagearea_get_most_recent_message_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some skeleton data just so we can call the WS.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person asking for the most recent message.
-        $this->setUser($user1);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id);
-    }
-
-    /**
-     * Tests retrieving a user's profile.
-     */
-    public function test_messagearea_get_profile() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person asking for the profile information.
-        $this->setUser($user1);
-
-        // Get the profile.
-        $result = core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id);
-
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_profile_returns(),
-            $result);
-
-        $this->assertEquals($user2->id, $result['userid']);
-        $this->assertEmpty($result['email']);
-        $this->assertEmpty($result['country']);
-        $this->assertEmpty($result['city']);
-        $this->assertEquals(fullname($user2), $result['fullname']);
-        $this->assertNull($result['isonline']);
-        $this->assertFalse($result['isblocked']);
-        $this->assertFalse($result['iscontact']);
-    }
-
-    /**
-     * Tests retrieving a user's profile as another user.
-     */
-    public function test_messagearea_profile_as_other_user() {
-        $this->resetAfterTest(true);
+        // Confirm the members data is correct.
+        $members = $result['members'];
+        $this->assertCount(3, $members);
+        $membersid = [$members[0]['id'], $members[1]['id'], $members[2]['id']];
+        $this->assertContains($user1->id, $membersid);
+        $this->assertContains($user2->id, $membersid);
+        $this->assertContains($user3->id, $membersid);
 
-        // The person asking for the profile information.
-        $this->setAdminUser();
+        // Confirm the message data is correct.
+        $messages = $result['messages'];
+        $this->assertCount(4, $messages);
 
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
+        $message1 = $messages[0];
+        $message2 = $messages[1];
+        $message3 = $messages[2];
+        $message4 = $messages[3];
 
-        $user2 = new stdClass();
-        $user2->country = 'AU';
-        $user2->city = 'Perth';
-        $user2 = self::getDataGenerator()->create_user($user2);
+        $this->assertEquals($user1->id, $message1['useridfrom']);
+        $this->assertContains('Yo!', $message1['text']);
 
-        // Get the profile.
-        $result = core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id);
+        $this->assertEquals($user3->id, $message2['useridfrom']);
+        $this->assertContains('Sup mang?', $message2['text']);
 
-        // We need to execute the return values cleaning process to simulate the web service server.
-        $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_get_profile_returns(),
-            $result);
+        $this->assertEquals($user2->id, $message3['useridfrom']);
+        $this->assertContains('Writing PHPUnit tests!', $message3['text']);
 
-        $this->assertEquals($user2->id, $result['userid']);
-        $this->assertEquals($user2->email, $result['email']);
-        $this->assertEquals(get_string($user2->country, 'countries'), $result['country']);
-        $this->assertEquals($user2->city, $result['city']);
-        $this->assertEquals(fullname($user2), $result['fullname']);
-        $this->assertFalse($result['isonline']);
-        $this->assertFalse($result['isblocked']);
-        $this->assertFalse($result['iscontact']);
+        $this->assertEquals($user1->id, $message4['useridfrom']);
+        $this->assertContains('Word.', $message4['text']);
     }
 
     /**
-     * Tests retrieving a user's profile as another user without the proper capabilities.
+     * Tests get_conversation_messages for retrieving messages as another user without the proper capabilities.
      */
-    public function test_messagearea_profile_as_other_user_without_cap() {
+    public function test_get_conversation_messages_as_other_user_without_cap() {
         $this->resetAfterTest(true);
 
         // Create some users.
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
         $user3 = self::getDataGenerator()->create_user();
+        $user4 = self::getDataGenerator()->create_user();
+
+        // Create group conversation.
+        $conversation = \core_message\api::create_conversation(
+            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
+            [$user1->id, $user2->id, $user3->id, $user4->id]
+        );
 
-        // The person asking for the profile information for another user.
+        // The person asking for the messages for another user.
         $this->setUser($user1);
 
         // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_get_profile($user2->id, $user3->id);
+        core_message_external::get_conversation_messages($user2->id, $conversation->id);
     }
 
     /**
-     * Tests retrieving a user's profile with messaging disabled.
+     * Tests get_conversation_messages for retrieving messages as another user not in the conversation.
      */
-    public function test_messagearea_profile_messaging_disabled() {
-        global $CFG;
-
+    public function test_get_conversation_messages_as_user_not_in_conversation() {
         $this->resetAfterTest(true);
 
-        // Create some skeleton data just so we can call the WS.
+        // Create some users.
         $user1 = self::getDataGenerator()->create_user();
         $user2 = self::getDataGenerator()->create_user();
+        $user3 = self::getDataGenerator()->create_user(); // Not in group.
 
-        // The person asking for the profile information.
-        $this->setUser($user1);
+        // Create group conversation.
+        $conversation = \core_message\api::create_conversation(
+            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
+            [$user1->id, $user2->id]
+        );
 
-        // Disable messaging.
-        $CFG->messaging = 0;
+        // The person asking for the messages for a conversation he does not belong to.
+        $this->setUser($user3);
 
         // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::data_for_messagearea_get_profile($user1->id, $user2->id);
-    }
-
-    /**
-     * Test marking all message as read with an invalid user.
-     */
-    public function test_mark_all_messages_as_read_invalid_user_exception() {
-        $this->resetAfterTest(true);
-
-        $this->expectException('moodle_exception');
-        core_message_external::mark_all_messages_as_read(-2132131, 0);
+        $this->expectExceptionMessage('User is not part of conversation.');
+        core_message_external::get_conversation_messages($user3->id, $conversation->id);
     }
 
     /**
-     * Test marking all message as read without proper access.
+     * Tests get_conversation_messages for retrieving messages with messaging disabled.
      */
-    public function test_mark_all_messages_as_read_access_denied_exception() {
+    public function test_get_conversation_messages_messaging_disabled() {
         $this->resetAfterTest(true);
 
-        $sender = $this->getDataGenerator()->create_user();
-        $user = $this->getDataGenerator()->create_user();
+        // Create some skeleton data just so we can call the WS.
+        $user1 = self::getDataGenerator()->create_user();
+        $user2 = self::getDataGenerator()->create_user();
+        $user3 = self::getDataGenerator()->create_user();
+        $user4 = self::getDataGenerator()->create_user();
 
-        $this->setUser($user);
-        $this->expectException('moodle_exception');
-        core_message_external::mark_all_messages_as_read($sender->id, 0);
-    }
+        // Create group conversation.
+        $conversation = \core_message\api::create_conversation(
+            \core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
+            [$user1->id, $user2->id, $user3->id, $user4->id]
+        );
 
-    /**
-     * Test marking all message as read with missing from user.
-     */
-    public function test_mark_all_messages_as_read_missing_from_user_exception() {
-        $this->resetAfterTest(true);
+        // The person asking for the messages for another user.
+        $this->setUser($user1);
 
-        $sender = $this->getDataGenerator()->create_user();
+        // Disable messaging.
+        set_config('messaging', 0);
 
-        $this->setUser($sender);
+        // Ensure an exception is thrown.
         $this->expectException('moodle_exception');
-        core_message_external::mark_all_messages_as_read($sender->id, 99999);
-    }
-
-    /**
-     * Test marking all message as read.
-     */
-    public function test_mark_all_messages_as_read() {
-        global $DB;
-
-        $this->resetAfterTest(true);
-
-        $sender1 = $this->getDataGenerator()->create_user();
-        $sender2 = $this->getDataGenerator()->create_user();
-        $sender3 = $this->getDataGenerator()->create_user();
-        $recipient = $this->getDataGenerator()->create_user();
-
-        $this->setUser($recipient);
-
-        $this->send_message($sender1, $recipient, 'Message');
-        $this->send_message($sender1, $recipient, 'Message');
-        $this->send_message($sender2, $recipient, 'Message');
-        $this->send_message($sender2, $recipient, 'Message');
-        $this->send_message($sender3, $recipient, 'Message');
-        $this->send_message($sender3, $recipient, 'Message');
-
-        core_message_external::mark_all_messages_as_read($recipient->id, $sender1->id);
-        $this->assertEquals(2, $DB->count_records('message_user_actions'));
-
-        core_message_external::mark_all_messages_as_read($recipient->id, 0);
-        $this->assertEquals(6, $DB->count_records('message_user_actions'));
+        core_message_external::get_conversation_messages($user1->id, $conversation->id);
     }
 
     /**
@@ -4736,158 +3248,6 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
         core_message_external::get_unread_conversations_count($user2->id);
     }
 
-    /**
-     * Test deleting conversation.
-     */
-    public function test_delete_conversation() {
-        global $DB;
-
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person wanting to delete the conversation.
-        $this->setUser($user1);
-
-        // Send some messages back and forth.
-        $time = time();
-        $m1id = $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $m2id = $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $m3id = $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $m4id = $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Delete the conversation.
-        core_message_external::delete_conversation($user1->id, $user2->id);
-
-        $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC');
-        $this->assertCount(4, $muas);
-        // Sort by id.
-        ksort($muas);
-
-        $mua1 = array_shift($muas);
-        $mua2 = array_shift($muas);
-        $mua3 = array_shift($muas);
-        $mua4 = array_shift($muas);
-
-        $this->assertEquals($user1->id, $mua1->userid);
-        $this->assertEquals($m1id, $mua1->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action);
-
-        $this->assertEquals($user1->id, $mua2->userid);
-        $this->assertEquals($m2id, $mua2->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action);
-
-        $this->assertEquals($user1->id, $mua3->userid);
-        $this->assertEquals($m3id, $mua3->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action);
-
-        $this->assertEquals($user1->id, $mua4->userid);
-        $this->assertEquals($m4id, $mua4->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action);
-    }
-
-    /**
-     * Test deleting conversation as other user.
-     */
-    public function test_delete_conversation_as_other_user() {
-        global $DB;
-
-        $this->resetAfterTest(true);
-
-        $this->setAdminUser();
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth.
-        $time = time();
-        $m1id = $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $m2id = $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $m3id = $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $m4id = $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // Delete the conversation.
-        core_message_external::delete_conversation($user1->id, $user2->id);
-
-        $muas = $DB->get_records('message_user_actions', array(), 'timecreated ASC');
-        $this->assertCount(4, $muas);
-        // Sort by id.
-        ksort($muas);
-
-        $mua1 = array_shift($muas);
-        $mua2 = array_shift($muas);
-        $mua3 = array_shift($muas);
-        $mua4 = array_shift($muas);
-
-        $this->assertEquals($user1->id, $mua1->userid);
-        $this->assertEquals($m1id, $mua1->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua1->action);
-
-        $this->assertEquals($user1->id, $mua2->userid);
-        $this->assertEquals($m2id, $mua2->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua2->action);
-
-        $this->assertEquals($user1->id, $mua3->userid);
-        $this->assertEquals($m3id, $mua3->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua3->action);
-
-        $this->assertEquals($user1->id, $mua4->userid);
-        $this->assertEquals($m4id, $mua4->messageid);
-        $this->assertEquals(\core_message\api::MESSAGE_ACTION_DELETED, $mua4->action);
-    }
-
-    /**
-     * Test deleting conversation as other user without proper capability.
-     */
-    public function test_delete_conversation_as_other_user_without_cap() {
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-        $user3 = self::getDataGenerator()->create_user();
-
-        // Send some messages back and forth.
-        $time = time();
-        $this->send_message($user1, $user2, 'Yo!', 0, $time);
-        $this->send_message($user2, $user1, 'Sup mang?', 0, $time + 1);
-        $this->send_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 2);
-        $this->send_message($user2, $user1, 'Word.', 0, $time + 3);
-
-        // The person wanting to delete the conversation.
-        $this->setUser($user3);
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::delete_conversation($user1->id, $user2->id);
-    }
-
-    /**
-     * Test deleting conversation with messaging disabled.
-     */
-    public function test_delete_conversation_messaging_disabled() {
-        global $CFG;
-
-        $this->resetAfterTest(true);
-
-        // Create some users.
-        $user1 = self::getDataGenerator()->create_user();
-        $user2 = self::getDataGenerator()->create_user();
-
-        // The person wanting to delete the conversation.
-        $this->setUser($user1);
-
-        // Disable messaging.
-        $CFG->messaging = 0;
-
-        // Ensure an exception is thrown.
-        $this->expectException('moodle_exception');
-        core_message_external::delete_conversation($user1->id, $user2->id);
-    }
-
     /**
      * Test deleting conversations.
      */
index c02a610..5a75739 100644 (file)
@@ -143,6 +143,7 @@ class core_message_messagelib_testcase extends advanced_testcase {
 
     /**
      * Test message_count_unread_messages.
+     * TODO: MDL-69643
      */
     public function test_message_count_unread_messages() {
         // Create users to send and receive message.
@@ -151,13 +152,17 @@ class core_message_messagelib_testcase extends advanced_testcase {
         $userto = $this->getDataGenerator()->create_user();
 
         $this->assertEquals(0, message_count_unread_messages($userto));
+        $this->assertDebuggingCalled();
 
         // Send fake messages.
         $this->send_fake_message($userfrom1, $userto);
         $this->send_fake_message($userfrom2, $userto);
 
         $this->assertEquals(2, message_count_unread_messages($userto));
+        $this->assertDebuggingCalled();
+
         $this->assertEquals(1, message_count_unread_messages($userto, $userfrom1));
+        $this->assertDebuggingCalled();
     }
 
     /**
@@ -183,7 +188,10 @@ class core_message_messagelib_testcase extends advanced_testcase {
 
         // Should only count the messages that weren't read by the current user.
         $this->assertEquals(1, message_count_unread_messages($userto));
+        $this->assertDebuggingCalledCount(2);
+
         $this->assertEquals(0, message_count_unread_messages($userto, $userfrom1));
+        $this->assertDebuggingCalled();
     }
 
     /**
@@ -198,6 +206,7 @@ class core_message_messagelib_testcase extends advanced_testcase {
         $userto = $this->getDataGenerator()->create_user();
 
         $this->assertEquals(0, message_count_unread_messages($userto));
+        $this->assertDebuggingCalled();
 
         // Send fake messages.
         $messageid = $this->send_fake_message($userfrom1, $userto);
@@ -208,7 +217,9 @@ class core_message_messagelib_testcase extends advanced_testcase {
 
         // Should only count the messages that weren't deleted by the current user.
         $this->assertEquals(1, message_count_unread_messages($userto));
+        $this->assertDebuggingCalled();
         $this->assertEquals(0, message_count_unread_messages($userto, $userfrom1));
+        $this->assertDebuggingCalled();
     }
 
     /**
@@ -220,7 +231,9 @@ class core_message_messagelib_testcase extends advanced_testcase {
 
         $this->send_fake_message($userfrom, $userto);
 
+        // Ensure an exception is thrown.
         $this->assertEquals(0, message_count_unread_messages($userfrom));
+        $this->assertDebuggingCalled();
     }
 
     /**
index be6da94..a989150 100644 (file)
@@ -1,6 +1,38 @@
 This files describes API changes in /message/ messaging system,
 information provided here is intended especially for developers.
 
+=== 3.10 ===
+
+* The following methods have been deprecated and should not be used any more:
+  * message_count_unread_messages()
+  * get_non_contacts_with_unread_message_count()
+  * get_contacts_with_unread_message_count()
+
+* The following functions have been finally deprecated and can not be used anymore::
+  * search_users_in_course()
+  * search_users()
+  * get_contacts()
+  * get_messages()
+  * get_most_recent_message()
+  * get_profile()
+  * get_messages()
+  * create_messages()
+  * get_conversations_legacy_formatter()
+  * create_contacts()
+  * block_contacts()
+  * unblock_contacts()
+  * data_for_messagearea_search_users_in_course()
+  * data_for_messagearea_search_users()
+  * message_search_users()
+  * data_for_messagearea_conversations()
+  * data_for_messagearea_contacts()
+  * data_for_messagearea_messages()
+  * get_conversation_messages()
+  * data_for_messagearea_get_most_recent_message()
+  * data_for_messagearea_get_profile()
+  * mark_all_messages_as_read()
+  * delete_conversation()
+
 === 3.9 ===
 * Removed the following deprecated functions:
   - message_move_userfrom_unread2read
index 143e9a7..1ff2d00 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2021052500.10;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2021052500.11;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.
 $release  = '4.0dev (Build: 20200903)'; // Human-friendly version name