MDL-64400 core_messages: Mark notifications sent via email as read

This commit is contained in:
Amaia Anabitarte
2018-12-27 09:15:53 +01:00
parent 57afd82ab0
commit 0f38e62970
3 changed files with 17 additions and 1 deletions
@@ -37,7 +37,7 @@ class message_output_email extends message_output {
* @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
*/
function send_message($eventdata) {
global $CFG;
global $CFG, $DB;
// skip any messaging suspended and deleted users
if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
@@ -93,6 +93,10 @@ class message_output_email extends message_output {
$result = email_to_user($recipient, $eventdata->userfrom, $eventdata->subject, $eventdata->fullmessage,
$eventdata->fullmessagehtml, $attachment, $attachname, true, $replyto, $replytoname);
if ($result && $notification = $DB->get_record('notifications', ['id' => $eventdata->savedmessageid])) {
\core_message\api::mark_notification_as_read($notification);
}
// Remove an attachment file if any.
if (!empty($attachment) && file_exists($attachment)) {
unlink($attachment);
+7
View File
@@ -1678,9 +1678,16 @@ class mod_assign_locallib_testcase extends advanced_testcase {
assign::cron();
$events = $sink->get_events();
// Notification has been marked as read, so now first event should be a 'notification_viewed' one. For student.
$event = reset($events);
$this->assertInstanceOf('\core\event\notification_viewed', $event);
$this->assertEquals($student->id, $event->userid);
// And next event should be the 'notification_sent' one. For teacher.
$event = $events[1];
$this->assertInstanceOf('\core\event\notification_sent', $event);
$this->assertEquals($assign->get_course()->id, $event->other['courseid']);
$this->assertEquals($teacher->id, $event->userid);
$sink->close();
}
+5
View File
@@ -286,8 +286,13 @@ class mod_forum_mail_testcase extends advanced_testcase {
// Reset the message sink for other tests.
$this->helper->messagesink = $this->redirectMessages();
// Notification has been marked as read, so now first event should be a 'notification_viewed' one.
$event = reset($events);
$this->assertInstanceOf('\core\event\notification_viewed', $event);
// And next event should be the 'notification_sent' one.
$event = $events[1];
$this->assertInstanceOf('\core\event\notification_sent', $event);
$this->assertEquals($course->id, $event->other['courseid']);
}