Commit ee94aded authored by Mathew May's avatar Mathew May
Browse files

MDL-63261 messaging: Final 3.6 deprecations

parent 99777d96
......@@ -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',
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -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,
......
......@@ -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() {
......
This diff is collapsed.
......@@ -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.');
}
/**
......
<?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?
*/