'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
'ajax' => true,
),
- 'core_message_get_notifications' => array(
+ 'core_message_get_popup_notifications' => array(
'classname' => 'core_message_external',
- 'methodname' => 'get_notifications',
+ 'methodname' => 'get_popup_notifications',
'classpath' => 'message/externallib.php',
- 'description' => 'Retrieve a list of notifications sent and received by a user',
+ 'description' => 'Retrieve a list of popup notifications for a user',
'type' => 'read',
'ajax' => true,
),
- 'core_message_get_unread_notification_count' => array(
+ 'core_message_get_unread_popup_notification_count' => array(
'classname' => 'core_message_external',
- 'methodname' => 'get_unread_notification_count',
+ 'methodname' => 'get_unread_popup_notification_count',
'classpath' => 'message/externallib.php',
- 'description' => 'Retrieve the count of unread notifications for a given user',
+ 'description' => 'Retrieve the count of unread popup notifications for a given user',
'type' => 'read',
'ajax' => true,
),
}
var request = {
- methodname: 'core_message_get_notifications',
+ methodname: 'core_message_get_popup_notifications',
args: args
};
*/
var countUnread = function(args) {
var request = {
- methodname: 'core_message_get_unread_notification_count',
+ methodname: 'core_message_get_unread_popup_notification_count',
args: args
};
}
/**
- * Get notifications parameters description.
+ * Get popup notifications parameters description.
*
* @return external_function_parameters
* @since 3.2
*/
- public static function get_notifications_parameters() {
+ public static function get_popup_notifications_parameters() {
return new external_function_parameters(
array(
'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED),
- 'useridfrom' => new external_value(
- PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user',
- VALUE_DEFAULT, 0),
'status' => new external_value(
PARAM_ALPHA, 'filter the results to just "read" or "unread" notifications',
VALUE_DEFAULT, ''),
* @throws invalid_parameter_exception
* @throws moodle_exception
* @param int $useridto the user id who received the message
- * @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user
* @param string $status filter the results to only read or unread notifications
* @param bool $embedpreference true to embed the recipient user details in the record for each notification
* @param bool $embeduserto true to embed the recipient user details in the record for each notification
* @param int $offset offset the result set by a given amount
* @return external_description
*/
- public static function get_notifications($useridto, $useridfrom, $status, $embedpreference,
+ public static function get_popup_notifications($useridto, $status, $embedpreference,
$embeduserto, $embeduserfrom, $newestfirst, $markasread, $limit, $offset) {
global $CFG, $USER, $OUTPUT;
$params = self::validate_parameters(
- self::get_notifications_parameters(),
+ self::get_popup_notifications_parameters(),
array(
'useridto' => $useridto,
- 'useridfrom' => $useridfrom,
'status' => $status,
'embedpreference' => $embedpreference,
'embeduserto' => $embeduserto,
self::validate_context($context);
$useridto = $params['useridto'];
- $useridfrom = $params['useridfrom'];
$status = $params['status'];
$embedpreference = $params['embedpreference'];
$embeduserto = $params['embeduserto'];
}
}
- if (!empty($useridfrom) && $embeduserfrom) {
- // We use get_user here because the from user can be the noreply or support user.
- $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST);
- }
-
// Check if the current user is the sender/receiver or just a privileged user.
- if ($useridto != $USER->id and $useridfrom != $USER->id and !$issuperuser) {
+ if ($useridto != $USER->id and !$issuperuser) {
throw new moodle_exception('accessdenied', 'admin');
}
$sort = $newestfirst ? 'DESC' : 'ASC';
- $notifications = message_get_notifications($useridto, $useridfrom, $status, $embeduserto, $embeduserfrom, $sort, $limit, $offset);
+ $notifications = message_get_popup_notifications($useridto, $status, $embeduserto, $embeduserfrom, $sort, $limit, $offset);
if ($notifications) {
- // In some cases, we don't need to get the to/from user objects from the sql query.
- $userfromfullname = '';
+ // In some cases, we don't need to get the to user objects from the sql query.
$usertofullname = '';
// In this case, the useridto field is not empty, so we can get the user destinatary fullname from there.
if (!empty($useridto) && $embeduserto) {
$usertofullname = fullname($userto);
- // The user from may or may not be filled.
- if (!empty($useridfrom) && $embeduserfrom) {
- $userfromfullname = fullname($userfrom);
- }
- } else if (!empty($useridfrom) && $embeduserfrom) {
- // If the useridto field is empty, the useridfrom must be filled.
- $userfromfullname = fullname($userfrom);
}
foreach ($notifications as $notification) {
- if (($useridto == $USER->id and $notification->timeusertodeleted) or
- ($useridfrom == $USER->id and $notification->timeuserfromdeleted)) {
-
+ if ($useridto == $USER->id and $notification->timeusertodeleted) {
$notification->deleted = true;
} else {
$notification->deleted = false;
// We need to get the user from the query.
if ($embeduserfrom) {
- if (empty($userfromfullname)) {
- // Check for non-reply and support users.
- if (core_user::is_real_user($notification->useridfrom)) {
- $user = new stdClass();
- $user = username_load_fields_from_object($user, $notification, 'userfrom');
- $profileurl = new moodle_url('/user/profile.php', array('id' => $notification->useridfrom));
- $notification->userfromfullname = fullname($user);
- $notification->userfromprofileurl = $profileurl->out();
- } else {
- $notification->userfromfullname = get_string('coresystem');
- }
+ // Check for non-reply and support users.
+ if (core_user::is_real_user($notification->useridfrom)) {
+ $user = new stdClass();
+ $user = username_load_fields_from_object($user, $notification, 'userfrom');
+ $profileurl = new moodle_url('/user/profile.php', array('id' => $notification->useridfrom));
+ $notification->userfromfullname = fullname($user);
+ $notification->userfromprofileurl = $profileurl->out();
} else {
- $notification->userfromfullname = $userfromfullname;
+ $notification->userfromfullname = get_string('coresystem');
}
}
return array(
'notifications' => $notifications,
- 'unreadcount' => message_count_unread_notifications($useridto, $useridfrom),
+ 'unreadcount' => message_count_unread_popup_notifications($useridto),
);
}
* @return external_single_structure
* @since 3.2
*/
- public static function get_notifications_returns() {
+ public static function get_popup_notifications_returns() {
return new external_single_structure(
array(
'notifications' => new external_multiple_structure(
* @return external_function_parameters
* @since 3.2
*/
- public static function get_unread_notification_count_parameters() {
+ public static function get_unread_popup_notification_count_parameters() {
return new external_function_parameters(
array(
'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED),
- 'useridfrom' => new external_value(
- PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user',
- VALUE_DEFAULT, 0),
)
);
}
* @throws invalid_parameter_exception
* @throws moodle_exception
* @param int $useridto the user id who received the message
- * @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user
* @return external_description
*/
- public static function get_unread_notification_count($useridto, $useridfrom) {
+ public static function get_unread_popup_notification_count($useridto) {
global $CFG, $USER;
$params = self::validate_parameters(
- self::get_unread_notification_count_parameters(),
- array(
- 'useridto' => $useridto,
- 'useridfrom' => $useridfrom,
- )
+ self::get_unread_popup_notification_count_parameters(),
+ array('useridto' => $useridto)
);
$context = context_system::instance();
self::validate_context($context);
$useridto = $params['useridto'];
- $useridfrom = $params['useridfrom'];
if (!empty($useridto)) {
if (core_user::is_real_user($useridto)) {
}
}
- if (!empty($useridfrom)) {
- // We use get_user here because the from user can be the noreply or support user.
- $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST);
- }
-
// Check if the current user is the sender/receiver or just a privileged user.
- if ($useridto != $USER->id and $useridfrom != $USER->id and
- !has_capability('moodle/site:readallmessages', $context)) {
+ if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
throw new moodle_exception('accessdenied', 'admin');
}
- return message_count_unread_notifications($useridto, $useridfrom);
+ return message_count_unread_popup_notifications($useridto);
}
/**
- * Get unread notification count return description.
+ * Get unread popup notification count return description.
*
* @return external_single_structure
* @since 3.2
*/
- public static function get_unread_notification_count_returns() {
+ public static function get_unread_popup_notification_count_returns() {
return new external_value(PARAM_INT, 'the user whose blocked users we want to retrieve');
}
}
/**
- * Get notifications to and from the specified users.
+ * Get popup notifications for the specified users.
*
* @param int $useridto the user id who received the notification
- * @param int $useridfrom the user id who sent the notification. -10 or -20 for no-reply or support user
* @param bool $status MESSAGE_READ for retrieving read notifications, MESSAGE_UNREAD for unread, empty for both
- * @param string $sort the column name to order by including optionally direction
* @param bool $embeduserto embed the to user details in the notification response
* @param bool $embeduserfrom embed the from user details in the notification response
+ * @param string $sort the column name to order by including optionally direction
* @param int $limit limit the number of result returned
* @param int $offset offset the result set by this amount
* @return array array of notification records
- * @since 3.1
+ * @since 3.2
*/
-function message_get_notifications($useridto = 0, $useridfrom = 0, $status = '',
+function message_get_popup_notifications($useridto = 0, $status = '',
$embeduserto = false, $embeduserfrom = false, $sort = 'DESC', $limit = 0, $offset = 0) {
global $DB;
throw new moodle_exception('invalid parameter: sort: must be "DESC" or "ASC"');
}
+ if (empty($useridto)) {
+ $useridto = $USER->id;
+ }
+
$params = array();
- $buildtablesql = function($table, $prefix, $additionalfields) use ($useridto, $useridfrom, $embeduserto, $embeduserfrom) {
- $params = array();
+ $buildtablesql = function($table, $prefix, $additionalfields, $messagestatus)
+ use ($status, $useridto, $embeduserto, $embeduserfrom) {
+
+ $joinsql = '';
$fields = "concat('$prefix', $prefix.id) as uniqueid, $prefix.id, $prefix.useridfrom, $prefix.useridto,
$prefix.subject, $prefix.fullmessage, $prefix.fullmessageformat,
$prefix.fullmessagehtml, $prefix.smallmessage, $prefix.notification, $prefix.contexturl,
$prefix.contexturlname, $prefix.timecreated, $prefix.timeuserfromdeleted, $prefix.timeusertodeleted,
$prefix.component, $prefix.eventtype, $additionalfields";
- $where = '';
- $joinsql = '';
-
- if (empty($useridto)) {
- $where .= " AND $prefix.useridfrom = :{$prefix}useridfrom";
- $params["{$prefix}useridfrom"] = $useridfrom;
- } else {
- $where .= " AND $prefix.useridto = :{$prefix}useridto";
- $params["{$prefix}useridto"] = $useridto;
-
- if (!empty($useridfrom)) {
- $where .= " AND $prefix.useridfrom = :{$prefix}useridfrom";
- $params["{$prefix}useridfrom"] = $useridfrom;
- }
- }
+ $where = " AND $prefix.useridto = :{$prefix}useridto";
+ $params = ["{$prefix}useridto" => $useridto];
if ($embeduserto) {
$embedprefix = "{$prefix}ut";
$joinsql .= " LEFT JOIN {user} $embedprefix ON $embedprefix.id = $prefix.useridfrom";
}
- return array(sprintf("SELECT %s FROM %s %s %s WHERE %s.notification = 1 %s", $fields, $table, $prefix, $joinsql, $prefix, $where), $params);
+ if ($messagestatus == MESSAGE_READ) {
+ $isread = '1';
+ } else {
+ $isread = '0';
+ }
+
+ return array(
+ sprintf(
+ "SELECT %s
+ FROM %s %s %s
+ WHERE %s.notification = 1
+ AND %s.id IN (SELECT messageid FROM {message_popup} WHERE isread = %s)
+ %s",
+ $fields, $table, $prefix, $joinsql, $prefix, $prefix, $isread, $where
+ ),
+ $params
+ );
};
$sql = '';
switch ($status) {
case MESSAGE_READ:
- list($sql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread');
+ list($sql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread', MESSAGE_READ);
$params = array_merge($params, $readparams);
break;
case MESSAGE_UNREAD:
- list($sql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread');
+ list($sql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread', MESSAGE_UNREAD);
$params = array_merge($params, $unreadparams);
break;
default:
- list($readsql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread');
- list($unreadsql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread');
+ list($readsql, $readparams) = $buildtablesql('{message_read}', 'r', 'r.timeread', MESSAGE_READ);
+ list($unreadsql, $unreadparams) = $buildtablesql('{message}', 'u', '0 as timeread', MESSAGE_UNREAD);
$sql = sprintf("SELECT * FROM (%s UNION %s) f", $readsql, $unreadsql);
$params = array_merge($params, $readparams, $unreadparams);
}
* Count the unread notifications for a user.
*
* @param int $useridto the user id who received the notification
- * @param int $useridfrom the user id who sent the notification. -10 or -20 for no-reply or support user
* @return int count of the unread notifications
- * @since 3.1
+ * @since 3.2
*/
-function message_count_unread_notifications($useridto = 0, $useridfrom = 0) {
+function message_count_unread_popup_notifications($useridto = 0) {
global $USER, $DB;
if (empty($useridto)) {
$useridto = $USER->id;
}
- if (!empty($useridfrom)) {
- return $DB->count_records_select('message', "useridto = ? AND useridfrom = ? AND notification = 1",
- array($useridto, $useridfrom), "COUNT('id')");
- } else {
- return $DB->count_records_select('message', "useridto = ? AND notification = 1",
- array($useridto), "COUNT('id')");
- }
+ return $DB->count_records_sql(
+ "SELECT count(id)
+ FROM {message}
+ WHERE id IN (SELECT messageid FROM {message_popup} WHERE isread = 0)
+ AND useridto = ?",
+ [$useridto]
+ );
}
/**
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Event observers definition.
+ *
+ * @package message_output_popup
+ * @category event
+ * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$observers = array(
+
+ // Message viewed.
+ array(
+ 'eventname' => '\core\event\message_viewed',
+ 'callback' => 'message_output_popup::message_viewed',
+ 'includefile' => '/message/output/popup/message_output_popup.php'
+ )
+);
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="message/output/popup/db" VERSION="20160729" COMMENT="XMLDB file for Moodle message/output/popup"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
+>
+ <TABLES>
+ <TABLE NAME="message_popup" COMMENT="Keep state of notifications for the popup message processor">
+ <FIELDS>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+ <FIELD NAME="messageid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="isread" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+ </FIELDS>
+ <KEYS>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ </KEYS>
+ <INDEXES>
+ <INDEX NAME="messageid-isread" UNIQUE="true" FIELDS="messageid, isread"/>
+ </INDEXES>
+ </TABLE>
+ </TABLES>
+</XMLDB>
\ No newline at end of file
* @param int $oldversion The version that we are upgrading from
*/
function xmldb_message_popup_upgrade($oldversion) {
- global $CFG;
+ global $CFG, $DB;
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
+ $dbman = $DB->get_manager();
+
+ if ($oldversion < 2016052309) {
+
+ // Define table message_popup to be created.
+ $table = new xmldb_table('message_popup');
+
+ // Adding fields to table message_popup.
+ $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+ $table->add_field('messageid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
+ $table->add_field('isread', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
+
+ // Adding keys to table message_popup.
+ $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+
+ // Adding indexes to table message_popup.
+ $table->add_index('messageid-isread', XMLDB_INDEX_UNIQUE, array('messageid', 'isread'));
+
+ // Conditionally launch create table for message_popup.
+ if (!$dbman->table_exists($table)) {
+ $dbman->create_table($table);
+ }
+
+ // Popup savepoint reached.
+ upgrade_plugin_savepoint(true, 2016052309, 'message', 'popup');
+ }
+
return true;
}
* @copyright 2008 Luis Rodrigues and Martin Dougiamas
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class message_output_popup extends message_output{
+class message_output_popup extends message_output {
/**
* Do nothing on send_message.
* @return true if ok, false if error
*/
public function send_message($eventdata) {
+ global $DB;
+
+ //hold onto the popup processor id because /admin/cron.php sends a lot of messages at once
+ static $processorid = null;
+
+ //prevent users from getting popup notifications of messages to themselves (happens with forum notifications)
+ if ($eventdata->userfrom->id != $eventdata->userto->id) {
+ if (empty($processorid)) {
+ $processor = $DB->get_record('message_processors', array('name'=>'popup'));
+ $processorid = $processor->id;
+ }
+ $procmessage = new stdClass();
+ $procmessage->unreadmessageid = $eventdata->savedmessageid;
+ $procmessage->processorid = $processorid;
+
+ //save this message for later delivery
+ $DB->insert_record('message_working', $procmessage);
+
+ if ($eventdata->notification) {
+ if (!$DB->record_exists('message_popup', ['messageid' => $eventdata->savedmessageid, 'isread' => 0])) {
+ $record = new StdClass();
+ $record->messageid = $eventdata->savedmessageid;
+ $record->isread = 0;
+
+ $DB->insert_record('message_popup', $record);
+ }
+ }
+ }
+
return true;
}
global $USER;
return true;
}
+
+ /**
+ * Handles the message_viewed event to keep data in sync.
+ *
+ * @param \core\event\base $event The event data
+ */
+ public static function message_viewed(\core\event\base $event) {
+ global $DB;
+
+ if ($record = $DB->get_record('message_popup', ['messageid' => $event->other['messageid']])) {
+ // The id can change when the moving to the message_read table.
+ $record->messageid = $event->objectid;
+ $record->isread = 1;
+ $DB->update_record('message_popup', $record);
+ }
+ }
}
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2016052300; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version = 2016052309; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2016051900; // Requires this Moodle version
$plugin->component = 'message_popup'; // Full name of the plugin (used for diagnostics)
$insert = $DB->insert_record('message', $record);
}
- /**
- * Send a fake unread notification.
+ /**
+ * Send a fake unread popup notification.
*
* {@link message_send()} does not support transaction, this function will simulate a message
* sent from a user to another. We should stop using it once {@link message_send()} will support
* @param int $timecreated time the message was created.
* @return int the id of the message
*/
- protected function send_fake_unread_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0) {
+ protected function send_fake_unread_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0) {
global $DB;
$record = new stdClass();
$record->smallmessage = $message;
$record->timecreated = $timecreated ? $timecreated : time();
- return $DB->insert_record('message', $record);
+ $id = $DB->insert_record('message', $record);
+
+ $popup = new stdClass();
+ $popup->messageid = $id;
+ $popup->isread = 0;
+
+ $DB->insert_record('message_popup', $popup);
+
+ return $id;
}
/**
- * Send a fake read notification.
+ * Send a fake read popup notification.
*
* {@link message_send()} does not support transaction, this function will simulate a message
* sent from a user to another. We should stop using it once {@link message_send()} will support
* @param int $timecreated time the message was created.
* @return int the id of the message
*/
- protected function send_fake_read_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) {
+ protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) {
global $DB;
$record = new stdClass();
$record->timecreated = $timecreated ? $timecreated : time();
$record->timeread = $timeread ? $timeread : time();
- return $DB->insert_record('message_read', $record);
+ $id = $DB->insert_record('message_read', $record);
+
+ $popup = new stdClass();
+ $popup->messageid = $id;
+ $popup->isread = 1;
+
+ $DB->insert_record('message_popup', $popup);
+
+ return $id;
}
/**
}
- public function test_get_notifications_no_user_exception() {
+ public function test_get_popup_notifications_no_user_exception() {
$this->resetAfterTest(true);
$this->setExpectedException('moodle_exception');
- $result = core_message_external::get_notifications(-2132131, 0, '', false, false, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications(-2132131, '', false, false, false, true, false, 0, 0);
}
- public function test_get_notifications_access_denied_exception() {
+ public function test_get_popup_notifications_access_denied_exception() {
$this->resetAfterTest(true);
$sender = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->setExpectedException('moodle_exception');
- $result = core_message_external::get_notifications($sender->id, 0, '', false, false, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications($sender->id, '', false, false, false, true, false, 0, 0);
}
- public function test_get_notifications_as_recipient() {
+ public function test_get_popup_notifications_as_recipient() {
$this->resetAfterTest(true);
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Sendy', 'lastname' => 'Sender'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Recipy', 'lastname' => 'Recipient'));
$notificationids = array(
- $this->send_fake_unread_notification($sender, $recipient),
- $this->send_fake_unread_notification($sender, $recipient),
- $this->send_fake_read_notification($sender, $recipient),
- $this->send_fake_read_notification($sender, $recipient),
+ $this->send_fake_unread_popup_notification($sender, $recipient),
+ $this->send_fake_unread_popup_notification($sender, $recipient),
+ $this->send_fake_read_popup_notification($sender, $recipient),
+ $this->send_fake_read_popup_notification($sender, $recipient),
);
// Confirm that admin has super powers to retrieve any notifications.
$this->setAdminUser();
- $result = core_message_external::get_notifications($recipient->id, 0, '', false, false, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, '', false, false, false, true, false, 0, 0);
$this->assertCount(4, $result['notifications']);
$this->setUser($recipient);
- $result = core_message_external::get_notifications($recipient->id, 0, '', false, false, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, '', false, false, false, true, false, 0, 0);
$this->assertCount(4, $result['notifications']);
- $result = core_message_external::get_notifications($recipient->id, 0, MESSAGE_UNREAD, false, true, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, MESSAGE_UNREAD, false, false, true, true, false, 0, 0);
$this->assertCount(2, $result['notifications']);
$this->assertObjectHasAttribute('userfromfullname', $result['notifications'][0]);
$this->assertObjectNotHasAttribute('usertofullname', $result['notifications'][0]);
$this->assertObjectHasAttribute('userfromfullname', $result['notifications'][1]);
$this->assertObjectNotHasAttribute('usertofullname', $result['notifications'][1]);
- $result = core_message_external::get_notifications($recipient->id, 0, MESSAGE_UNREAD, true, true, true, false, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, MESSAGE_UNREAD, false, true, true, true, false, 0, 0);
$this->assertCount(2, $result['notifications']);
$this->assertObjectHasAttribute('userfromfullname', $result['notifications'][0]);
$this->assertObjectHasAttribute('usertofullname', $result['notifications'][0]);
$this->assertObjectHasAttribute('userfromfullname', $result['notifications'][1]);
$this->assertObjectHasAttribute('usertofullname', $result['notifications'][1]);
- $result = core_message_external::get_notifications($recipient->id, 0, MESSAGE_UNREAD, true, true, true, true, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, MESSAGE_UNREAD, false, true, true, true, true, 0, 0);
$this->assertCount(2, $result['notifications']);
$this->assertEquals(0, $result['unreadcount']);
- $result = core_message_external::get_notifications($recipient->id, 0, MESSAGE_UNREAD, true, true, true, true, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, MESSAGE_UNREAD, false, true, true, true, true, 0, 0);
$this->assertCount(0, $result['notifications']);
- $result = core_message_external::get_notifications($recipient->id, 0, MESSAGE_READ, true, true, true, true, 0, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, MESSAGE_READ, false, true, true, true, true, 0, 0);
$this->assertCount(4, $result['notifications']);
}
- public function test_get_notification_limit_offset() {
+ public function test_get_popup_notification_limit_offset() {
$this->resetAfterTest(true);
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Sendy', 'lastname' => 'Sender'));
$this->setUser($recipient);
$notificationids = array(
- $this->send_fake_unread_notification($sender, $recipient, 'Notification', 1),
- $this->send_fake_unread_notification($sender, $recipient, 'Notification', 2),
- $this->send_fake_unread_notification($sender, $recipient, 'Notification', 3),
- $this->send_fake_unread_notification($sender, $recipient, 'Notification', 4),
- $this->send_fake_read_notification($sender, $recipient, 'Notification', 5),
- $this->send_fake_read_notification($sender, $recipient, 'Notification', 6),
- $this->send_fake_read_notification($sender, $recipient, 'Notification', 7),
- $this->send_fake_read_notification($sender, $recipient, 'Notification', 8),
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Notification 1', 1),
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Notification 2', 2),
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Notification 3', 3),
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Notification 4', 4),
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Notification 5', 5),
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Notification 6', 6),
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Notification 7', 7),
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Notification 8', 8),
);
- $result = core_message_external::get_notifications($recipient->id, 0, '', false, false, true, false, 2, 0);
+ $result = core_message_external::get_popup_notifications($recipient->id, '', false, false, false, true, false, 2, 0);
$this->assertEquals($result['notifications'][0]->id, $notificationids[7]);
$this->assertEquals($result['notifications'][1]->id, $notificationids[6]);
- $result = core_message_external::get_notifications($recipient->id, 0, '', false, false, true, false, 2, 2);
+ $result = core_message_external::get_popup_notifications($recipient->id, '', false, false, false, true, false, 2, 2);
$this->assertEquals($result['notifications'][0]->id, $notificationids[5]);
$this->assertEquals($result['notifications'][1]->id, $notificationids[4]);
$this->setUser($recipient);
$notificationids = array(
- $this->send_fake_unread_notification($sender1, $recipient, 'Notification', 1),
- $this->send_fake_unread_notification($sender1, $recipient, 'Notification', 2),
- $this->send_fake_unread_notification($sender2, $recipient, 'Notification', 3),
- $this->send_fake_unread_notification($sender2, $recipient, 'Notification', 4),
- $this->send_fake_unread_notification($sender3, $recipient, 'Notification', 5),
- $this->send_fake_unread_notification($sender3, $recipient, 'Notification', 6),
+ $this->send_fake_unread_popup_notification($sender1, $recipient, 'Notification', 1),
+ $this->send_fake_unread_popup_notification($sender1, $recipient, 'Notification', 2),
+ $this->send_fake_unread_popup_notification($sender2, $recipient, 'Notification', 3),
+ $this->send_fake_unread_popup_notification($sender2, $recipient, 'Notification', 4),
+ $this->send_fake_unread_popup_notification($sender3, $recipient, 'Notification', 5),
+ $this->send_fake_unread_popup_notification($sender3, $recipient, 'Notification', 6),
);
core_message_external::mark_all_notifications_as_read($recipient->id, $sender1->id);
- $readresult = core_message_external::get_notifications($recipient->id, 0, 'read', false, false, true, false, 0, 0);
- $unreadresult = core_message_external::get_notifications($recipient->id, 0, 'unread', false, false, true, false, 0, 0);
+ $readresult = core_message_external::get_popup_notifications($recipient->id, 'read', false, false, false, true, false, 0, 0);
+ $unreadresult = core_message_external::get_popup_notifications($recipient->id, 'unread', false, false, false, true, false, 0, 0);
$this->assertCount(2, $readresult['notifications']);
$this->assertCount(4, $unreadresult['notifications']);
core_message_external::mark_all_notifications_as_read($recipient->id, 0);
- $readresult = core_message_external::get_notifications($recipient->id, 0, 'read', false, false, true, false, 0, 0);
- $unreadresult = core_message_external::get_notifications($recipient->id, 0, 'unread', false, false, true, false, 0, 0);
+ $readresult = core_message_external::get_popup_notifications($recipient->id, 'read', false, false, false, true, false, 0, 0);
+ $unreadresult = core_message_external::get_popup_notifications($recipient->id, 'unread', false, false, false, true, false, 0, 0);
$this->assertCount(6, $readresult['notifications']);
$this->assertCount(0, $unreadresult['notifications']);
}
- public function test_get_unread_notification_count_invalid_user_exception() {
+ public function test_get_unread_popup_notification_count_invalid_user_exception() {
$this->resetAfterTest(true);
$this->setExpectedException('moodle_exception');
- $result = core_message_external::get_unread_notification_count(-2132131, 0);
+ $result = core_message_external::get_unread_popup_notification_count(-2132131, 0);
}
- public function test_get_unread_notification_count_access_denied_exception() {
+ public function test_get_unread_popup_notification_count_access_denied_exception() {
$this->resetAfterTest(true);
$sender = $this->getDataGenerator()->create_user();
$this->setUser($user);
$this->setExpectedException('moodle_exception');
- $result = core_message_external::get_unread_notification_count($sender->id, 0);
- }
-
- public function test_get_unread_notification_count_missing_from_user_exception() {
- $this->resetAfterTest(true);
-
- $sender = $this->getDataGenerator()->create_user();
-
- $this->setUser($sender);
- $this->setExpectedException('moodle_exception');
- $result = core_message_external::get_unread_notification_count($sender->id, 99999);
+ $result = core_message_external::get_unread_popup_notification_count($sender->id, 0);
}
- public function test_get_unread_notification_count() {
+ public function test_get_unread_popup_notification_count() {
$this->resetAfterTest(true);
$sender1 = $this->getDataGenerator()->create_user();
$this->setUser($recipient);
$notificationids = array(
- $this->send_fake_unread_notification($sender1, $recipient, 'Notification', 1),
- $this->send_fake_unread_notification($sender1, $recipient, 'Notification', 2),
- $this->send_fake_unread_notification($sender2, $recipient, 'Notification', 3),
- $this->send_fake_unread_notification($sender2, $recipient, 'Notification', 4),
- $this->send_fake_unread_notification($sender3, $recipient, 'Notification', 5),
- $this->send_fake_unread_notification($sender3, $recipient, 'Notification', 6),
+ $this->send_fake_unread_popup_notification($sender1, $recipient, 'Notification', 1),
+ $this->send_fake_unread_popup_notification($sender1, $recipient, 'Notification', 2),
+ $this->send_fake_unread_popup_notification($sender2, $recipient, 'Notification', 3),
+ $this->send_fake_unread_popup_notification($sender2, $recipient, 'Notification', 4),
+ $this->send_fake_unread_popup_notification($sender3, $recipient, 'Notification', 5),
+ $this->send_fake_unread_popup_notification($sender3, $recipient, 'Notification', 6),
);
- $count = core_message_external::get_unread_notification_count($recipient->id, $sender1->id);
- $this->assertEquals($count, 2);
-
- $count = core_message_external::get_unread_notification_count($recipient->id, 0);
+ $count = core_message_external::get_unread_popup_notification_count($recipient->id);
$this->assertEquals($count, 6);
}
}
}
/**
- * Send a fake unread notification.
+ * Send a fake unread popup notification.
*
* {@link message_send()} does not support transaction, this function will simulate a message
* sent from a user to another. We should stop using it once {@link message_send()} will support
* @param int $timecreated time the message was created.
* @return int the id of the message
*/
- protected function send_fake_unread_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0) {
+ protected function send_fake_unread_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0) {
global $DB;
$record = new stdClass();
$record->smallmessage = $message;
$record->timecreated = $timecreated ? $timecreated : time();
- return $DB->insert_record('message', $record);
+ $id = $DB->insert_record('message', $record);
+
+ $popup = new stdClass();
+ $popup->messageid = $id;
+ $popup->isread = 0;
+
+ $DB->insert_record('message_popup', $popup);
+
+ return $id;
}
/**
- * Send a fake read notification.
+ * Send a fake read popup notification.
*
* {@link message_send()} does not support transaction, this function will simulate a message
* sent from a user to another. We should stop using it once {@link message_send()} will support
* @param int $timecreated time the message was created.
* @return int the id of the message
*/
- protected function send_fake_read_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) {
+ protected function send_fake_read_popup_notification($userfrom, $userto, $message = 'Hello world!', $timecreated = 0, $timeread = 0) {
global $DB;
$record = new stdClass();
$record->timecreated = $timecreated ? $timecreated : time();
$record->timeread = $timeread ? $timeread : time();
- return $DB->insert_record('message_read', $record);
+ $id = $DB->insert_record('message_read', $record);
+
+ $popup = new stdClass();
+ $popup->messageid = $id;
+ $popup->isread = 1;
+
+ $DB->insert_record('message_popup', $popup);
+
+ return $id;
}
/**
}
/**
- * Test that the message_get_notifications function will return only read notifications if requested.
+ * Test that the message_get_popup_notifications function will return only read notifications if requested.
*/
- public function test_message_get_notifications_read_only() {
+ public function test_message_get_popup_notifications_read_only() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 2);
- $this->send_fake_read_notification($sender, $recipient, 'Message 2', 4);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 2', 4);
- $notifications = message_get_notifications($recipient->id, 0, MESSAGE_READ);
+ $notifications = message_get_popup_notifications($recipient->id, MESSAGE_READ);
$this->assertEquals($notifications[0]->fullmessage, 'Message 2');
$this->assertEquals($notifications[1]->fullmessage, 'Message 1');
// Check if we request read and unread but there are only read messages, it should
// still return those correctly.
- $notifications = message_get_notifications($recipient->id, 0, '');
+ $notifications = message_get_popup_notifications($recipient->id, '');
$this->assertEquals($notifications[0]->fullmessage, 'Message 2');
$this->assertEquals($notifications[1]->fullmessage, 'Message 1');
}
/**
- * Test that the message_get_notifications function will return only unread notifications if requested.
+ * Test that the message_get_popup_notifications function will return only unread notifications if requested.
*/
- public function test_message_get_notifications_unread_only() {
+ public function test_message_get_popup_notifications_unread_only() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_unread_notification($sender, $recipient, 'Message 1', 2);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 4);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 1', 2);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 4);
- $notifications = message_get_notifications($recipient->id, 0, MESSAGE_UNREAD);
+ $notifications = message_get_popup_notifications($recipient->id, MESSAGE_UNREAD);
$this->assertEquals($notifications[0]->fullmessage, 'Message 2');
$this->assertEquals($notifications[1]->fullmessage, 'Message 1');
// Check if we request read and unread but there are only read messages, it should
// still return those correctly.
- $notifications = message_get_notifications($recipient->id, 0, '');
+ $notifications = message_get_popup_notifications($recipient->id, '');
$this->assertEquals($notifications[0]->fullmessage, 'Message 2');
$this->assertEquals($notifications[1]->fullmessage, 'Message 1');
}
/**
- * Test that the message_get_notifications function will return the correct notifications when both
+ * Test that the message_get_popup_notifications function will return the correct notifications when both
* read and unread notifications are included.
*/
- public function test_message_get_notifications_mixed() {
+ public function test_message_get_popup_notifications_mixed() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 1);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 2);
- $this->send_fake_read_notification($sender, $recipient, 'Message 3', 3, 1);
- $this->send_fake_read_notification($sender, $recipient, 'Message 4', 3, 2);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 5', 4);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 1);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 3', 3, 1);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 4', 3, 2);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 5', 4);
- $notifications = message_get_notifications($recipient->id, 0);
+ $notifications = message_get_popup_notifications($recipient->id);
$this->assertEquals($notifications[0]->fullmessage, 'Message 5');
$this->assertEquals($notifications[1]->fullmessage, 'Message 4');
$this->assertEquals($notifications[3]->fullmessage, 'Message 2');
$this->assertEquals($notifications[4]->fullmessage, 'Message 1');
- $notifications = message_get_notifications($recipient->id, 0, MESSAGE_READ);
+ $notifications = message_get_popup_notifications($recipient->id, MESSAGE_READ);
$this->assertEquals($notifications[0]->fullmessage, 'Message 4');
$this->assertEquals($notifications[1]->fullmessage, 'Message 3');
$this->assertEquals($notifications[2]->fullmessage, 'Message 1');
- $notifications = message_get_notifications($recipient->id, 0, MESSAGE_UNREAD);
+ $notifications = message_get_popup_notifications($recipient->id, MESSAGE_UNREAD);
$this->assertEquals($notifications[0]->fullmessage, 'Message 5');
$this->assertEquals($notifications[1]->fullmessage, 'Message 2');
}
/**
- * Test that the message_get_notifications function works correctly with limiting and offsetting
+ * Test that the message_get_popup_notifications function works correctly with limiting and offsetting
* the result set if requested.
*/
- public function test_message_get_notifications_all_with_limit_and_offset() {
+ public function test_message_get_popup_notifications_all_with_limit_and_offset() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 1);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 2);
- $this->send_fake_read_notification($sender, $recipient, 'Message 3', 3, 1);
- $this->send_fake_read_notification($sender, $recipient, 'Message 4', 3, 2);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 5', 4);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 6', 5);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 1);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 3', 3, 1);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 4', 3, 2);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 5', 4);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 6', 5);
- $notifications = message_get_notifications($recipient->id, 0, '', false, false, 'DESC', 2, 0);
+ $notifications = message_get_popup_notifications($recipient->id, '', false, false, 'DESC', 2, 0);
$this->assertEquals($notifications[0]->fullmessage, 'Message 6');
$this->assertEquals($notifications[1]->fullmessage, 'Message 5');
- $notifications = message_get_notifications($recipient->id, 0, '', false, false, 'DESC', 2, 2);
+ $notifications = message_get_popup_notifications($recipient->id, '', false, false, 'DESC', 2, 2);
$this->assertEquals($notifications[0]->fullmessage, 'Message 4');
$this->assertEquals($notifications[1]->fullmessage, 'Message 3');
- $notifications = message_get_notifications($recipient->id, 0, '', false, false, 'DESC', 0, 3);
+ $notifications = message_get_popup_notifications($recipient->id, '', false, false, 'DESC', 0, 3);
$this->assertEquals($notifications[0]->fullmessage, 'Message 3');
$this->assertEquals($notifications[1]->fullmessage, 'Message 2');
}
/**
- * Test that the message_get_notifications function returns correct values if specifying
- * a sender.
- */
- public function test_message_get_notifications_multiple_senders() {
- $sender1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
- $sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
- $recipient1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $recipient2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test4', 'lastname' => 'User4'));
-
- $this->send_fake_read_notification($sender1, $recipient1, 'Message 1', 1);
- $this->send_fake_unread_notification($sender1, $recipient1, 'Message 2', 2);
- $this->send_fake_read_notification($sender1, $recipient2, 'Message 3', 3);
- $this->send_fake_unread_notification($sender1, $recipient2, 'Message 4', 4);
- $this->send_fake_read_notification($sender2, $recipient1, 'Message 5', 5);
- $this->send_fake_unread_notification($sender2, $recipient1, 'Message 6', 6);
- $this->send_fake_read_notification($sender2, $recipient2, 'Message 7', 7);
- $this->send_fake_unread_notification($sender2, $recipient2, 'Message 8', 8);
-
- $notifications = message_get_notifications(0, $sender1->id, '', false, false, 'DESC');
-
- $this->assertEquals($notifications[0]->fullmessage, 'Message 4');
- $this->assertEquals($notifications[1]->fullmessage, 'Message 3');
- $this->assertEquals($notifications[2]->fullmessage, 'Message 2');
- $this->assertEquals($notifications[3]->fullmessage, 'Message 1');
-
- $notifications = message_get_notifications(0, $sender1->id, '', false, false, 'DESC', 2, 2);
-
- $this->assertEquals($notifications[0]->fullmessage, 'Message 2');
- $this->assertEquals($notifications[1]->fullmessage, 'Message 1');
-
- $notifications = message_get_notifications($recipient1->id, $sender1->id, '', false, false, 'DESC');
-
- $this->assertEquals($notifications[0]->fullmessage, 'Message 2');
- $this->assertEquals($notifications[1]->fullmessage, 'Message 1');
- }
-
- /**
- * Test that the message_get_notifications function returns embedded user details for the
+ * Test that the message_get_popup_notifications function returns embedded user details for the
* sender if requested.
*/
- public function test_message_get_notifications_embed_sender() {
+ public function test_message_get_popup_notifications_embed_sender() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 1);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 1);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 2);
- $notifications = message_get_notifications(0, $sender->id, '', false, true, 'DESC');
+ $notifications = message_get_popup_notifications($recipient->id, '', false, true, 'DESC');
$func = function($type) {
return function($notification) use ($type) {
}
/**
- * Test that the message_get_notifications function returns embedded user details for the
+ * Test that the message_get_popup_notifications function returns embedded user details for the
* recipient if requested.
*/
- public function test_message_get_notifications_embed_recipient() {
+ public function test_message_get_popup_notifications_embed_recipient() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 1);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 1);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 2);
- $notifications = message_get_notifications(0, $sender->id, '', true, false, 'DESC');
+ $notifications = message_get_popup_notifications($recipient->id, '', true, false, 'DESC');
$func = function($type) {
return function($notification) use ($type) {
}
/**
- * Test that the message_get_notifications function returns embedded all user details.
+ * Test that the message_get_popup_notifications function returns embedded all user details.
*/
- public function test_message_get_notifications_embed_both() {
+ public function test_message_get_popup_notifications_embed_both() {
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_read_notification($sender, $recipient, 'Message 1', 1);
- $this->send_fake_unread_notification($sender, $recipient, 'Message 2', 2);
+ $this->send_fake_read_popup_notification($sender, $recipient, 'Message 1', 1);
+ $this->send_fake_unread_popup_notification($sender, $recipient, 'Message 2', 2);
- $notifications = message_get_notifications(0, $sender->id, '', true, true, 'DESC');
+ $notifications = message_get_popup_notifications($recipient->id, '', true, true, 'DESC');
$func = function($type) {
return function($notification) use ($type) {
}
/**
- * Test message_count_unread_notifications.
+ * Test message_count_unread_popup_notifications.
*/
- public function test_message_count_unread_notifications() {
+ public function test_message_count_unread_popup_notifications() {
$sender1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
$recipient1 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
$recipient2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test4', 'lastname' => 'User4'));
- $this->send_fake_unread_notification($sender1, $recipient1);
- $this->send_fake_unread_notification($sender1, $recipient1);
- $this->send_fake_unread_notification($sender1, $recipient2);
- $this->send_fake_unread_notification($sender2, $recipient1);
- $this->send_fake_unread_notification($sender2, $recipient2);
- $this->send_fake_unread_notification($sender2, $recipient2);
-
- $this->assertEquals(message_count_unread_notifications($recipient1->id, $sender1->id), 2);
- $this->assertEquals(message_count_unread_notifications($recipient2->id, $sender1->id), 1);
- $this->assertEquals(message_count_unread_notifications($recipient1->id, $sender2->id), 1);
- $this->assertEquals(message_count_unread_notifications($recipient2->id, $sender2->id), 2);
- $this->assertEquals(message_count_unread_notifications($recipient1->id, 0), 3);
- $this->assertEquals(message_count_unread_notifications($recipient2->id, 0), 3);
+ $this->send_fake_unread_popup_notification($sender1, $recipient1);
+ $this->send_fake_unread_popup_notification($sender1, $recipient1);
+ $this->send_fake_unread_popup_notification($sender2, $recipient1);
+ $this->send_fake_unread_popup_notification($sender1, $recipient2);
+ $this->send_fake_unread_popup_notification($sender2, $recipient2);
+ $this->send_fake_unread_popup_notification($sender2, $recipient2);
+ $this->send_fake_unread_popup_notification($sender2, $recipient2);
+ $this->send_fake_unread_popup_notification($sender2, $recipient2);
+
+ $this->assertEquals(message_count_unread_popup_notifications($recipient1->id), 3);
+ $this->assertEquals(message_count_unread_popup_notifications($recipient2->id), 5);
}
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_unread_notification($sender, $recipient);
- $this->send_fake_unread_notification($sender, $recipient);
- $this->send_fake_unread_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);
$sender2 = $this->getDataGenerator()->create_user(array('firstname' => 'Test3', 'lastname' => 'User3'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_unread_notification($sender1, $recipient);
- $this->send_fake_unread_notification($sender1, $recipient);
- $this->send_fake_unread_notification($sender1, $recipient);
+ $this->send_fake_unread_popup_notification($sender1, $recipient);
+ $this->send_fake_unread_popup_notification($sender1, $recipient);
+ $this->send_fake_unread_popup_notification($sender1, $recipient);
$this->send_fake_message($sender1, $recipient);
$this->send_fake_message($sender1, $recipient);
$this->send_fake_message($sender1, $recipient);
- $this->send_fake_unread_notification($sender2, $recipient);
- $this->send_fake_unread_notification($sender2, $recipient);
- $this->send_fake_unread_notification($sender2, $recipient);
+ $this->send_fake_unread_popup_notification($sender2, $recipient);
+ $this->send_fake_unread_popup_notification($sender2, $recipient);
+ $this->send_fake_unread_popup_notification($sender2, $recipient);
$this->send_fake_message($sender2, $recipient);
$this->send_fake_message($sender2, $recipient);
$this->send_fake_message($sender2, $recipient);
$sender = $this->getDataGenerator()->create_user(array('firstname' => 'Test1', 'lastname' => 'User1'));
$recipient = $this->getDataGenerator()->create_user(array('firstname' => 'Test2', 'lastname' => 'User2'));
- $this->send_fake_unread_notification($sender, $recipient);
- $this->send_fake_unread_notification($sender, $recipient);
- $this->send_fake_unread_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
+ $this->send_fake_unread_popup_notification($sender, $recipient);
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);
$this->send_fake_message($sender, $recipient);