original_string: public static function mark_all_messages_as_read($userid, $conversationid = null) {
          global $DB;
  
          $messagesql = "SELECT m.*
                           FROM {messages} m
                     INNER JOIN {message_conversations} mc
                             ON mc.id = m.conversationid
                     INNER JOIN {message_conversation_members} mcm
                             ON mcm.conversationid = mc.id
                      LEFT JOIN {message_user_actions} mua
                             ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                          WHERE mua.id is NULL
                            AND mcm.userid = ?
                            AND m.useridfrom != ?";
          $messageparams = [];
          $messageparams[] = $userid;
          $messageparams[] = self::MESSAGE_ACTION_READ;
          $messageparams[] = $userid;
          $messageparams[] = $userid;
          if (!is_null($conversationid)) {
              $messagesql .= " AND mc.id = ?";
              $messageparams[] = $conversationid;
          }
  
          $messages = $DB->get_recordset_sql($messagesql, $messageparams);
          foreach ($messages as $message) {
              self::mark_message_as_read($userid, $message);
          }
          $messages->close();
      }
code: public static function mark_all_messages_as_read($userid, $conversationid = null) {
          global $DB;
  
          $messagesql = "SELECT m.*
                           FROM {messages} m
                     INNER JOIN {message_conversations} mc
                             ON mc.id = m.conversationid
                     INNER JOIN {message_conversation_members} mcm
                             ON mcm.conversationid = mc.id
                      LEFT JOIN {message_user_actions} mua
                             ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                          WHERE mua.id is NULL
                            AND mcm.userid = ?
                            AND m.useridfrom != ?";
          $messageparams = [];
          $messageparams[] = $userid;
          $messageparams[] = self::MESSAGE_ACTION_READ;
          $messageparams[] = $userid;
          $messageparams[] = $userid;
          if (!is_null($conversationid)) {
              $messagesql .= " AND mc.id = ?";
              $messageparams[] = $conversationid;
          }
  
          $messages = $DB->get_recordset_sql($messagesql, $messageparams);
          foreach ($messages as $message) {
              self::mark_message_as_read($userid, $message);
          }
          $messages->close();
      }
code_tokens: public static function mark_all_messages_as_read ( $ userid , $ conversationid = null ) { global $ DB ; $ messagesql = "SELECT m.*
                           FROM {messages} m
                     INNER JOIN {message_conversations} mc
                             ON mc.id = m.conversationid
                     INNER JOIN {message_conversation_members} mcm
                             ON mcm.conversationid = mc.id
                      LEFT JOIN {message_user_actions} mua
                             ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)
                          WHERE mua.id is NULL
                            AND mcm.userid = ?
                            AND m.useridfrom != ?" ; $ messageparams = [ ] ; $ messageparams [ ] = $ userid ; $ messageparams [ ] = self :: MESSAGE_ACTION_READ ; $ messageparams [ ] = $ userid ; $ messageparams [ ] = $ userid ; if ( ! is_null ( $ conversationid ) ) { $ messagesql .= " AND mc.id = ?" ; $ messageparams [ ] = $ conversationid ; } $ messages = $ DB -> get_recordset_sql ( $ messagesql , $ messageparams ) ; foreach ( $ messages as $ message ) { self :: mark_message_as_read ( $ userid , $ message ) ; } $ messages -> close ( ) ; }
docstring: Marks all messages being sent to a user in a particular conversation.
  
  If $conversationdid is null then it marks all messages as read sent to $userid.
  
  @param int $userid
  @param int|null $conversationid The conversation the messages belong to mark as read, if null mark all
docstring_tokens: Marks all messages being sent to a user in a particular conversation .