mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-60680 notifications: Include action buttons information
This commit is contained in:
parent
36fa0ec900
commit
2356454f21
12 changed files with 77 additions and 27 deletions
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$string['abouttobeinstalled'] = 'about to be installed';
|
$string['abouttobeinstalled'] = 'about to be installed';
|
||||||
|
$string['accept'] = 'Accept';
|
||||||
$string['action'] = 'Action';
|
$string['action'] = 'Action';
|
||||||
$string['actionchoice'] = 'What do you want to do with the file \'{$a}\'?';
|
$string['actionchoice'] = 'What do you want to do with the file \'{$a}\'?';
|
||||||
$string['actions'] = 'Actions';
|
$string['actions'] = 'Actions';
|
||||||
|
|
|
@ -1915,6 +1915,15 @@ class api {
|
||||||
|
|
||||||
$eventdata->timecreated = time();
|
$eventdata->timecreated = time();
|
||||||
$eventdata->notification = 0;
|
$eventdata->notification = 0;
|
||||||
|
// Custom data for event.
|
||||||
|
$customdata = [
|
||||||
|
'actionbuttons' => [
|
||||||
|
'send' => get_string('send', 'message'),
|
||||||
|
],
|
||||||
|
'placeholders' => [
|
||||||
|
'send' => get_string('writeamessage', 'message'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
$conv = $DB->get_record('message_conversations', ['id' => $conversationid]);
|
$conv = $DB->get_record('message_conversations', ['id' => $conversationid]);
|
||||||
if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_GROUP) {
|
if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_GROUP) {
|
||||||
|
@ -1922,16 +1931,20 @@ class api {
|
||||||
// Conversation image.
|
// Conversation image.
|
||||||
$imageurl = isset($convextrafields[$conv->id]) ? $convextrafields[$conv->id]['imageurl'] : null;
|
$imageurl = isset($convextrafields[$conv->id]) ? $convextrafields[$conv->id]['imageurl'] : null;
|
||||||
if ($imageurl) {
|
if ($imageurl) {
|
||||||
$eventdata->customdata = [
|
$customdata['notificationiconurl'] = $imageurl;
|
||||||
'notificationiconurl' => $imageurl,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
// Conversation name.
|
||||||
|
if (is_null($conv->contextid)) {
|
||||||
|
$convcontext = \context_user::instance($userid);
|
||||||
|
} else {
|
||||||
|
$convcontext = \context::instance_by_id($conv->contextid);
|
||||||
|
}
|
||||||
|
$customdata['conversationname'] = format_string($conv->name, true, ['context' => $convcontext]);
|
||||||
} else if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
} else if ($conv->type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
||||||
$userpicture = new \user_picture($eventdata->userfrom);
|
$userpicture = new \user_picture($eventdata->userfrom);
|
||||||
$eventdata->customdata = [
|
$customdata['notificationiconurl'] = $userpicture->get_url($PAGE)->out(false);
|
||||||
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
$eventdata->customdata = $customdata;
|
||||||
|
|
||||||
$messageid = message_send($eventdata);
|
$messageid = message_send($eventdata);
|
||||||
|
|
||||||
|
@ -2564,6 +2577,10 @@ class api {
|
||||||
$userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message.
|
$userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message.
|
||||||
$message->customdata = [
|
$message->customdata = [
|
||||||
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
||||||
|
'actionbuttons' => [
|
||||||
|
'accept' => get_string_manager()->get_string('accept', 'moodle', null, $userto->lang),
|
||||||
|
'reject' => get_string_manager()->get_string('reject', 'moodle', null, $userto->lang),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
message_send($message);
|
message_send($message);
|
||||||
|
|
|
@ -356,6 +356,12 @@ function message_post_message($userfrom, $userto, $message, $format) {
|
||||||
$userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message.
|
$userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message.
|
||||||
$eventdata->customdata = [
|
$eventdata->customdata = [
|
||||||
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
||||||
|
'actionbuttons' => [
|
||||||
|
'send' => get_string_manager()->get_string('send', 'message', null, $eventdata->userto->lang),
|
||||||
|
],
|
||||||
|
'placeholders' => [
|
||||||
|
'send' => get_string_manager()->get_string('writeamessage', 'message', null, $eventdata->userto->lang),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
return message_send($eventdata);
|
return message_send($eventdata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,14 @@ class message_popup_externallib_testcase extends advanced_testcase {
|
||||||
$result = message_popup_external::get_popup_notifications($recipient->id, false, 0, 0);
|
$result = message_popup_external::get_popup_notifications($recipient->id, false, 0, 0);
|
||||||
$this->assertCount(4, $result['notifications']);
|
$this->assertCount(4, $result['notifications']);
|
||||||
// Check we receive custom data as a unserialisable json.
|
// Check we receive custom data as a unserialisable json.
|
||||||
$this->assertObjectHasAttribute('datakey', json_decode($result['notifications'][0]->customdata));
|
$found = 0;
|
||||||
|
foreach ($result['notifications'] as $notification) {
|
||||||
|
if (!empty($notification->customdata)) {
|
||||||
|
$this->assertObjectHasAttribute('datakey', json_decode($notification->customdata));
|
||||||
|
$found++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertEquals(2, $found);
|
||||||
|
|
||||||
$this->setUser($recipient);
|
$this->setUser($recipient);
|
||||||
$result = message_popup_external::get_popup_notifications($recipient->id, false, 0, 0);
|
$result = message_popup_external::get_popup_notifications($recipient->id, false, 0, 0);
|
||||||
|
|
|
@ -4760,6 +4760,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
$customdata = json_decode($messages[0]->customdata);
|
$customdata = json_decode($messages[0]->customdata);
|
||||||
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
||||||
|
$this->assertObjectHasAttribute('actionbuttons', $customdata);
|
||||||
|
$this->assertCount(2, (array) $customdata->actionbuttons);
|
||||||
|
|
||||||
$this->assertEquals($user1->id, $request->userid);
|
$this->assertEquals($user1->id, $request->userid);
|
||||||
$this->assertEquals($user2->id, $request->requesteduserid);
|
$this->assertEquals($user2->id, $request->requesteduserid);
|
||||||
|
@ -5783,13 +5785,17 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
|
|
||||||
// Send a message to an individual conversation.
|
// Send a message to an individual conversation.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
$messagesSink = $this->redirectMessages();
|
$messagessink = $this->redirectMessages();
|
||||||
$message1 = \core_message\api::send_message_to_conversation($user1->id, $ic1->id, 'this is a message', FORMAT_MOODLE);
|
$message1 = \core_message\api::send_message_to_conversation($user1->id, $ic1->id, 'this is a message', FORMAT_MOODLE);
|
||||||
$events = $sink->get_events();
|
$events = $sink->get_events();
|
||||||
$messages = $messagesSink->get_messages();
|
$messages = $messagessink->get_messages();
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
$customdata = json_decode($messages[0]->customdata);
|
$customdata = json_decode($messages[0]->customdata);
|
||||||
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
||||||
|
$this->assertObjectHasAttribute('actionbuttons', $customdata);
|
||||||
|
$this->assertCount(1, (array) $customdata->actionbuttons);
|
||||||
|
$this->assertObjectHasAttribute('placeholders', $customdata);
|
||||||
|
$this->assertCount(1, (array) $customdata->placeholders);
|
||||||
|
|
||||||
// Verify the message returned.
|
// Verify the message returned.
|
||||||
$this->assertInstanceOf(\stdClass::class, $message1);
|
$this->assertInstanceOf(\stdClass::class, $message1);
|
||||||
|
@ -5829,10 +5835,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
|
|
||||||
// Send a message to a group conversation.
|
// Send a message to a group conversation.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
$messagesSink = $this->redirectMessages();
|
$messagessink = $this->redirectMessages();
|
||||||
$message1 = \core_message\api::send_message_to_conversation($user1->id, $gc2->id, 'message to the group', FORMAT_MOODLE);
|
$message1 = \core_message\api::send_message_to_conversation($user1->id, $gc2->id, 'message to the group', FORMAT_MOODLE);
|
||||||
$events = $sink->get_events();
|
$events = $sink->get_events();
|
||||||
$messages = $messagesSink->get_messages();
|
$messages = $messagessink->get_messages();
|
||||||
// Verify the message returned.
|
// Verify the message returned.
|
||||||
$this->assertInstanceOf(\stdClass::class, $message1);
|
$this->assertInstanceOf(\stdClass::class, $message1);
|
||||||
$this->assertObjectHasAttribute('id', $message1);
|
$this->assertObjectHasAttribute('id', $message1);
|
||||||
|
@ -5840,7 +5846,12 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
$this->assertAttributeEquals('message to the group', 'text', $message1);
|
$this->assertAttributeEquals('message to the group', 'text', $message1);
|
||||||
$this->assertObjectHasAttribute('timecreated', $message1);
|
$this->assertObjectHasAttribute('timecreated', $message1);
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
$this->assertObjectHasAttribute('customdata', $messages[0]); // No group image means no customdata.
|
$customdata = json_decode($messages[0]->customdata);
|
||||||
|
$this->assertObjectHasAttribute('actionbuttons', $customdata);
|
||||||
|
$this->assertCount(1, (array) $customdata->actionbuttons);
|
||||||
|
$this->assertObjectHasAttribute('placeholders', $customdata);
|
||||||
|
$this->assertCount(1, (array) $customdata->placeholders);
|
||||||
|
$this->assertObjectNotHasAttribute('notificationiconurl', $customdata); // No group image means no image.
|
||||||
|
|
||||||
// Verify events. Note: the event is a message read event because of an if (PHPUNIT) conditional within message_send(),
|
// Verify events. Note: the event is a message read event because of an if (PHPUNIT) conditional within message_send(),
|
||||||
// however, we can still determine the number and ids of any recipients this way.
|
// however, we can still determine the number and ids of any recipients this way.
|
||||||
|
@ -5893,10 +5904,10 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
$sink = $this->redirectMessages();
|
$sink = $this->redirectMessages();
|
||||||
|
|
||||||
// Send a message to a group conversation.
|
// Send a message to a group conversation.
|
||||||
$messagesSink = $this->redirectMessages();
|
$messagessink = $this->redirectMessages();
|
||||||
$message1 = \core_message\api::send_message_to_conversation($user1->id, $conversations[0]->id,
|
$message1 = \core_message\api::send_message_to_conversation($user1->id, $conversations[0]->id,
|
||||||
'message to the group', FORMAT_MOODLE);
|
'message to the group', FORMAT_MOODLE);
|
||||||
$messages = $messagesSink->get_messages();
|
$messages = $messagessink->get_messages();
|
||||||
// Verify the message returned.
|
// Verify the message returned.
|
||||||
$this->assertInstanceOf(\stdClass::class, $message1);
|
$this->assertInstanceOf(\stdClass::class, $message1);
|
||||||
$this->assertObjectHasAttribute('id', $message1);
|
$this->assertObjectHasAttribute('id', $message1);
|
||||||
|
@ -5906,7 +5917,9 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
$customdata = json_decode($messages[0]->customdata);
|
$customdata = json_decode($messages[0]->customdata);
|
||||||
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
||||||
$this->assertEquals($groupimageurl, $customdata->notificationiconurl);;
|
$this->assertEquals($groupimageurl, $customdata->notificationiconurl);
|
||||||
|
$this->assertEquals($group->name, $customdata->conversationname);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -519,7 +519,7 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
|
||||||
$this->assertCount(7, $tmpitems); // 2 from the first page + 5 from the second page.
|
$this->assertCount(7, $tmpitems); // 2 from the first page + 5 from the second page.
|
||||||
|
|
||||||
// And finally, save everything! We are going to modify one previous recorded value.
|
// And finally, save everything! We are going to modify one previous recorded value.
|
||||||
$messagesSink = $this->redirectMessages();
|
$messagessink = $this->redirectMessages();
|
||||||
$data[2]['value'] = 2; // 2 is value of the option 'b'.
|
$data[2]['value'] = 2; // 2 is value of the option 'b'.
|
||||||
$secondpagedata = [$data[2], $data[3], $data[4], $data[5], $data[6]];
|
$secondpagedata = [$data[2], $data[3], $data[4], $data[5], $data[6]];
|
||||||
$result = mod_feedback_external::process_page($this->feedback->id, 1, $secondpagedata);
|
$result = mod_feedback_external::process_page($this->feedback->id, 1, $secondpagedata);
|
||||||
|
@ -544,8 +544,8 @@ class mod_feedback_external_testcase extends externallib_advanced_testcase {
|
||||||
$this->assertEquals(0, $completed->courseid);
|
$this->assertEquals(0, $completed->courseid);
|
||||||
|
|
||||||
// Test notifications sent.
|
// Test notifications sent.
|
||||||
$messages = $messagesSink->get_messages();
|
$messages = $messagessink->get_messages();
|
||||||
$messagesSink->close();
|
$messagessink->close();
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
$customdata = json_decode($messages[0]->customdata);
|
$customdata = json_decode($messages[0]->customdata);
|
||||||
$this->assertEquals($this->feedback->id, $customdata->instance);
|
$this->assertEquals($this->feedback->id, $customdata->instance);
|
||||||
|
|
|
@ -360,6 +360,9 @@ class send_user_notifications extends \core\task\adhoc_task {
|
||||||
'discussionid' => $discussion->id,
|
'discussionid' => $discussion->id,
|
||||||
'postid' => $post->id,
|
'postid' => $post->id,
|
||||||
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
|
||||||
|
'actionbuttons' => [
|
||||||
|
'reply' => get_string_manager()->get_string('reply', 'forum', null, $eventdata->userto->lang),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
return message_send($eventdata);
|
return message_send($eventdata);
|
||||||
|
|
|
@ -1536,5 +1536,7 @@ class mod_forum_mail_testcase extends advanced_testcase {
|
||||||
$this->assertEquals($post->id, $customdata->postid);
|
$this->assertEquals($post->id, $customdata->postid);
|
||||||
$this->assertEquals($discussion->id, $customdata->discussionid);
|
$this->assertEquals($discussion->id, $customdata->discussionid);
|
||||||
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
|
||||||
|
$this->assertObjectHasAttribute('actionbuttons', $customdata);
|
||||||
|
$this->assertCount(1, (array) $customdata->actionbuttons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1193,6 +1193,7 @@ class mod_quiz_external_testcase extends externallib_advanced_testcase {
|
||||||
$result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
|
$result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
|
||||||
$this->assertEquals(quiz_attempt::FINISHED, $result['state']);
|
$this->assertEquals(quiz_attempt::FINISHED, $result['state']);
|
||||||
$messages = $sink->get_messages();
|
$messages = $sink->get_messages();
|
||||||
|
$message = reset($messages);
|
||||||
$sink->close();
|
$sink->close();
|
||||||
// Test customdata.
|
// Test customdata.
|
||||||
if (!empty($message->customdata)) {
|
if (!empty($message->customdata)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue