# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/admin/settings/subsystems.php
--- moodle/admin/settings/subsystems.php Base (1.10)
+++ moodle/admin/settings/subsystems.php Locally Modified (Based On 1.10)
@@ -15,6 +15,8 @@
 
     $optionalsubsystems->add(new admin_setting_configcheckbox('messaging', get_string('messaging', 'admin'), get_string('configmessaging','admin'), 1));
 
+    $optionalsubsystems->add(new admin_setting_configcheckbox('messaginghidereadnotifications', get_string('messaginghidereadnotifications', 'admin'), get_string('configmessaginghidereadnotifications','admin'), 0));
+
     $optionalsubsystems->add(new admin_setting_configcheckbox('enablestats', get_string('enablestats', 'admin'), get_string('configenablestats', 'admin'), 0));
 
     $optionalsubsystems->add(new admin_setting_configcheckbox('enablerssfeeds', get_string('enablerssfeeds', 'admin'), get_string('configenablerssfeeds', 'admin'), 0));
Index: moodle/lang/en/admin.php
--- moodle/lang/en/admin.php Base (1.133)
+++ moodle/lang/en/admin.php Locally Modified (Based On 1.133)
@@ -259,6 +259,7 @@
 $string['configmemcachedhosts'] = 'For memcached. Comma-separated list of hosts that are running the memcached daemon. Use IP addresses to avoid DNS latency. memcached does not behave well if you add/remove hosts on a running setup.';
 $string['configmemcachedpconn'] = 'For memcached. Use persistent connections. Use carefully -- it can make Apache/PHP crash after a restart of the memcached daemon.';
 $string['configmessaging'] = 'Should the messaging system between site users be enabled?';
+$string['configmessaginghidereadnotifications'] = 'Hide read notifications of events like forum posts when viewing messaging history';
 $string['configminpassworddigits'] = 'Passwords must have at least these many digits.';
 $string['configminpasswordlength'] = 'Passwords must be at least these many characters long.';
 $string['configminpasswordlower'] = 'Passwords must have at least these many lower case letters.';
@@ -679,6 +680,7 @@
 $string['memcachedhosts'] = 'memcached hosts';
 $string['memcachedpconn'] = 'memcached use persistent connections';
 $string['messaging'] = 'Enable messaging system';
+$string['messaginghidereadnotifications'] = 'Hide read notifications';
 $string['minpassworddigits'] = 'Digits';
 $string['minpasswordlength'] = 'Password length';
 $string['minpasswordlower'] = 'Lowercase letters';
Index: moodle/lib/db/install.xml
--- moodle/lib/db/install.xml Base (1.280)
+++ moodle/lib/db/install.xml Locally Modified (Based On 1.280)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20101019" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20101020" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
@@ -580,7 +580,8 @@
         <FIELD NAME="fullmessageformat" TYPE="int" LENGTH="4" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the full message" PREVIOUS="fullmessage" NEXT="fullmessagehtml"/>
         <FIELD NAME="fullmessagehtml" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="html format of message" PREVIOUS="fullmessageformat" NEXT="smallmessage"/>
         <FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="timecreated"/>
-        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage"/>
+        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="notification"/>
+        <FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -601,7 +602,8 @@
         <FIELD NAME="fullmessagehtml" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="html format of message" PREVIOUS="fullmessageformat" NEXT="smallmessage"/>
         <FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="timeread"/>
-        <FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
+        <FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="notification"/>
+        <FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeread"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
@@ -1630,7 +1632,7 @@
         <FIELD NAME="aggregatesubcats" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="ignore subcategories in aggregation" PREVIOUS="aggregateoutcomes" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="aggregatesubcats" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" PREVIOUS="timecreated" NEXT="hidden"/>
