mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'MDL-64773_master' of git://github.com/markn86/moodle
This commit is contained in:
commit
a6646dfd92
39 changed files with 1093 additions and 21 deletions
|
@ -84,13 +84,16 @@ class manager {
|
|||
// Get user records for all members of the conversation.
|
||||
// We must fetch distinct users, because it's possible for a user to message themselves via bulk user actions.
|
||||
// In such cases, there will be 2 records referring to the same user.
|
||||
$sql = "SELECT u.*
|
||||
$sql = "SELECT u.*, mca.id as ismuted
|
||||
FROM {user} u
|
||||
LEFT JOIN {message_conversation_actions} mca
|
||||
ON mca.userid = u.id AND mca.conversationid = ? AND mca.action = ?
|
||||
WHERE u.id IN (
|
||||
SELECT mcm.userid FROM {message_conversation_members} mcm
|
||||
WHERE mcm.conversationid = :convid
|
||||
WHERE mcm.conversationid = ?
|
||||
)";
|
||||
$members = $DB->get_records_sql($sql, ['convid' => $eventdata->convid]);
|
||||
$members = $DB->get_records_sql($sql, [$eventdata->convid, \core_message\api::CONVERSATION_ACTION_MUTED,
|
||||
$eventdata->convid]);
|
||||
if (empty($members)) {
|
||||
throw new \moodle_exception("Conversation has no members or does not exist.");
|
||||
}
|
||||
|
@ -138,7 +141,10 @@ class manager {
|
|||
foreach ($otherusers as $recipient) {
|
||||
// If this message was a legacy (1:1) message, then we use the userto.
|
||||
if ($legacymessage) {
|
||||
$ismuted = $recipient->ismuted;
|
||||
|
||||
$recipient = $eventdata->userto;
|
||||
$recipient->ismuted = $ismuted;
|
||||
}
|
||||
|
||||
$usertoisrealuser = (\core_user::is_real_user($recipient->id) != false);
|
||||
|
@ -195,8 +201,9 @@ class manager {
|
|||
|
||||
// Fill in the array of processors to be used based on default and user preferences.
|
||||
// This applies only to individual conversations. Messages to group conversations ignore processors.
|
||||
// Do not process muted conversations.
|
||||
$processorlist = [];
|
||||
if ($conv->type == \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
||||
if ($conv->type == \core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL && !$recipient->ismuted) {
|
||||
foreach ($processors as $processor) {
|
||||
// Skip adding processors for internal user, if processor doesn't support sending message to internal user.
|
||||
if (!$usertoisrealuser && !$processor->object->can_send_to_any_users()) {
|
||||
|
|
|
@ -260,6 +260,7 @@ class icon_system_fontawesome extends icon_system_font {
|
|||
'core:i/moodle_host' => 'fa-graduation-cap',
|
||||
'core:i/moremenu' => 'fa-ellipsis-h',
|
||||
'core:i/move_2d' => 'fa-arrows',
|
||||
'core:i/muted' => 'fa-microphone-slash',
|
||||
'core:i/navigationitem' => 'fa-fw',
|
||||
'core:i/ne_red_mark' => 'fa-remove',
|
||||
'core:i/new' => 'fa-bolt',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20190122" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20190308" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
|
@ -650,6 +650,20 @@
|
|||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="message_conversation_actions" COMMENT="Stores all per-user actions on individual conversations">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="conversationid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="action" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
|
||||
<KEY NAME="conversationid" TYPE="foreign" FIELDS="conversationid" REFTABLE="message_conversations" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="message_user_actions" COMMENT="Stores all per-user actions on individual messages">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
|
|
|
@ -874,6 +874,24 @@ $functions = array(
|
|||
'type' => 'write',
|
||||
'capabilities' => 'moodle/course:managegroups'
|
||||
),
|
||||
'core_message_mute_conversations' => array(
|
||||
'classname' => 'core_message_external',
|
||||
'methodname' => 'mute_conversations',
|
||||
'classpath' => 'message/externallib.php',
|
||||
'description' => 'Mutes a list of conversations',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
|
||||
),
|
||||
'core_message_unmute_conversations' => array(
|
||||
'classname' => 'core_message_external',
|
||||
'methodname' => 'unmute_conversations',
|
||||
'classpath' => 'message/externallib.php',
|
||||
'description' => 'Unmutes a list of conversations',
|
||||
'type' => 'write',
|
||||
'ajax' => true,
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
|
||||
),
|
||||
'core_message_block_user' => array(
|
||||
'classname' => 'core_message_external',
|
||||
'methodname' => 'block_user',
|
||||
|
|
|
@ -2780,5 +2780,31 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint(true, 2019030700.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2019030800.00) {
|
||||
// Define table 'message_conversation_actions' to be created.
|
||||
// Note - I would have preferred 'message_conversation_user_actions' but due to Oracle we can't. Boo.
|
||||
$table = new xmldb_table('message_conversation_actions');
|
||||
|
||||
// Adding fields to table 'message_conversation_actions'.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('conversationid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('action', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
// Adding keys to table 'message_conversation_actions'.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('userid', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
|
||||
$table->add_key('conversationid', XMLDB_KEY_FOREIGN, ['conversationid'], 'message_conversations', ['id']);
|
||||
|
||||
// Conditionally launch create table for 'message_conversation_actions'.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2019030800.00);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1118,6 +1118,51 @@ class core_messagelib_testcase extends advanced_testcase {
|
|||
$this->assertTrue($storedfileexists);
|
||||
}
|
||||
|
||||
public function test_send_message_when_muted() {
|
||||
$this->preventResetByRollback();
|
||||
$this->resetAfterTest();
|
||||
|
||||
$userfrom = $this->getDataGenerator()->create_user();
|
||||
$userto = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Create a conversation between the users.
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL,
|
||||
[
|
||||
$userfrom->id,
|
||||
$userto->id
|
||||
]
|
||||
);
|
||||
|
||||
$message = new \core\message\message();
|
||||
$message->courseid = 1;
|
||||
$message->component = 'moodle';
|
||||
$message->name = 'instantmessage';
|
||||
$message->userfrom = $userfrom;
|
||||
$message->convid = $conversation->id;
|
||||
$message->subject = 'message subject 1';
|
||||
$message->fullmessage = 'message body';
|
||||
$message->fullmessageformat = FORMAT_MARKDOWN;
|
||||
$message->fullmessagehtml = '<p>message body</p>';
|
||||
$message->smallmessage = 'small message';
|
||||
$message->notification = '0';
|
||||
|
||||
$sink = $this->redirectEmails();
|
||||
message_send($message);
|
||||
$emails = $sink->get_messages();
|
||||
$this->assertCount(1, $emails);
|
||||
$sink->clear();
|
||||
|
||||
// Mute the conversation.
|
||||
\core_message\api::mute_conversation($userto->id, $conversation->id);
|
||||
|
||||
$sink = $this->redirectEmails();
|
||||
message_send($message);
|
||||
$emails = $sink->get_messages();
|
||||
$this->assertCount(0, $emails);
|
||||
$sink->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a particular message type in the list of message types.
|
||||
* @param string $component
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue