mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 17:10:45 +08:00
Only add posted activity if the post is visible publicly
This is very restrictive behaviour and we'll probably need to think of something a bit more powerful in the future. But it's a good stopgap.
This commit is contained in:
parent
667fe56947
commit
a2c3c4e51b
|
@ -5,6 +5,7 @@ use Flarum\Core\Activity\PostedBlueprint;
|
|||
use Flarum\Core\Activity\StartedDiscussionBlueprint;
|
||||
use Flarum\Core\Activity\JoinedBlueprint;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Users\Guest;
|
||||
use Flarum\Events\PostWasPosted;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Events\PostWasHidden;
|
||||
|
@ -95,9 +96,11 @@ class UserActivitySyncer
|
|||
*/
|
||||
protected function postBecameVisible(Post $post)
|
||||
{
|
||||
$blueprint = $this->postedBlueprint($post);
|
||||
if ($post->isVisibleTo(new Guest)) {
|
||||
$blueprint = $this->postedBlueprint($post);
|
||||
|
||||
$this->activity->sync($blueprint, [$post->user]);
|
||||
$this->activity->sync($blueprint, [$post->user]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use DomainException;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Core\Model;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Support\Locked;
|
||||
use Flarum\Core\Support\VisibleScope;
|
||||
use Flarum\Core\Support\EventGenerator;
|
||||
|
@ -96,6 +97,25 @@ class Post extends Model
|
|||
static::addGlobalScope(new RegisteredTypesScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this post is visible to the given user.
|
||||
*
|
||||
* @param User $user
|
||||
* @return boolean
|
||||
*/
|
||||
public function isVisibleTo(User $user)
|
||||
{
|
||||
$discussion = $this->discussion()->whereVisibleTo($user)->first();
|
||||
|
||||
if ($discussion) {
|
||||
$this->setRelation('discussion', $discussion);
|
||||
|
||||
return (bool) $discussion->postsVisibleTo($user)->find($this->id)->count();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the relationship with the post's discussion.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user