Gets whether the user has read this thread since the last post

@param User $user

@return boolean
965420
public function isUnread(User $user)
    {
        if ($this->posts->count() === 0) {
            return false;
        }

        return $this->posts->last()->isUnread($user);
    }
1336551
public function can_manually_control_post_read_status(stdClass $user) : bool {
        global $CFG;
        return $CFG->forum_usermarksread && isloggedin() && forum_tp_is_tracked($this->get_forum_record(), $user);
    }
400635
def unread(thread, user):
    
    return bool(thread.userthread_set.filter(user=user, unread=True))
141526
public function isReadable(int $user, int $group): bool
    {
        if ($this->user === $user) {
            $check = 0400;
        } elseif ($this->group === $group) {
            $check = 0040;
        } else {
            $check = 0004;
        }

        return (bool) ($this->permissions & $check);
    }
1231727
public static function get_user_role($user = null)
    {
        $wp_roles = \wp_roles();

        if ($user === null) {
            $user = \wp_get_current_user();
        }

        if (!($user instanceof WP_User)) {
            return false;
        }

        $roles = $user->roles;
        $role = \array_shift($roles);

        return isset($wp_roles->role_objects[ $role ]) ? $wp_roles->role_objects[ $role ] : false;
    }
1065815
public function delete($user, Thread $thread)
    {
        return Gate::allows('deleteThreads', $thread->category) || $user->getKey() === $thread->author_id;
    }
1165106
public function save(User $user) : bool
    {
        if (!$user->save()) {
            throw new \RuntimeException($this->i18n->t('setrun/user', 'Saving error'));
        }
        return true;
    }
525275
public function read(User $user, Notification $notification)
    {
        $notification->markAsRead();

        return $this->index($user, 'unread');
    }
861599
public function end(Users $user): bool
    {
        $this->find('users_id = ' . $user->getId())->delete();
        SessionKeys::find('users_id = ' . $user->getId())->delete();

        return true;
    }
1322616
public function isOwner(User $user)
    {
        $owner = $this->getOwner();
        if ($owner !== null && $user->getId() === $owner->getUser()->getId()) {
            return true;
        }

        return false;
    }
165449
public function next_user() {
        if (!$this->users_rs) {
            return false; // no users present
        }

        if (!$this->users_rs->valid()) {
            if ($current = $this->_pop()) {
                // this is not good - user or grades updated between the two reads above :-(
            }

            return false; // no more users
        } else {
            $user = $this->users_rs->current();
            $this->users_rs->next();
        }

        // find grades of this user
        $grade_records = array();
        while (true) {
            if (!$current = $this->_pop()) {
                break; // no more grades
            }

            if (empty($current->userid)) {
                break;
            }

            if ($current->userid != $user->id) {
                // grade of the next user, we have all for this user
                $this->_push($current);
                break;
            }

            $grade_records[$current->itemid] = $current;
        }

        $grades = array();
        $feedbacks = array();

        if (!empty($this->grade_items)) {
            foreach ($this->grade_items as $grade_item) {
                if (!isset($feedbacks[$grade_item->id])) {
                    $feedbacks[$grade_item->id] = new stdClass();
                }
                if (array_key_exists($grade_item->id, $grade_records)) {
                    $feedbacks[$grade_item->id]->feedback       = $grade_records[$grade_item->id]->feedback;
                    $feedbacks[$grade_item->id]->feedbackformat = $grade_records[$grade_item->id]->feedbackformat;
                    unset($grade_records[$grade_item->id]->feedback);
                    unset($grade_records[$grade_item->id]->feedbackformat);
                    $grades[$grade_item->id] = new grade_grade($grade_records[$grade_item->id], false);
                } else {
                    $feedbacks[$grade_item->id]->feedback       = '';
                    $feedbacks[$grade_item->id]->feedbackformat = FORMAT_MOODLE;
                    $grades[$grade_item->id] =
                        new grade_grade(array('userid'=>$user->id, 'itemid'=>$grade_item->id), false);
                }
                $grades[$grade_item->id]->grade_item = $grade_item;
            }
        }

        // Set user suspended status.
        $user->suspendedenrolment = isset($this->suspendedusers[$user->id]);
        $result = new stdClass();
        $result->user      = $user;
        $result->grades    = $grades;
        $result->feedbacks = $feedbacks;
        return $result;
    }
430969
public function has_user_read_post(stdClass $user, post_entity $post) : bool {
        global $CFG;
        $isoldpost = ($post->get_time_modified() < (time() - ($CFG->forum_oldpostdays * 24 * 3600)));

        if ($isoldpost) {
            return true;
        }

        $receipts = isset($this->receiptsbypostid[$post->get_id()]) ? $this->receiptsbypostid[$post->get_id()] : [];

        foreach ($receipts as $receipt) {
            if ($receipt->userid == $user->id) {
                return true;
            }
        }

        return false;
    }
1019649
public function deleteUser(User $user)
    {
        $parent = $user->getParent();
        if (!isset($this->userList[$user->getUsername()]) || $this->userList[$user->getUsername()] !== $user ||
            $parent == null
        ) {
            return false;
        }
        $this->connection->beginTransaction();
        $children = $this->getChildren($user);
        $success = true;
        foreach ($children as $child) {
            /** @var $child User */
            $success = $success && $child->setParent($parent);
        }
        $success = $success && $user->delete();

        if ($success) {
            $this->connection->commit();
            $this->setUpIterator();
        } else {
            $this->connection->rollBack();
        }
        return $success;
    }
871815
public function updateUnreadCount() {
    $unread = 0;

    // Get the user.
    $uid = $this->currentUser->id();
    // Get all the thread id's for this user.
    $threads = $this->getAllThreadIdsForUser($uid);

    if (empty($threads)) {
      return $unread;
    }

    // Check the last time someone other than the current user added
    // something to the threads.
    $thread_last_messages = $this->getLastMessagesFromOtherUsers($uid, $threads);
    if (empty($thread_last_messages)) {
      return $unread;
    }

    foreach ($thread_last_messages as $thread_id => $last_message) {
      // Check if the user has a timestamp on the thread.
      $thread_last_check = $this->userData->get('private_message', $uid, 'private_message_thread:' . $thread_id);
      if ($thread_last_check === NULL) {
        $thread_last_check = 0;
      }

      // Check if someone send a message after your last check.
      if ($last_message > $thread_last_check) {
        $unread++;
      }
    }
    return $unread;
  }
936332
public function restore(User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        try {
            $user->restore();

            $message = $this->transNotification('restored', ['name' => $user->full_name], $user->toArray());

            return $this->jsonResponseSuccess(compact('message'));
        }
        catch (\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
1314473
private function userAttemptBruteForceLockHasExceeded(User $user)
    {
        if ($user->login_attempt_lock_expiration > time()) {
            $user->updateAttributes(['login_attempt' => 0]);
            
            return true;
        }
        
        return false;
    }
1365349
public function hasAccess($accessKey, User $user = null)
    {
        if ($user === null) {
            $user = $this->currentUser();
        }

        if (is_array($accessKey)) {
            return $user->hasAnyAccess($accessKey);
        } else {
            return $user->hasAccess($accessKey);
        }
    }