Commit d1e8e69d authored by Mark Nelson's avatar Mark Nelson Committed by Jake Dallimore
Browse files

MDL-63466 core_message: deprecated methods and services

parent 4f22d7f2
......@@ -38,6 +38,7 @@ $string['contactableprivacy_site'] = 'Anyone on the site';
$string['contactblocked'] = 'Contact blocked';
$string['contactrequests'] = 'Contact requests';
$string['contacts'] = 'Contacts';
$string['conversationdoesntexist'] = 'Conversation does not exist';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$string['deleteallconfirm'] = "Are you sure you would like to delete this entire conversation?";
......
......@@ -595,6 +595,7 @@ class api {
/**
* Returns the messages to display in the message area.
*
* @deprecated since 3.6
* @param int $userid the current user
* @param int $otheruserid the other user
* @param int $limitfrom
......@@ -605,7 +606,9 @@ class api {
* @return array
*/
public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0,
$sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
$sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
debugging('\core_message\api::get_messages() is deprecated, please use ' .
'\core_message\api::get_conversation_messages() instead.', DEBUG_DEVELOPER);
if (!empty($timefrom)) {
// Get the conversation between userid and otheruserid.
......@@ -674,11 +677,15 @@ class api {
/**
* Returns the most recent message between two users.
*
* @deprecated since 3.6
* @param int $userid the current user
* @param int $otheruserid the other user
* @return \stdClass|null
*/
public static function get_most_recent_message($userid, $otheruserid) {
debugging('\core_message\api::get_most_recent_message() is deprecated, please use ' .
'\core_message\api::get_most_recent_conversation_message() instead.', DEBUG_DEVELOPER);
// 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.
......
......@@ -37,6 +37,7 @@ class helper {
/**
* Helper function to retrieve the messages between two users
*
* @deprecated since 3.6
* @param int $userid the current user
* @param int $otheruserid the other user
* @param int $timedeleted the time the message was deleted
......@@ -49,6 +50,9 @@ class helper {
*/
public static function get_messages($userid, $otheruserid, $timedeleted = 0, $limitfrom = 0, $limitnum = 0,
$sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) {
debugging('\core_message\helper::get_messages() is deprecated, please use ' .
'\core_message\helper::get_conversation_messages() instead.', DEBUG_DEVELOPER);
global $DB;
$hash = self::get_conversation_hash([$userid, $otheruserid]);
......@@ -232,11 +236,15 @@ class helper {
/**
* Helper function to return an array of messages.
*
* @deprecated since 3.6
* @param int $userid
* @param array $messages
* @return array
*/
public static function create_messages($userid, $messages) {
debugging('\core_message\helper::create_messages() is deprecated, please use ' .
'\core_message\helper::create_conversation_messages() instead.', DEBUG_DEVELOPER);
// Store the messages.
$arrmessages = array();
......
......@@ -135,7 +135,52 @@ if (!empty($user2->id)) {
$conversations[$user2->id]->isread = 1;
}
$messages = \core_message\api::get_messages($user1->id, $user2->id, 0, 20, 'timecreated DESC');
// Get the conversationid.
if (!isset($conversationid)) {
if (!$conversationid = self::get_conversation_between_users($userids)) {
// If the conversationid doesn't exist, throw an exception.
throw new moodle_exception('conversationdoesntexist', 'core_message');
}
}
$convmessages = \core_message\api::get_conversation_messages($user1->id, $conversationid, 0, 20, 'timecreated DESC');
$messages = $convmessages['messages'];
// Keeps track of the last day, month and year combo we were viewing.
$day = '';
$month = '';
$year = '';
// Parse the messages to add missing fields for backward compatibility.
$messages = array_map(function($message) use ($user1, $user2, $USER, $day, $month, $year) {
// Add useridto.
if (empty($message->useridto)) {
if ($message->useridfrom == $user1->id) {
$message->useridto = $user2->id;
} else {
$message->useridto = $user1->id;
}
}
// Add currentuserid.
$message->currentuserid = $USER->id;
// Add displayblocktime.
$date = usergetdate($message->timecreated);
if ($day != $date['mday'] || $month != $date['month'] || $year != $date['year']) {
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$message->displayblocktime = true;
} else {
$message->displayblocktime = false;
}
// We don't have this information here so, for now, we leave an empty value.
// This is a temporary solution because a new UI is being built in MDL-63303.
$message->timeread = 0;
return $message;
}, $messages);
}
$pollmin = !empty($CFG->messagingminpoll) ? $CFG->messagingminpoll : MESSAGE_DEFAULT_MIN_POLL_IN_SECONDS;
......
......@@ -1323,6 +1323,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// Retrieve the messages.
$messages = \core_message\api::get_messages($user1->id, $user2->id);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(4, count($messages));
......@@ -1778,6 +1779,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// Retrieve the most recent messages.
$message = \core_message\api::get_most_recent_message($user1->id, $user2->id);
$this->assertDebuggingCalledCount(3);
// Check the results are correct.
$this->assertEquals($user2->id, $message->useridfrom);
......@@ -2545,6 +2547,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// 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);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(4, count($messages));
......@@ -2561,6 +2564,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// 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);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(2, count($messages));
......@@ -2592,6 +2596,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// 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);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(4, count($messages));
......@@ -2608,6 +2613,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// 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);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(2, count($messages));
......@@ -2639,6 +2645,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
// 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);
$this->assertDebuggingCalledCount(3);
// Confirm the message data is correct.
$this->assertEquals(2, count($messages));
......
......@@ -2785,6 +2785,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
// Retrieve the messages.
$result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id);
$this->assertDebuggingCalledCount(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(),
......@@ -2849,6 +2850,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
// 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);
$this->assertDebuggingCalledCount(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(),
......@@ -2889,6 +2891,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
// Retrieve the messages.
$result = core_message_external::data_for_messagearea_messages($user1->id, $user2->id);
$this->assertDebuggingCalledCount(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(),
......@@ -3252,6 +3255,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
// Get the most recent message.
$result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id);
$this->assertDebuggingCalledCount(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_get_most_recent_message_returns(),
......@@ -3285,6 +3289,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
// Get the most recent message.
$result = core_message_external::data_for_messagearea_get_most_recent_message($user1->id, $user2->id);
$this->assertDebuggingCalledCount(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_get_most_recent_message_returns(),
......
......@@ -31,6 +31,10 @@ information provided here is intended especially for developers.
- \core_message\api::delete_conversation()
- \core_message\api::is_user_non_contact_blocked()
- \core_message\api::create_conversation_between_users()
- \core_message\api::get_messages()
- \core_message\api::get_most_recent_message()
- \core_message\helper::get_messages()
- \core_message\helper::create_messages()
* The method \core_message\api::can_delete_conversation() now expects a 'conversationid' to be passed
as the second parameter.
* The following web services have been deprecated. Please do not call these any more.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment