public static function lastUnreadByUser($topic, $user) { if ($user === null) { return; } $startTime = TopicTrack::where('topic_id', $topic->topic_id)->where('user_id', $user->user_id)->value('mark_time'); if ($startTime === null) { return; } $unreadPostId = $topic->posts()->where('post_time', '>=', $startTime->getTimestamp())->value('post_id'); if ($unreadPostId === null) { return $topic->posts()->orderBy('post_id', 'desc')->value('post_id'); } return $unreadPostId; }
public static function lastUnreadByUser($topic, $user) { if ($user === null) { return null; } $startTime = TopicTrack::where("topic_id", $topic->topic_id)->where("user_id", $user->user_id)->value("mark_time"); if ($startTime === null) { return null; } $unreadPostId = $topic->posts()->where("post_time", ">=", $startTime->getTimestamp())->value("post_id"); if ($unreadPostId === null) { return $topic->posts()->orderBy("post_id", "desc")->value("post_id"); } return $unreadPostId; }
public function markRead($user, $markTime) { if ($user === null) { return; } $status = TopicTrack::where(['user_id' => $user->user_id, 'topic_id' => $this->topic_id]); if ($status->first() === null) { // first time seeing the topic, create tracking entry // and increment views count TopicTrack::create(['user_id' => $user->user_id, 'topic_id' => $this->topic_id, 'forum_id' => $this->forum_id, 'mark_time' => $markTime]); $this->increment('topic_views'); } elseif ($status->first()->mark_time < $markTime) { // laravel doesn't like composite key ;_; // and the setMarkTimeAttribute doesn't work here $status->update(['mark_time' => $markTime->getTimeStamp()]); } if ($this->topic_last_view_time < $markTime) { $this->topic_last_view_time = $markTime; $this->save(); } }