original_string: public static function mark_message_as_read($userid, $message, $timeread = null) {
          global $DB;
  
          if (is_null($timeread)) {
              $timeread = time();
          }
  
          $mua = new \stdClass();
          $mua->userid = $userid;
          $mua->messageid = $message->id;
          $mua->action = self::MESSAGE_ACTION_READ;
          $mua->timecreated = $timeread;
          $mua->id = $DB->insert_record('message_user_actions', $mua);
  
          // Get the context for the user who received the message.
          $context = \context_user::instance($userid, IGNORE_MISSING);
          // If the user no longer exists the context value will be false, in this case use the system context.
          if ($context === false) {
              $context = \context_system::instance();
          }
  
          // Trigger event for reading a message.
          $event = \core\event\message_viewed::create(array(
              'objectid' => $mua->id,
              'userid' => $userid, // Using the user who read the message as they are the ones performing the action.
              'context' => $context,
              'relateduserid' => $message->useridfrom,
              'other' => array(
                  'messageid' => $message->id
              )
          ));
          $event->trigger();
      }
code: public static function mark_message_as_read($userid, $message, $timeread = null) {
          global $DB;
  
          if (is_null($timeread)) {
              $timeread = time();
          }
  
          $mua = new \stdClass();
          $mua->userid = $userid;
          $mua->messageid = $message->id;
          $mua->action = self::MESSAGE_ACTION_READ;
          $mua->timecreated = $timeread;
          $mua->id = $DB->insert_record('message_user_actions', $mua);
  
          // Get the context for the user who received the message.
          $context = \context_user::instance($userid, IGNORE_MISSING);
          // If the user no longer exists the context value will be false, in this case use the system context.
          if ($context === false) {
              $context = \context_system::instance();
          }
  
          // Trigger event for reading a message.
          $event = \core\event\message_viewed::create(array(
              'objectid' => $mua->id,
              'userid' => $userid, // Using the user who read the message as they are the ones performing the action.
              'context' => $context,
              'relateduserid' => $message->useridfrom,
              'other' => array(
                  'messageid' => $message->id
              )
          ));
          $event->trigger();
      }
code_tokens: public static function mark_message_as_read ( $ userid , $ message , $ timeread = null ) { global $ DB ; if ( is_null ( $ timeread ) ) { $ timeread = time ( ) ; } $ mua = new \ stdClass ( ) ; $ mua -> userid = $ userid ; $ mua -> messageid = $ message -> id ; $ mua -> action = self :: MESSAGE_ACTION_READ ; $ mua -> timecreated = $ timeread ; $ mua -> id = $ DB -> insert_record ( 'message_user_actions' , $ mua ) ; // Get the context for the user who received the message. $ context = \ context_user :: instance ( $ userid , IGNORE_MISSING ) ; // If the user no longer exists the context value will be false, in this case use the system context. if ( $ context === false ) { $ context = \ context_system :: instance ( ) ; } // Trigger event for reading a message. $ event = \ core \ event \ message_viewed :: create ( array ( 'objectid' => $ mua -> id , 'userid' => $ userid , // Using the user who read the message as they are the ones performing the action. 'context' => $ context , 'relateduserid' => $ message -> useridfrom , 'other' => array ( 'messageid' => $ message -> id ) ) ) ; $ event -> trigger ( ) ; }
docstring: Mark a single message as read.
  
  @param int $userid The user id who marked the message as read
  @param \stdClass $message The message
  @param int|null $timeread The time the message was marked as read, if null will default to time()
docstring_tokens: Mark a single message as read .