MDL-63650 core_message: Final deprecation of mark_all_read_for_user

This commit is contained in:
Amaia Anabitarte 2019-12-13 17:12:30 +01:00
parent 7850f76a93
commit 23033ff48b
3 changed files with 12 additions and 46 deletions

View File

@ -1753,46 +1753,11 @@ class api {
}
/**
* Marks ALL messages being sent from $fromuserid to $touserid as read.
*
* Can be filtered by type.
*
* @deprecated since 3.5
* @param int $touserid the id of the message recipient
* @param int $fromuserid the id of the message sender
* @param string $type filter the messages by type, either MESSAGE_TYPE_NOTIFICATION, MESSAGE_TYPE_MESSAGE or '' for all.
* @return void
*/
public static function mark_all_read_for_user($touserid, $fromuserid = 0, $type = '') {
debugging('\core_message\api::mark_all_read_for_user is deprecated. Please either use ' .
'\core_message\api::mark_all_notifications_read_for_user or \core_message\api::mark_all_messages_read_for_user',
DEBUG_DEVELOPER);
$type = strtolower($type);
$conversationid = null;
$ignoremessages = false;
if (!empty($fromuserid)) {
$conversationid = self::get_conversation_between_users([$touserid, $fromuserid]);
if (!$conversationid) { // If there is no conversation between the users then there are no messages to mark.
$ignoremessages = true;
}
}
if (!empty($type)) {
if ($type == MESSAGE_TYPE_NOTIFICATION) {
self::mark_all_notifications_as_read($touserid, $fromuserid);
} else if ($type == MESSAGE_TYPE_MESSAGE) {
if (!$ignoremessages) {
self::mark_all_messages_as_read($touserid, $conversationid);
}
}
} else { // We want both.
self::mark_all_notifications_as_read($touserid, $fromuserid);
if (!$ignoremessages) {
self::mark_all_messages_as_read($touserid, $conversationid);
}
}
public static function mark_all_read_for_user() {
throw new \coding_exception('\core_message\api::mark_all_read_for_user has been removed. Please either use ' .
'\core_message\api::mark_all_notifications_as_read or \core_message\api::mark_all_messages_as_read');
}
/**

View File

@ -52,8 +52,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);
\core_message\api::mark_all_read_for_user($recipient->id);
$this->assertDebuggingCalled();
\core_message\api::mark_all_notifications_as_read($recipient->id);
\core_message\api::mark_all_messages_as_read($recipient->id);
$this->assertEquals(message_count_unread_messages($recipient), 0);
}
@ -75,8 +75,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$this->send_fake_message($sender2, $recipient);
$this->send_fake_message($sender2, $recipient);
\core_message\api::mark_all_read_for_user($recipient->id, $sender1->id);
$this->assertDebuggingCalled();
\core_message\api::mark_all_notifications_as_read($recipient->id, $sender1->id);
$conversationid = \core_message\api::get_conversation_between_users([$recipient->id, $sender1->id]);
\core_message\api::mark_all_messages_as_read($recipient->id, $conversationid);
$this->assertEquals(message_count_unread_messages($recipient), 3);
}
@ -91,12 +93,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);
\core_message\api::mark_all_read_for_user($recipient->id, 0, MESSAGE_TYPE_NOTIFICATION);
$this->assertDebuggingCalled();
\core_message\api::mark_all_notifications_as_read($recipient->id);
$this->assertEquals(message_count_unread_messages($recipient), 3);
\core_message\api::mark_all_read_for_user($recipient->id, 0, MESSAGE_TYPE_MESSAGE);
$this->assertDebuggingCalled();
\core_message\api::mark_all_messages_as_read($recipient->id);
$this->assertEquals(message_count_unread_messages($recipient), 0);
}

View File

@ -9,6 +9,7 @@ information provided here is intended especially for developers.
- message_mark_message_read
- message_can_delete_message
- message_delete_message
* mark_all_read_for_user()
=== 3.8 ===