mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-54708 message: change popover processor to nav bar notification
This commit is contained in:
parent
c5dd16a111
commit
607454d6f3
@ -8817,103 +8817,6 @@ function fullclone($thing) {
|
||||
return unserialize(serialize($thing));
|
||||
}
|
||||
|
||||
/**
|
||||
* If new messages are waiting for the current user, then insert
|
||||
* JavaScript to pop up the messaging window into the page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function message_popup_window() {
|
||||
global $USER, $DB, $PAGE, $CFG;
|
||||
|
||||
if (!$PAGE->get_popup_notification_allowed() || empty($CFG->messaging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isloggedin() || isguestuser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($USER->message_lastpopup)) {
|
||||
$USER->message_lastpopup = 0;
|
||||
} else if ($USER->message_lastpopup > (time()-120)) {
|
||||
// Don't run the query to check whether to display a popup if its been run in the last 2 minutes.
|
||||
return;
|
||||
}
|
||||
|
||||
// A quick query to check whether the user has new messages.
|
||||
$messagecount = $DB->count_records('message', array('useridto' => $USER->id));
|
||||
if ($messagecount < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// There are unread messages so now do a more complex but slower query.
|
||||
$messagesql = "SELECT m.id, c.blocked
|
||||
FROM {message} m
|
||||
JOIN {message_working} mw ON m.id=mw.unreadmessageid
|
||||
JOIN {message_processors} p ON mw.processorid=p.id
|
||||
LEFT JOIN {message_contacts} c ON c.contactid = m.useridfrom
|
||||
AND c.userid = m.useridto
|
||||
WHERE m.useridto = :userid
|
||||
AND p.name='popup'";
|
||||
|
||||
// If the user was last notified over an hour ago we can re-notify them of old messages
|
||||
// so don't worry about when the new message was sent.
|
||||
$lastnotifiedlongago = $USER->message_lastpopup < (time()-3600);
|
||||
if (!$lastnotifiedlongago) {
|
||||
$messagesql .= 'AND m.timecreated > :lastpopuptime';
|
||||
}
|
||||
|
||||
$waitingmessages = $DB->get_records_sql($messagesql, array('userid' => $USER->id, 'lastpopuptime' => $USER->message_lastpopup));
|
||||
|
||||
$validmessages = 0;
|
||||
foreach ($waitingmessages as $messageinfo) {
|
||||
if ($messageinfo->blocked) {
|
||||
// Message is from a user who has since been blocked so just mark it read.
|
||||
// Get the full message to mark as read.
|
||||
$messageobject = $DB->get_record('message', array('id' => $messageinfo->id));
|
||||
message_mark_message_read($messageobject, time());
|
||||
} else {
|
||||
$validmessages++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($validmessages > 0) {
|
||||
$strmessages = get_string('unreadnewmessages', 'message', $validmessages);
|
||||
$strgomessage = get_string('gotomessages', 'message');
|
||||
$strstaymessage = get_string('ignore', 'admin');
|
||||
|
||||
$notificationsound = null;
|
||||
$beep = get_user_preferences('message_beepnewmessage', '');
|
||||
if (!empty($beep)) {
|
||||
// Browsers will work down this list until they find something they support.
|
||||
$sourcetags = html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.wav', 'type' => 'audio/wav'));
|
||||
$sourcetags .= html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.ogg', 'type' => 'audio/ogg'));
|
||||
$sourcetags .= html_writer::empty_tag('source', array('src' => $CFG->wwwroot.'/message/bell.mp3', 'type' => 'audio/mpeg'));
|
||||
$sourcetags .= html_writer::empty_tag('embed', array('src' => $CFG->wwwroot.'/message/bell.wav', 'autostart' => 'true', 'hidden' => 'true'));
|
||||
|
||||
$notificationsound = html_writer::tag('audio', $sourcetags, array('preload' => 'auto', 'autoplay' => 'autoplay'));
|
||||
}
|
||||
|
||||
$url = $CFG->wwwroot.'/message/index.php';
|
||||
$content = html_writer::start_tag('div', array('id' => 'newmessageoverlay', 'class' => 'mdl-align')).
|
||||
html_writer::start_tag('div', array('id' => 'newmessagetext')).
|
||||
$strmessages.
|
||||
html_writer::end_tag('div').
|
||||
|
||||
$notificationsound.
|
||||
html_writer::start_tag('div', array('id' => 'newmessagelinks')).
|
||||
html_writer::link($url, $strgomessage, array('id' => 'notificationyes')).' '.
|
||||
html_writer::link('', $strstaymessage, array('id' => 'notificationno')).
|
||||
html_writer::end_tag('div');
|
||||
html_writer::end_tag('div');
|
||||
|
||||
$PAGE->requires->js_init_call('M.core_message.init_notification', array('', $content, $url));
|
||||
|
||||
$USER->message_lastpopup = time();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to make sure that $min <= $value <= $max
|
||||
*
|
||||
|
@ -3198,9 +3198,11 @@ EOD;
|
||||
* @return string HTML for the notification menu
|
||||
*/
|
||||
public function notification_menu() {
|
||||
global $USER;
|
||||
global $USER, $DB;
|
||||
|
||||
if (isloggedin()) {
|
||||
$processor = $DB->get_record('message_processors', array('name' => 'popup'));
|
||||
|
||||
if (isloggedin() && $processor->enabled) {
|
||||
$context = [
|
||||
'userid' => $USER->id,
|
||||
'urls' => [
|
||||
|
@ -1501,9 +1501,6 @@ class moodle_page {
|
||||
$title .= ' - ';
|
||||
}
|
||||
$this->set_title($title . get_string('maintenancemode', 'admin'));
|
||||
} else {
|
||||
// Show the messaging popup if there are messages.
|
||||
message_popup_window();
|
||||
}
|
||||
|
||||
$this->initialise_standard_body_classes();
|
||||
|
@ -17,33 +17,6 @@ M.core_message.combinedsearchgotfocus = function(e) {
|
||||
}
|
||||
};
|
||||
|
||||
M.core_message.init_notification = function(Y, title, content, url) {
|
||||
Y.use('overlay', function() {
|
||||
var o = new Y.Overlay({
|
||||
headerContent : title,
|
||||
bodyContent : content
|
||||
});
|
||||
o.render(Y.one(document.body));
|
||||
|
||||
if (Y.UA.ie > 0 && Y.UA.ie < 7) {
|
||||
// Adjust for IE 6 (can't handle fixed pos)
|
||||
//align the bottom right corner of the overlay with the bottom right of the viewport
|
||||
o.set("align", {
|
||||
points:[Y.WidgetPositionAlign.BR, Y.WidgetPositionAlign.BR]
|
||||
});
|
||||
}
|
||||
|
||||
Y.one('#notificationyes').on('click', function(e) {
|
||||
window.location.href = url;
|
||||
}, o);
|
||||
Y.one('#notificationno').on('click', function(e) {
|
||||
o.hide();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}, o);
|
||||
});
|
||||
};
|
||||
|
||||
M.core_message.init_defaultoutputs = function(Y) {
|
||||
var defaultoutputs = {
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Popup message processor, stores messages to be shown using the message popup
|
||||
* Popup message processor
|
||||
*
|
||||
* @package message_popup
|
||||
* @copyright 2008 Luis Rodrigues
|
||||
@ -35,33 +35,12 @@ require_once($CFG->dirroot.'/message/output/lib.php');
|
||||
class message_output_popup extends message_output{
|
||||
|
||||
/**
|
||||
* Process the popup message.
|
||||
* The popup doesn't send data only saves in the database for later use,
|
||||
* the popup_interface.php takes the message from the message table into
|
||||
* the message_read.
|
||||
* Do nothing on send_message.
|
||||
*
|
||||
* @param object $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
|
||||
* @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);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,6 @@ class core_message_renderer extends plugin_renderer_base {
|
||||
|
||||
//load general messaging preferences
|
||||
$preferences->blocknoncontacts = get_user_preferences( 'message_blocknoncontacts', '', $user->id);
|
||||
$preferences->beepnewmessage = get_user_preferences( 'message_beepnewmessage', '', $user->id);
|
||||
$preferences->mailformat = $user->mailformat;
|
||||
$preferences->mailcharset = get_user_preferences( 'mailcharset', '', $user->id);
|
||||
|
||||
@ -501,7 +500,6 @@ class core_message_renderer extends plugin_renderer_base {
|
||||
|
||||
$generalsettingscontext = [
|
||||
'userid' => $user->id,
|
||||
'beepnewmessage' => $preferences->beepnewmessage,
|
||||
'blocknoncontacts' => $preferences->blocknoncontacts,
|
||||
'disableall' => $user->emailstop,
|
||||
'disableallhelpicon' => $this->output->help_icon('disableall', 'message'),
|
||||
|
@ -33,12 +33,6 @@
|
||||
}}
|
||||
<h2 class="title-case">{{#str}} generalsettings, admin {{/str}}</h2>
|
||||
<div class="general-settings-container" data-user-id="{{userid}}">
|
||||
<label data-preference-key="message_beepnewmessage">
|
||||
<input type="checkbox" {{#beepnewmessage}}checked{{/beepnewmessage}} />
|
||||
{{#str}} beepnewmessage, message {{/str}}
|
||||
<div class="loading-icon">{{> message/loading }}</div>
|
||||
</label>
|
||||
<br/>
|
||||
<label data-preference-key="message_blocknoncontacts">
|
||||
<input type="checkbox" {{#blocknoncontacts}}checked{{/blocknoncontacts}} />
|
||||
{{#str}} blocknoncontacts, message {{/str}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user