1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00

went over most of the changed attributes from the other pr

This commit is contained in:
Daniel Klabbers
2018-04-17 14:22:38 +02:00
parent efa3b62fb8
commit a2927b725f
21 changed files with 122 additions and 106 deletions

View File

@@ -30,18 +30,18 @@ use Flarum\Util\Str;
* @property int $id
* @property string $title
* @property string $slug
* @property int $comments_count
* @property int $participants_count
* @property int $number_index
* @property \Carbon\Carbon $start_time
* @property int|null $start_user_id
* @property int|null $start_post_id
* @property \Carbon\Carbon|null $last_time
* @property int|null $last_user_id
* @property int $comment_count
* @property int $participant_count
* @property int $post_number_index
* @property \Carbon\Carbon $created_at
* @property int|null $user_id
* @property int|null $first_post_id
* @property \Carbon\Carbon|null $last_posted_at
* @property int|null $last_posted_user_id
* @property int|null $last_post_id
* @property int|null $last_post_number
* @property \Carbon\Carbon|null $hide_time
* @property int|null $hide_user_id
* @property \Carbon\Carbon|null $hidden_at
* @property int|null $hidden_user_id
* @property UserState|null $state
* @property \Illuminate\Database\Eloquent\Collection $posts
* @property \Illuminate\Database\Eloquent\Collection $comments
@@ -73,7 +73,7 @@ class Discussion extends AbstractModel
/**
* {@inheritdoc}
*/
protected $dates = ['start_time', 'last_time', 'hide_time'];
protected $dates = ['created_at', 'last_posted_at', 'hidden_at'];
/**
* Casts properties to a specific type.
@@ -138,8 +138,8 @@ class Discussion extends AbstractModel
$discussion = new static;
$discussion->title = $title;
$discussion->start_time = time();
$discussion->start_user_id = $user->id;
$discussion->created_at = time();
$discussion->user_id = $user->id;
$discussion->setRelation('startUser', $user);
@@ -174,9 +174,9 @@ class Discussion extends AbstractModel
*/
public function hide(User $actor = null)
{
if (! $this->hide_time) {
$this->hide_time = time();
$this->hide_user_id = $actor ? $actor->id : null;
if (! $this->hidden_at) {
$this->hidden_at = time();
$this->hidden_user_id = $actor ? $actor->id : null;
$this->raise(new Hidden($this));
}
@@ -191,9 +191,9 @@ class Discussion extends AbstractModel
*/
public function restore()
{
if ($this->hide_time !== null) {
$this->hide_time = null;
$this->hide_user_id = null;
if ($this->hidden_at !== null) {
$this->hidden_at = null;
$this->hidden_user_id = null;
$this->raise(new Restored($this));
}
@@ -209,9 +209,9 @@ class Discussion extends AbstractModel
*/
public function setStartPost(Post $post)
{
$this->start_time = $post->time;
$this->start_user_id = $post->user_id;
$this->start_post_id = $post->id;
$this->created_at = $post->time;
$this->user_id = $post->user_id;
$this->first_post_id = $post->id;
return $this;
}
@@ -224,8 +224,8 @@ class Discussion extends AbstractModel
*/
public function setLastPost(Post $post)
{
$this->last_time = $post->time;
$this->last_user_id = $post->user_id;
$this->last_posted_at = $post->time;
$this->last_posted_user_id = $post->user_id;
$this->last_post_id = $post->id;
$this->last_post_number = $post->number;
@@ -240,7 +240,7 @@ class Discussion extends AbstractModel
public function refreshLastPost()
{
/** @var Post $lastPost */
if ($lastPost = $this->comments()->latest('time')->first()) {
if ($lastPost = $this->comments()->latest('created_at')->first()) {
$this->setLastPost($lastPost);
}
@@ -254,7 +254,7 @@ class Discussion extends AbstractModel
*/
public function refreshCommentsCount()
{
$this->comments_count = $this->comments()->count();
$this->comment_count = $this->comments()->count();
return $this;
}
@@ -266,7 +266,7 @@ class Discussion extends AbstractModel
*/
public function refreshParticipantsCount()
{
$this->participants_count = $this->participants()->count('users.id');
$this->participant_count = $this->participants()->count('users.id');
return $this;
}
@@ -286,7 +286,7 @@ class Discussion extends AbstractModel
*/
public function mergePost(MergeableInterface $post)
{
$lastPost = $this->posts()->latest('time')->first();
$lastPost = $this->posts()->latest('created_at')->first();
$post = $post->saveAfter($lastPost);
@@ -322,7 +322,7 @@ class Discussion extends AbstractModel
{
return $this->posts()
->where('is_private', false)
->whereNull('hide_time')
->whereNull('hidden_at')
->where('type', 'comment');
}
@@ -349,7 +349,7 @@ class Discussion extends AbstractModel
*/
public function startPost()
{
return $this->belongsTo(Post::class, 'start_post_id');
return $this->belongsTo(Post::class, 'first_post_id');
}
/**
@@ -359,7 +359,7 @@ class Discussion extends AbstractModel
*/
public function startUser()
{
return $this->belongsTo(User::class, 'start_user_id');
return $this->belongsTo(User::class, 'user_id');
}
/**

View File

@@ -93,7 +93,7 @@ class DiscussionPolicy extends AbstractPolicy
if (! $actor->hasPermission('discussion.hide')) {
$query->where(function ($query) use ($actor) {
$query->whereNull('discussions.hide_time')
->orWhere('start_user_id', $actor->id)
->orWhere('user_id', $actor->id)
->orWhere(function ($query) use ($actor) {
$this->events->fire(
new ScopeModelVisibility($query, $actor, 'hide')
@@ -106,8 +106,8 @@ class DiscussionPolicy extends AbstractPolicy
// current user, or the user is allowed to edit the discussion's posts.
if (! $actor->hasPermission('discussion.editPosts')) {
$query->where(function ($query) use ($actor) {
$query->where('comments_count', '>', 0)
->orWhere('start_user_id', $actor->id)
$query->where('comment_count', '>', 0)
->orWhere('user_id', $actor->id)
->orWhere(function ($query) use ($actor) {
$this->events->dispatch(
new ScopeModelVisibility($query, $actor, 'editPosts')
@@ -124,12 +124,12 @@ class DiscussionPolicy extends AbstractPolicy
*/
public function rename(User $actor, Discussion $discussion)
{
if ($discussion->start_user_id == $actor->id) {
if ($discussion->user_id == $actor->id) {
$allowRenaming = $this->settings->get('allow_renaming');
if ($allowRenaming === '-1'
|| ($allowRenaming === 'reply' && $discussion->participants_count <= 1)
|| ($discussion->start_time->diffInMinutes(new Carbon) < $allowRenaming)) {
|| ($allowRenaming === 'reply' && $discussion->participant_count <= 1)
|| ($discussion->created_at->diffInMinutes(new Carbon) < $allowRenaming)) {
return true;
}
}
@@ -142,7 +142,7 @@ class DiscussionPolicy extends AbstractPolicy
*/
public function hide(User $actor, Discussion $discussion)
{
if ($discussion->start_user_id == $actor->id && $discussion->participants_count <= 1) {
if ($discussion->user_id == $actor->id && $discussion->participant_count <= 1) {
return true;
}
}

View File

@@ -54,7 +54,7 @@ class DiscussionRenamedLogger
$post = $event->discussion->mergePost($post);
if ($event->discussion->start_user_id !== $event->actor->id) {
if ($event->discussion->user_id !== $event->actor->id) {
$blueprint = new DiscussionRenamedBlueprint($post);
if ($post->exists) {

View File

@@ -49,7 +49,7 @@ class DiscussionRepository
*/
public function getReadIds(User $user)
{
return Discussion::leftJoin('users_discussions', 'users_discussions.discussion_id', '=', 'discussions.id')
return Discussion::leftJoin('discussions_users', 'discussions_users.discussion_id', '=', 'discussions.id')
->where('user_id', $user->id)
->whereRaw('read_number >= last_post_number')
->pluck('id')

View File

@@ -23,7 +23,7 @@ class DiscussionSearch extends AbstractSearch
/**
* {@inheritdoc}
*/
protected $defaultSort = ['lastTime' => 'desc'];
protected $defaultSort = ['lastPostedAt' => 'desc'];
/**
* @var array

View File

@@ -54,6 +54,6 @@ class AuthorGambit extends AbstractRegexGambit
$ids[] = $this->users->getIdForUsername($username);
}
$search->getQuery()->whereIn('start_user_id', $ids, 'and', $negate);
$search->getQuery()->whereIn('user_id', $ids, 'and', $negate);
}
}

View File

@@ -37,9 +37,9 @@ class CreatedGambit extends AbstractRegexGambit
// provided with a YYYY-MM-DD..YYYY-MM-DD range, then find discussions
// that were started during that period.
if (empty($matches[3])) {
$search->getQuery()->whereDate('start_time', $negate ? '!=' : '=', $matches[1]);
$search->getQuery()->whereDate('created_at', $negate ? '!=' : '=', $matches[1]);
} else {
$search->getQuery()->whereBetween('start_time', [$matches[1], $matches[3]], 'and', $negate);
$search->getQuery()->whereBetween('created_at', [$matches[1], $matches[3]], 'and', $negate);
}
}
}

View File

@@ -34,9 +34,9 @@ class HiddenGambit extends AbstractRegexGambit
$search->getQuery()->where(function ($query) use ($negate) {
if ($negate) {
$query->whereNull('hide_time')->where('comments_count', '>', 0);
$query->whereNull('hidden_at')->where('comment_count', '>', 0);
} else {
$query->whereNotNull('hide_time')->orWhere('comments_count', 0);
$query->whereNotNull('hidden_at')->orWhere('comment_count', 0);
}
});
}

View File

@@ -53,9 +53,9 @@ class UnreadGambit extends AbstractRegexGambit
$search->getQuery()->where(function ($query) use ($readIds, $negate, $actor) {
if (! $negate) {
$query->whereNotIn('id', $readIds)->where('last_time', '>', $actor->read_time ?: 0);
$query->whereNotIn('id', $readIds)->where('last_posted_at', '>', $actor->marked_all_as_read_at ?: 0);
} else {
$query->whereIn('id', $readIds)->orWhere('last_time', '<=', $actor->read_time ?: 0);
$query->whereIn('id', $readIds)->orWhere('last_posted_at', '<=', $actor->marked_all_as_read_at ?: 0);
}
});
}

View File

@@ -26,8 +26,8 @@ use Illuminate\Database\Eloquent\Builder;
*
* @property int $user_id
* @property int $discussion_id
* @property \Carbon\Carbon|null $read_time
* @property int|null $read_number
* @property \Carbon\Carbon|null $last_read_at
* @property int|null $last_read_post_number
* @property Discussion $discussion
* @property \Flarum\User\User $user
*/
@@ -38,12 +38,12 @@ class UserState extends AbstractModel
/**
* {@inheritdoc}
*/
protected $table = 'users_discussions';
protected $table = 'discussions_users';
/**
* {@inheritdoc}
*/
protected $dates = ['read_time'];
protected $dates = ['last_read_at'];
/**
* Mark the discussion as being read up to a certain point. Raises the
@@ -54,9 +54,9 @@ class UserState extends AbstractModel
*/
public function read($number)
{
if ($number > $this->read_number) {
$this->read_number = $number;
$this->read_time = time();
if ($number > $this->last_read_at) {
$this->last_read_at = $number;
$this->last_read_at = time();
$this->raise(new UserRead($this));
}