message MDL-24563 altered messaging so that forum post notifications aren't so overwhelming when viewed on /message/index.php
This commit is contained in:
+18
-9
@@ -8920,23 +8920,20 @@ function message_popup_window() {
|
||||
|
||||
$message_users = null;
|
||||
|
||||
$sql = "SELECT m.id, u.firstname, u.lastname FROM {message} m
|
||||
$messagesql = "SELECT m.id, m.smallmessage, u.firstname, u.lastname FROM {message} m
|
||||
JOIN {message_working} mw ON m.id=mw.unreadmessageid
|
||||
JOIN {message_processors} p ON mw.processorid=p.id
|
||||
JOIN {user} u ON m.useridfrom=u.id
|
||||
WHERE m.useridto = :userid AND m.timecreated > :ts AND p.name='popup'";
|
||||
WHERE m.useridto = :userid AND p.name='popup'";
|
||||
|
||||
$sql = $messagesql.' AND m.timecreated > :ts';
|
||||
$message_users = $DB->get_records_sql($sql, array('userid'=>$USER->id, 'ts'=>$USER->message_lastpopup));
|
||||
if (empty($message_users)) {
|
||||
|
||||
//if the user was last notified over an hour ago remind them of any new messages regardless of when they were sent
|
||||
$canrenotify = (time() - $USER->message_lastpopup) > 3600;
|
||||
if ($canrenotify) {
|
||||
$sql = "SELECT m.id, u.firstname, u.lastname FROM {message} m
|
||||
JOIN {message_working} mw ON m.id=mw.unreadmessageid
|
||||
JOIN {message_processors} p ON mw.processorid=p.id
|
||||
JOIN {user} u ON m.useridfrom=u.id
|
||||
WHERE m.useridto = :userid AND p.name='popup'";
|
||||
$message_users = $DB->get_records_sql($sql, array('userid'=>$USER->id));
|
||||
$message_users = $DB->get_records_sql($messagesql, array('userid'=>$USER->id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8947,7 +8944,19 @@ WHERE m.useridto = :userid AND p.name='popup'";
|
||||
if (count($message_users)>1) {
|
||||
$strmessages = get_string('unreadnewmessages', 'message', count($message_users));
|
||||
} else {
|
||||
$strmessages = get_string('unreadnewmessage', 'message', fullname(reset($message_users)) );
|
||||
$message_users = reset($message_users);
|
||||
$strmessages = get_string('unreadnewmessage', 'message', fullname($message_users) );
|
||||
|
||||
if (!empty($message_users->smallmessage)) {
|
||||
//display the first 200 chars of the message in the popup
|
||||
$smallmessage = null;
|
||||
if (strlen($message_users->smallmessage>200)) {
|
||||
$smallmessage = substr($message_users->smallmessage,0,200).'...';
|
||||
} else {
|
||||
$smallmessage = $message_users->smallmessage;
|
||||
}
|
||||
$strmessages .= '<div id="usermessage">'.$smallmessage.'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$strgomessage = get_string('gotomessages', 'message');
|
||||
|
||||
+17
-4
@@ -1495,7 +1495,14 @@ function message_format_message(&$message, &$user, $format='', $keywords='', $cl
|
||||
$time = userdate($message->timecreated, $dateformat);
|
||||
$options = new stdClass();
|
||||
$options->para = false;
|
||||
$messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options);
|
||||
|
||||
//if supplied display small messages as fullmessage may contain boilerplate text that shouldnt appear in the messaging UI
|
||||
if (!empty($message->smallmessage)) {
|
||||
$messagetext = format_text($message->smallmessage, null, $options);
|
||||
} else {
|
||||
$messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options);
|
||||
}
|
||||
|
||||
if ($keywords) {
|
||||
$messagetext = highlight($keywords, $messagetext);
|
||||
}
|
||||
@@ -1519,15 +1526,21 @@ function message_post_message($userfrom, $userto, $message, $format, $messagetyp
|
||||
$eventdata->fullmessage = $message;
|
||||
$eventdata->fullmessageformat = $format;
|
||||
$eventdata->fullmessagehtml = '';
|
||||
$eventdata->smallmessage = '';
|
||||
$eventdata->smallmessage = $message;
|
||||
|
||||
$s = new stdClass();
|
||||
$s->sitename = $SITE->shortname;
|
||||
$s->url = $CFG->wwwroot.'/message/index.php?id='.$userfrom->id;//.'&user='.$userto->id;
|
||||
|
||||
$emailtagline = get_string('emailtagline', 'message', $s);
|
||||
$eventdata->footer = "\n\n---------------------------------------------------------------------\n".$emailtagline;
|
||||
$eventdata->footerhtml = "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
|
||||
//$eventdata->footer = "\n\n---------------------------------------------------------------------\n".$emailtagline;
|
||||
if (!empty($eventdata->fullmessage)) {
|
||||
$eventdata->fullmessage .= "\n\n---------------------------------------------------------------------\n".$emailtagline;
|
||||
}
|
||||
//$eventdata->footerhtml = "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
|
||||
if (!empty($eventdata->fullmessagehtml)) {
|
||||
$eventdata->fullmessagehtml .= "<br /><br />---------------------------------------------------------------------<br />".$emailtagline;
|
||||
}
|
||||
|
||||
$eventdata->timecreated = time();
|
||||
return message_send($eventdata);
|
||||
|
||||
@@ -50,19 +50,8 @@ class message_output_email extends message_output {
|
||||
$userto->email = $usertoemailaddress;
|
||||
}
|
||||
|
||||
//concatenating the footer on here so that it appears on emails but not within the saved message
|
||||
$messagetosend = null;
|
||||
if (!empty($message->fullmessage)) {
|
||||
$messagetosend = $message->fullmessage.$message->footer;
|
||||
}
|
||||
|
||||
$messagetosendhtml = null;
|
||||
if (!empty($message->fullmessagehtml)) {
|
||||
$messagetosendhtml = $message->fullmessagehtml.$message->footerhtml;
|
||||
}
|
||||
|
||||
$result = email_to_user($userto, $userfrom,
|
||||
$message->subject, $messagetosend, $messagetosendhtml);
|
||||
$message->subject, $message->fullmessage, $message->fullmessagehtml);
|
||||
|
||||
return $result===true; //email_to_user() can return true, false or "emailstop"
|
||||
//return true;//do we want to report an error if email sending fails?
|
||||
|
||||
@@ -39,16 +39,16 @@ class message_output_popup extends message_output{
|
||||
public function send_message($message) {
|
||||
global $DB;
|
||||
|
||||
//do we want to prevent users from messaging themselves?
|
||||
//if ($message->useridfrom==$message->useridto) {
|
||||
//prevent users from getting popup notifications of messages to themselves (happens with forum notifications)
|
||||
if ($message->useridfrom!=$message->useridto) {
|
||||
$processor = $DB->get_record('message_processors', array('name'=>'popup'));
|
||||
$procmessage = new stdClass();
|
||||
$procmessage->unreadmessageid = $message->id;
|
||||
$procmessage->processorid = $processor->id;
|
||||
|
||||
$processor = $DB->get_record('message_processors', array('name'=>'popup'));
|
||||
$procmessage = new stdClass();
|
||||
$procmessage->unreadmessageid = $message->id;
|
||||
$procmessage->processorid = $processor->id;
|
||||
|
||||
//save this message for later delivery
|
||||
$DB->insert_record('message_working', $procmessage);
|
||||
//save this message for later delivery
|
||||
$DB->insert_record('message_working', $procmessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ $string['postaddedtimeleft'] = 'You have {$a} to edit it if you want to make any
|
||||
$string['postincontext'] = 'See this post in context';
|
||||
$string['postmailinfo'] = 'This is a copy of a message posted on the {$a} website.
|
||||
|
||||
To add your reply via the website, click on this link:';
|
||||
To reply click on this link:';
|
||||
$string['postmailnow'] = '<p>This post will be mailed out immediately to all forum subscribers.</p>';
|
||||
$string['postrating1'] = 'Mostly Separate Knowing';
|
||||
$string['postrating2'] = 'Separate and Connected';
|
||||
@@ -336,6 +336,7 @@ $string['seeallposts'] = 'See all posts made by this user';
|
||||
$string['shortpost'] = 'Short post';
|
||||
$string['showsubscribers'] = 'Show/edit current subscribers';
|
||||
$string['singleforum'] = 'A single simple discussion';
|
||||
$string['smallmessage'] = '{$a->user} posted in {$a->forumname}<br />To view: {$a->replylink}';
|
||||
$string['startedby'] = 'Started by';
|
||||
$string['subject'] = 'Subject';
|
||||
$string['subscribe'] = 'Subscribe to this forum';
|
||||
|
||||
+7
-1
@@ -635,7 +635,13 @@ function forum_cron() {
|
||||
$eventdata->fullmessage = $posttext;
|
||||
$eventdata->fullmessageformat = FORMAT_PLAIN;
|
||||
$eventdata->fullmessagehtml = $posthtml;
|
||||
$eventdata->smallmessage = '';
|
||||
|
||||
$smallmessagestrings = new stdClass();
|
||||
$smallmessagestrings->user = fullname($userfrom);
|
||||
$smallmessagestrings->forumname = "{$course->shortname}->".format_string($forum->name,true);
|
||||
$smallmessagestrings->replylink = "$CFG->wwwroot/mod/forum/discuss.php?d=$discussion->id#p$post->id";
|
||||
$smallmessagestrings->message = $post->message;
|
||||
$eventdata->smallmessage = get_string('smallmessage', 'forum', $smallmessagestrings);
|
||||
|
||||
$mailresult = message_send($eventdata);
|
||||
if (!$mailresult){
|
||||
|
||||
@@ -52,4 +52,5 @@ table.message .searchresults td {padding:5px;}
|
||||
.messagesearchresults td span {white-space:nowrap;}
|
||||
|
||||
#newmessageoverlay {background-color:LightGrey;padding:20px;position:fixed;bottom:0;right:0;}
|
||||
#newmessageoverlay #usermessage {padding:10px;font-weight:bold;}
|
||||
.ie6 #newmessageoverlay {position:static;}
|
||||
|
||||
Reference in New Issue
Block a user