mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-56407-master-2' of git://github.com/junpataleta/moodle
This commit is contained in:
commit
d10ca75b8c
6 changed files with 62 additions and 16 deletions
|
@ -5616,7 +5616,11 @@ function message_is_user_blocked($recipient, $sender = null) {
|
|||
debugging('message_is_user_blocked() is deprecated and is no longer used, please use
|
||||
\core_message\api::is_user_blocked() instead.', DEBUG_DEVELOPER);
|
||||
|
||||
return \core_message\api::is_user_blocked($recipient, $sender);
|
||||
$senderid = null;
|
||||
if ($sender !== null && isset($sender->id)) {
|
||||
$senderid = $sender->id;
|
||||
}
|
||||
return \core_message\api::is_user_blocked($recipient->id, $senderid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -616,8 +616,12 @@ class api {
|
|||
return false;
|
||||
}
|
||||
|
||||
$senderid = null;
|
||||
if ($sender !== null && isset($sender->id)) {
|
||||
$senderid = $sender->id;
|
||||
}
|
||||
// The recipient has specifically blocked this sender.
|
||||
if (self::is_user_blocked($recipient, $sender)) {
|
||||
if (self::is_user_blocked($recipient->id, $senderid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -663,27 +667,25 @@ class api {
|
|||
* Note: This function will always return false if the sender has the
|
||||
* readallmessages capability at the system context level.
|
||||
*
|
||||
* @param object $recipient User object.
|
||||
* @param object $sender User object.
|
||||
* @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($recipient, $sender = null) {
|
||||
public static function is_user_blocked($recipientid, $senderid = null) {
|
||||
global $USER, $DB;
|
||||
|
||||
if (is_null($sender)) {
|
||||
if (is_null($senderid)) {
|
||||
// The message is from the logged in user, unless otherwise specified.
|
||||
$sender = $USER;
|
||||
$senderid = $USER->id;
|
||||
}
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
if (has_capability('moodle/site:readallmessages', $systemcontext, $sender)) {
|
||||
if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($contact = $DB->get_record('message_contacts', array('userid' => $recipient->id, 'contactid' => $sender->id))) {
|
||||
if ($contact->blocked) {
|
||||
return true;
|
||||
}
|
||||
if ($DB->get_field('message_contacts', 'blocked', ['userid' => $recipientid, 'contactid' => $senderid])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace core_message\output\messagearea;
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_message\api;
|
||||
use renderable;
|
||||
use templatable;
|
||||
|
||||
|
@ -95,6 +96,8 @@ class messages implements templatable, renderable {
|
|||
$data->messages[] = $message->export_for_template($output);
|
||||
}
|
||||
|
||||
$data->isblocked = api::is_user_blocked($this->currentuserid, $this->otheruserid);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -996,7 +996,8 @@ class core_message_external extends external_api {
|
|||
'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),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,37 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/message_area_messages_area
|
||||
|
||||
Messages area template.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Context variables required for this template:
|
||||
* isonline - boolean
|
||||
* isblocked - boolean
|
||||
* otheruserid - int
|
||||
* otheruserfullname - string
|
||||
* messages - array of messages
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"isonline": true,
|
||||
"isblocked": true,
|
||||
"otheruserid": 1,
|
||||
"otheruserfullname": "Sam Student",
|
||||
"messages": [
|
||||
{
|
||||
"text": "Hello there!"
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
{{#otheruserid}}
|
||||
<div class="messages-header">
|
||||
<div class="view-toggle btn-container">
|
||||
|
@ -25,6 +56,11 @@
|
|||
<div class="name-container">
|
||||
<div class="name">
|
||||
<button class="btn btn-link" data-action="view-contact-profile" data-userid="{{otheruserid}}">{{otheruserfullname}}</button>
|
||||
{{#isblocked}}
|
||||
<span data-region="contact-icon-blocked">
|
||||
{{#pix}} t/block, core, {{#str}} contactblocked, message {{/str}} {{/pix}}
|
||||
</span>
|
||||
{{/isblocked}}
|
||||
</div>
|
||||
<div class="status {{#isonline}}online{{/isonline}}">
|
||||
<span class="offline-text">{{#str}} offline, message {{/str}}</span>
|
||||
|
|
|
@ -839,13 +839,13 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
|||
$this->setUser($user1);
|
||||
|
||||
// User shouldn't be blocked.
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1, $user2));
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1->id, $user2->id));
|
||||
|
||||
// Block the user.
|
||||
message_block_contact($user2->id);
|
||||
|
||||
// User should be blocked.
|
||||
$this->assertTrue(\core_message\api::is_user_blocked($user1, $user2));
|
||||
$this->assertTrue(\core_message\api::is_user_blocked($user1->id, $user2->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -865,7 +865,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
|||
$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));
|
||||
$this->assertFalse(\core_message\api::is_user_blocked($user1->id));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue