mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02: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:
@@ -5,6 +5,7 @@ use Flarum\Core\Activity\PostedBlueprint;
|
|||||||
use Flarum\Core\Activity\StartedDiscussionBlueprint;
|
use Flarum\Core\Activity\StartedDiscussionBlueprint;
|
||||||
use Flarum\Core\Activity\JoinedBlueprint;
|
use Flarum\Core\Activity\JoinedBlueprint;
|
||||||
use Flarum\Core\Posts\Post;
|
use Flarum\Core\Posts\Post;
|
||||||
|
use Flarum\Core\Users\Guest;
|
||||||
use Flarum\Events\PostWasPosted;
|
use Flarum\Events\PostWasPosted;
|
||||||
use Flarum\Events\PostWasDeleted;
|
use Flarum\Events\PostWasDeleted;
|
||||||
use Flarum\Events\PostWasHidden;
|
use Flarum\Events\PostWasHidden;
|
||||||
@@ -95,9 +96,11 @@ class UserActivitySyncer
|
|||||||
*/
|
*/
|
||||||
protected function postBecameVisible(Post $post)
|
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 DomainException;
|
||||||
use Flarum\Events\PostWasDeleted;
|
use Flarum\Events\PostWasDeleted;
|
||||||
use Flarum\Core\Model;
|
use Flarum\Core\Model;
|
||||||
|
use Flarum\Core\Users\User;
|
||||||
use Flarum\Core\Support\Locked;
|
use Flarum\Core\Support\Locked;
|
||||||
use Flarum\Core\Support\VisibleScope;
|
use Flarum\Core\Support\VisibleScope;
|
||||||
use Flarum\Core\Support\EventGenerator;
|
use Flarum\Core\Support\EventGenerator;
|
||||||
@@ -96,6 +97,25 @@ class Post extends Model
|
|||||||
static::addGlobalScope(new RegisteredTypesScope);
|
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.
|
* Define the relationship with the post's discussion.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user