From 6ee2611c63e7e553d2fa83a3663f92b49dee4148 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 15 Oct 2010 06:59:02 +0000 Subject: [PATCH] message MDL-24563 altered messaging so that forum post notifications aren't so overwhelming when viewed on /message/index.php --- lib/moodlelib.php | 27 ++++++++++++------- message/lib.php | 21 ++++++++++++--- message/output/email/message_output_email.php | 13 +-------- message/output/popup/message_output_popup.php | 18 ++++++------- mod/forum/lang/en/forum.php | 3 ++- mod/forum/lib.php | 8 +++++- theme/base/style/message.css | 1 + 7 files changed, 55 insertions(+), 36 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 96d46df1952..f6eca669f9a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 .= '
'.$smallmessage.'
'; + } } $strgomessage = get_string('gotomessages', 'message'); diff --git a/message/lib.php b/message/lib.php index 6fe36557d39..a7fc1f2258b 100644 --- a/message/lib.php +++ b/message/lib.php @@ -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 = "

---------------------------------------------------------------------
".$emailtagline; + //$eventdata->footer = "\n\n---------------------------------------------------------------------\n".$emailtagline; + if (!empty($eventdata->fullmessage)) { + $eventdata->fullmessage .= "\n\n---------------------------------------------------------------------\n".$emailtagline; + } + //$eventdata->footerhtml = "

---------------------------------------------------------------------
".$emailtagline; + if (!empty($eventdata->fullmessagehtml)) { + $eventdata->fullmessagehtml .= "

---------------------------------------------------------------------
".$emailtagline; + } $eventdata->timecreated = time(); return message_send($eventdata); diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index c64712b3263..e7fedd3773d 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -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? diff --git a/message/output/popup/message_output_popup.php b/message/output/popup/message_output_popup.php index 7ea4831ed67..2a64ba8b8c4 100644 --- a/message/output/popup/message_output_popup.php +++ b/message/output/popup/message_output_popup.php @@ -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; } diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 8b6a0653a31..037312fb95e 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -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'] = '

This post will be mailed out immediately to all forum subscribers.

'; $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}
To view: {$a->replylink}'; $string['startedby'] = 'Started by'; $string['subject'] = 'Subject'; $string['subscribe'] = 'Subscribe to this forum'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 4a253fef046..43722590d2b 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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){ diff --git a/theme/base/style/message.css b/theme/base/style/message.css index 1610360c571..c203cb90e3d 100644 --- a/theme/base/style/message.css +++ b/theme/base/style/message.css @@ -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;}