original_string: public static function can_delete_message($userid, $messageid) {
          global $DB, $USER;
  
          $systemcontext = \context_system::instance();
  
          $conversationid = $DB->get_field('messages', 'conversationid', ['id' => $messageid], MUST_EXIST);
  
          if (has_capability('moodle/site:deleteanymessage', $systemcontext)) {
              return true;
          }
  
          if (!self::is_user_in_conversation($userid, $conversationid)) {
              return false;
          }
  
          if (has_capability('moodle/site:deleteownmessage', $systemcontext) &&
                  $USER->id == $userid) {
              return true;
          }
  
          return false;
      }
code: public static function can_delete_message($userid, $messageid) {
          global $DB, $USER;
  
          $systemcontext = \context_system::instance();
  
          $conversationid = $DB->get_field('messages', 'conversationid', ['id' => $messageid], MUST_EXIST);
  
          if (has_capability('moodle/site:deleteanymessage', $systemcontext)) {
              return true;
          }
  
          if (!self::is_user_in_conversation($userid, $conversationid)) {
              return false;
          }
  
          if (has_capability('moodle/site:deleteownmessage', $systemcontext) &&
                  $USER->id == $userid) {
              return true;
          }
  
          return false;
      }
code_tokens: public static function can_delete_message ( $ userid , $ messageid ) { global $ DB , $ USER ; $ systemcontext = \ context_system :: instance ( ) ; $ conversationid = $ DB -> get_field ( 'messages' , 'conversationid' , [ 'id' => $ messageid ] , MUST_EXIST ) ; if ( has_capability ( 'moodle/site:deleteanymessage' , $ systemcontext ) ) { return true ; } if ( ! self :: is_user_in_conversation ( $ userid , $ conversationid ) ) { return false ; } if ( has_capability ( 'moodle/site:deleteownmessage' , $ systemcontext ) && $ USER -> id == $ userid ) { return true ; } return false ; }
docstring: Checks if a user can delete a message.
  
  @param int $userid the user id of who we want to delete the message for (this may be done by the admin
  but will still seem as if it was by the user)
  @param int $messageid The message id
  @return bool Returns true if a user can delete the message, false otherwise.
docstring_tokens: Checks if a user can delete a message .