mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'MDL-64034-master' of https://github.com/snake/moodle
This commit is contained in:
commit
8699a985bc
@ -100,8 +100,8 @@ class api {
|
||||
$ufields2 = \user_picture::fields('u2', array('lastaccess'), 'userto_id', 'userto_');
|
||||
|
||||
$sql = "SELECT m.id, m.useridfrom, mcm.userid as useridto, m.subject, m.fullmessage, m.fullmessagehtml, m.fullmessageformat,
|
||||
m.smallmessage, m.timecreated, 0 as isread, $ufields, mub.id as userfrom_blocked, $ufields2,
|
||||
mub2.id as userto_blocked
|
||||
m.smallmessage, m.conversationid, m.timecreated, 0 as isread, $ufields, mub.id as userfrom_blocked,
|
||||
$ufields2, mub2.id as userto_blocked
|
||||
FROM {messages} m
|
||||
INNER JOIN {user} u
|
||||
ON u.id = m.useridfrom
|
||||
|
@ -326,6 +326,7 @@ class helper {
|
||||
$data->isblocked = isset($contact->blocked) ? (bool) $contact->blocked : false;
|
||||
$data->isread = isset($contact->isread) ? (bool) $contact->isread : false;
|
||||
$data->unreadcount = isset($contact->unreadcount) ? $contact->unreadcount : null;
|
||||
$data->conversationid = $contact->conversationid ?? null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -108,6 +108,11 @@ class contact implements templatable, renderable {
|
||||
*/
|
||||
public $unreadcount;
|
||||
|
||||
/**
|
||||
* @var int The id of the conversation to which to message belongs.
|
||||
*/
|
||||
public $conversationid;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -127,6 +132,7 @@ class contact implements templatable, renderable {
|
||||
$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) {
|
||||
@ -152,6 +158,7 @@ class contact implements templatable, renderable {
|
||||
$contact->isblocked = $this->isblocked;
|
||||
$contact->isread = $this->isread;
|
||||
$contact->unreadcount = $this->unreadcount;
|
||||
$contact->conversationid = $this->conversationid;
|
||||
|
||||
return $contact;
|
||||
}
|
||||
|
@ -1049,6 +1049,7 @@ class core_message_external extends external_api {
|
||||
'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'),
|
||||
'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation',
|
||||
VALUE_DEFAULT, null),
|
||||
'conversationid' => new external_value(PARAM_INT, 'The id of the conversation', VALUE_DEFAULT, null),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -732,6 +732,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->send_fake_message($user1, $user2, 'Writing PHPUnit tests!', 0, $time + 3);
|
||||
$this->send_fake_message($user2, $user1, 'Word.', 0, $time + 4);
|
||||
|
||||
$convid = \core_message\api::get_conversation_between_users([$user1->id, $user2->id]);
|
||||
$conv2id = \core_message\api::get_conversation_between_users([$user1->id, $user3->id]);
|
||||
|
||||
// Block user 3.
|
||||
\core_message\api::block_user($user1->id, $user3->id);
|
||||
|
||||
@ -755,6 +758,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$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($user1->id, $message2->useridfrom);
|
||||
@ -766,6 +770,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->assertTrue($message2->isread);
|
||||
$this->assertFalse($message2->isblocked);
|
||||
$this->assertNull($message2->unreadcount);
|
||||
$this->assertEquals($convid, $message2->conversationid);
|
||||
|
||||
$this->assertEquals($user3->id, $message3->userid);
|
||||
$this->assertEquals($user3->id, $message3->useridfrom);
|
||||
@ -777,6 +782,7 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
$this->assertFalse($message3->isread);
|
||||
$this->assertTrue($message3->isblocked);
|
||||
$this->assertNull($message3->unreadcount);
|
||||
$this->assertEquals($conv2id, $message3->conversationid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2653,13 +2653,13 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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);
|
||||
$result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(), $result);
|
||||
|
||||
// Confirm the data is correct.
|
||||
$messages = $result['contacts'];
|
||||
@ -2678,6 +2678,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$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']);
|
||||
@ -2689,6 +2690,7 @@ class core_message_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertTrue($message2['isread']);
|
||||
$this->assertFalse($message2['isblocked']);
|
||||
$this->assertNull($message2['unreadcount']);
|
||||
$this->assertEquals($convid, $message2['conversationid']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user