protected function getNewPosts()
    {
        Container::get('hooks')->fire('model.index.get_new_posts_start');

        $query['select'] = ['f.id', 'f.last_post'];
        $query['where'] = [
            ['fp.read_forum' => 'IS NULL'],
            ['fp.read_forum' => '1']
        ];
        $query = DB::forTable('forums')
            ->table_alias('f')
            ->select_many($query['select'])
            ->left_outer_join(
                DB::prefix().'forum_perms',
                '(`fp`.`forum_id`=`f`.`id` AND `fp`.`group_id`='.User::get()->g_id.')',
                'fp'
            )
//            ->left_outer_join(DB::prefix().'forum_perms', array('fp.forum_id', '=', 'f.id'), 'fp')
//            ->left_outer_join(DB::prefix().'forum_perms', array('fp.group_id', '=',
// User::get()->g_id), null, true)
//            ->where_any_is($query['where'])
            ->where_raw('(fp.read_forum IS NULL OR fp.read_forum = 1)')
            ->where_gt('f.last_post', User::get()->last_visit);

        $query = Container::get('hooks')->fireDB('model.index.query_get_new_posts', $query);

        $query = $query->find_result_set();

        $forums = $new_topics = [];
        $tracked_topics = Track::getTrackedTopics();

        foreach ($query as $cur_forum) {
            if (!isset($tracked_topics['forums'][$cur_forum->id]) ||
                $tracked_topics['forums'][$cur_forum->id] < $cur_forum->last_post) {
                $forums[$cur_forum->id] = $cur_forum->last_post;
            }
        }

        if (!empty($forums)) {
            if (empty($tracked_topics['topics'])) {
                $new_topics = $forums;
            } else {
                $query['select'] = ['forum_id', 'id', 'last_post'];

                $query = DB::forTable('topics')
                    ->select_many($query['select'])
                    ->where_in('forum_id', array_keys($forums))
                    ->where_gt('last_post', User::get()->last_visit)
                    ->where_null('moved_to');

                $query = Container::get('hooks')->fireDB('model.index.get_new_posts_query', $query);

                $query = $query->find_result_set();

                foreach ($query as $cur_topic) {
                    if (!isset($new_topics[$cur_topic->forum_id]) &&
                        (!isset($tracked_topics['forums'][$cur_topic->forum_id]) ||
                            $tracked_topics['forums'][$cur_topic->forum_id] < $forums[$cur_topic->forum_id]) &&
                        (!isset($tracked_topics['topics'][$cur_topic->id]) ||
                            $tracked_topics['topics'][$cur_topic->id] < $cur_topic->last_post)) {
                        $new_topics[$cur_topic->forum_id] = $forums[$cur_topic->forum_id];
                    }
                }
            }
        }

        $new_topics = Container::get('hooks')->fire('model.index.get_new_posts', $new_topics);

        return $new_topics;
    }