-        <FIELD NAME="hidden" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified"/>
\ No newline at end of file
+        <FIELD NAME="hidden" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timemodified"/>
\ No newline at end of file
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="courseid"/>
Index: moodle/lib/db/upgrade.php
--- moodle/lib/db/upgrade.php Base (1.493)
+++ moodle/lib/db/upgrade.php Locally Modified (Based On 1.493)
@@ -5299,7 +5299,7 @@
     //install.xml so there are 2.0 sites that are missing it.
     if ($oldversion < 2010101900) {
         $table = new xmldb_table('grade_categories');
-        $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
+        $field = new xmldb_field('hidden', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
 
         if (!$dbman->field_exists($table, $field)) {
             $dbman->add_field($table, $field);
@@ -5308,6 +5308,23 @@
         upgrade_main_savepoint(true, 2010101900);
     }
 
+    //MDL-24771
+    if ($oldversion < 2010102000) {
+        $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
+
+        $table = new xmldb_table('message');
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        $table = new xmldb_table('message_read');
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        upgrade_main_savepoint(true, 2010102000);
+    }
+
     return true;
 }
 
Index: moodle/lib/messagelib.php
--- moodle/lib/messagelib.php Base (1.21)
+++ moodle/lib/messagelib.php Locally Modified (Based On 1.21)
@@ -77,18 +77,12 @@
     $savemessage->fullmessagehtml   = $eventdata->fullmessagehtml;
     $savemessage->smallmessage      = $eventdata->smallmessage;
 
-    if (!empty($eventdata->footer)) {
-        $savemessage->footer = $eventdata->footer;
+    if (!empty($eventdata->notification)) {
+        $savemessage->notification = $eventdata->notification;
     } else {
-        $savemessage->footer = null;
+        $savemessage->notification = 0;
     }
 
-    if (!empty($eventdata->footerhtml)) {
-        $savemessage->footerhtml = $eventdata->footerhtml;
-    } else {
-        $savemessage->footerhtml = null;
-    }
-    
     $savemessage->timecreated = time();
 
     // Find out what processors are defined currently
Index: moodle/lib/moodlelib.php
--- moodle/lib/moodlelib.php Base (1.1483)
+++ moodle/lib/moodlelib.php Locally Modified (Based On 1.1483)
@@ -8919,7 +8919,7 @@
 
     $message_users = null;
 
-    $messagesql = "SELECT m.id, m.smallmessage, u.firstname, u.lastname FROM {message} m
+    $messagesql = "SELECT m.id, m.smallmessage, m.notification, 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
@@ -8944,7 +8944,9 @@
             $strmessages = get_string('unreadnewmessages', 'message', count($message_users));
         } else {
             $message_users = reset($message_users);
+            if (!$message_users->notification) {
             $strmessages = get_string('unreadnewmessage', 'message', fullname($message_users) );
+            }
 
             if (!empty($message_users->smallmessage)) {
                 //display the first 200 chars of the message in the popup
Index: moodle/message/index.php
--- moodle/message/index.php Base (1.39)
+++ moodle/message/index.php Locally Modified (Based On 1.39)
@@ -261,7 +261,7 @@
 
             $messagehistorylink .= html_writer::end_tag('div');
 
-            message_print_message_history($user1, $user2, $search, $displaycount, $messagehistorylink);
+            message_print_message_history($user1, $user2, $search, $displaycount, $messagehistorylink, $viewingnewmessages);
         echo html_writer::end_tag('div');
 
         //send message form
Index: moodle/message/lib.php
--- moodle/message/lib.php Base (1.141)
+++ moodle/message/lib.php Locally Modified (Based On 1.141)
@@ -1372,8 +1372,8 @@
 }
 
 //retrieve the messages between two users
-function message_get_history($user1, $user2, $limitnum=0) {
-    global $DB;
+function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) {
+    global $DB, $CFG;
 
     $messages = array();
 
@@ -1384,8 +1384,14 @@
         $sort = 'desc';
     }
 
-    if ($messages_read = $DB->get_records_select('message_read', "(useridto = ? AND useridfrom = ?) OR
-                                                    (useridto = ? AND useridfrom = ?)", array($user1->id, $user2->id, $user2->id, $user1->id),
+    $notificationswhere = null;
+    //we have just moved new messages to read. If theyre here to see new messages dont hide notifications
+    if (!$viewingnewmessages && $CFG->messaginghidereadnotifications) {
+        $notificationswhere = 'AND notification=0';
+    }
+
+    if ($messages_read = $DB->get_records_select('message_read', "((useridto = ? AND useridfrom = ?) OR
+                                                    (useridto = ? AND useridfrom = ?)) $notificationswhere", array($user1->id, $user2->id, $user2->id, $user1->id),
                                                     "timecreated $sort", '*', 0, $limitnum)) {
         foreach ($messages_read as $message) {
             $messages[$message->timecreated] = $message;
@@ -1408,7 +1414,7 @@
     return $messages;
 }
 
-function message_print_message_history($user1,$user2,$search='',$messagelimit=0, $messagehistorylink=false) {
+function message_print_message_history($user1,$user2,$search='',$messagelimit=0, $messagehistorylink=false, $viewingnewmessages=false) {
     global $CFG, $OUTPUT;
 
     echo $OUTPUT->box_start('center');
@@ -1449,7 +1455,7 @@
     }
 
     /// Get all the messages and print them
-    if ($messages = message_get_history($user1, $user2, $messagelimit)) {
+    if ($messages = message_get_history($user1, $user2, $messagelimit, $viewingnewmessages)) {
         $tablecontents = '';
 
         $current = new stdClass();
@@ -1459,6 +1465,11 @@
         $messagedate = get_string('strftimetime');
         $blockdate   = get_string('strftimedaydate');
         foreach ($messages as $message) {
+            if ($message->notification) {
+                $notificationclass = ' notification';
+            } else {
+                $notificationclass = null;
+            }
             $date = usergetdate($message->timecreated);
             if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
                 $current->mday = $date['mday'];
@@ -1469,9 +1480,9 @@
                 $tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'center').'</div>';
             }
             if ($message->useridfrom == $user1->id) {
-                $tablecontents .= '<div class="mdl-left left">'.message_format_message($message, $user1, $messagedate, $search, 'me').'</div><br />';
+                $tablecontents .= "<div class='mdl-left left $notificationclass'>".message_format_message($message, $user1, $messagedate, $search, 'me').'</div><br />';
             } else {
-                $tablecontents .= '<div class="mdl-left right">'.message_format_message($message, $user2, $messagedate, $search, 'other').'</div><br />';
+                $tablecontents .= "<div class='mdl-left right $notificationclass'>".message_format_message($message, $user2, $messagedate, $search, 'other').'</div><br />';
             }
         }
 
@@ -1533,11 +1544,9 @@
     $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;
     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;
     }
Index: moodle/mod/forum/lib.php
--- moodle/mod/forum/lib.php Base (1.906)
+++ moodle/mod/forum/lib.php Locally Modified (Based On 1.906)
@@ -642,6 +642,7 @@
                 $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);
+                $eventdata->notification = 1;
 
                 $mailresult = message_send($eventdata);
                 if (!$mailresult){
Index: moodle/theme/base/style/message.css
--- moodle/theme/base/style/message.css Base (1.5)
+++ moodle/theme/base/style/message.css Locally Modified (Based On 1.5)
@@ -40,6 +40,7 @@
 .message .messagearea .messagehistory .heading {width:100%;clear:both;}
 .message .messagearea .messagehistory .left {padding-bottom:10px;width:50%;float:left;clear:both;}
 .message .messagearea .messagehistory .right {padding-bottom:10px;width:50%;float:right;clear:both;}
+.message .messagearea .messagehistory .notification {padding:10px;background-color:#EEEEEE;}
 .message .messagearea .messagesend {padding-top:20px;float:center;clear:both;}
 .message .messagearea .messagesend .messagesendbox {width:100%}
 .message .messagearea .messagesend fieldset {padding:0px;margin:0;} /** bring the message send button closer to the message box */
@@ -51,6 +52,6 @@
 .messagesearchresults td {padding:0px 10px 0px 20px;}
 .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;}
+#newmessageoverlay {background-color:LightGrey;border:1px solid black;padding:20px;position:fixed;bottom:0;right:0;}
+#newmessageoverlay #usermessage {padding:10px;font-weightXX:bold;}
 .ie6 #newmessageoverlay {position:static;}
Index: moodle/version.php
--- moodle/version.php Base (1.1802)
+++ moodle/version.php Locally Modified (Based On 1.1802)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version = 2010101901;  // YYYYMMDD   = date of the last version bump
+$version = 2010102000;  // YYYYMMDD   = date of the last version bump
                         //         XX = daily increments
 
 $release = '2.0 RC1 (Build: 20101020)';  // Human-friendly version name
