/** * Bootstrap the application events. * * @return void */ public function boot() { Discussion::setValidator($this->app->make('validator')); $events = $this->app->make('events'); $settings = $this->app->make('Flarum\\Core\\Settings\\SettingsRepository'); $events->subscribe('Flarum\\Core\\Discussions\\Listeners\\DiscussionMetadataUpdater'); $events->listen(ModelAllow::class, function (ModelAllow $event) use($settings) { if ($event->model instanceof Discussion) { if ($event->actor->hasPermission('discussion.' . $event->action)) { return true; } if (($event->action === 'rename' || $event->action === 'delete') && $event->model->start_user_id == $event->actor->id) { $allowRenaming = $settings->get('allow_renaming'); if ($allowRenaming === '-1' || $allowRenaming === 'reply' && $event->model->participants_count <= 1 || $event->model->start_time->diffInMinutes(Carbon::now()) < $allowRenaming) { return true; } } } }); $events->listen(ScopeModelVisibility::class, function (ScopeModelVisibility $event) { if ($event->model instanceof Discussion) { $user = $event->actor; if (!$user->hasPermission('discussion.hide')) { $event->query->where(function ($query) use($user) { $query->whereNull('discussions.hide_time')->where('comments_count', '>', 0)->orWhere('start_user_id', $user->id); event(new ScopeHiddenDiscussionVisibility($query, $user, 'discussion.hide')); }); } } }); }
/** * Bootstrap the application events. * * @return void */ public function boot() { Discussion::setValidator($this->app->make('validator')); $events = $this->app->make('events'); $settings = $this->app->make('Flarum\\Core\\Settings\\SettingsRepository'); $events->subscribe('Flarum\\Core\\Discussions\\Listeners\\DiscussionMetadataUpdater'); $events->listen(ModelAllow::class, function (ModelAllow $event) use($settings) { if ($event->model instanceof Discussion) { if ($event->actor->hasPermission('discussion.' . $event->action)) { return true; } if (($event->action === 'rename' || $event->action === 'delete') && $event->model->start_user_id == $event->actor->id) { $allowRenaming = $settings->get('allow_renaming'); if ($allowRenaming === '-1' || $allowRenaming === 'reply' && $event->model->participants_count == 1 || $event->model->start_time->diffInMinutes(Carbon::now()) < $allowRenaming) { return true; } } } }); }