Rename discussion.startPost

This commit is contained in:
Toby Zerner 2018-08-24 20:42:07 +09:30
parent 98d85d51d3
commit 14885fc0e1
9 changed files with 16 additions and 16 deletions

View File

@ -11,7 +11,7 @@ Object.assign(Discussion.prototype, {
startTime: Model.attribute('startTime', Model.transformDate),
startUser: Model.hasOne('startUser'),
startPost: Model.hasOne('startPost'),
firstPost: Model.hasOne('firstPost'),
lastTime: Model.attribute('lastTime', Model.transformDate),
lastUser: Model.hasOne('lastUser'),

View File

@ -156,7 +156,7 @@ export default class DiscussionListItem extends Component {
*
* @return {Boolean}
*/
showStartPost() {
showFirstPost() {
return ['newest', 'oldest'].indexOf(this.props.params.sort) !== -1;
}
@ -192,7 +192,7 @@ export default class DiscussionListItem extends Component {
const items = new ItemList();
if (this.props.params.q) {
const post = this.props.discussion.mostRelevantPost() || this.props.discussion.startPost();
const post = this.props.discussion.mostRelevantPost() || this.props.discussion.firstPost();
if (post && post.contentType() === 'comment') {
const excerpt = highlight(post.contentPlain(), this.highlightRegExp, 175);
@ -202,7 +202,7 @@ export default class DiscussionListItem extends Component {
items.add('terminalPost',
TerminalPost.component({
discussion: this.props.discussion,
lastPost: !this.showStartPost()
lastPost: !this.showFirstPost()
})
);
}

View File

@ -33,7 +33,7 @@ class CreateDiscussionController extends AbstractCreateController
'posts',
'startUser',
'lastUser',
'startPost',
'firstPost',
'lastPost'
];

View File

@ -40,7 +40,7 @@ class ListDiscussionsController extends AbstractListController
* {@inheritdoc}
*/
public $optionalInclude = [
'startPost',
'firstPost',
'lastPost'
];
@ -98,7 +98,7 @@ class ListDiscussionsController extends AbstractListController
$results = $results->getResults()->load($load);
if ($relations = array_intersect($load, ['startPost', 'lastPost'])) {
if ($relations = array_intersect($load, ['firstPost', 'lastPost'])) {
foreach ($results as $discussion) {
foreach ($relations as $relation) {
if ($discussion->$relation) {

View File

@ -54,7 +54,7 @@ class ShowDiscussionController extends AbstractShowController
public $optionalInclude = [
'startUser',
'lastUser',
'startPost',
'firstPost',
'lastPost'
];

View File

@ -52,7 +52,7 @@ class BasicDiscussionSerializer extends AbstractSerializer
/**
* @return \Tobscure\JsonApi\Relationship
*/
protected function startPost($discussion)
protected function firstPost($discussion)
{
return $this->hasOne($discussion, BasicPostSerializer::class);
}

View File

@ -94,7 +94,7 @@ class StartDiscussionHandler
// attributes as posting the reply will have changed some of them (e.g.
// last_time.)
$discussion->setRawAttributes($post->discussion->getAttributes(), true);
$discussion->setStartPost($post);
$discussion->setFirstPost($post);
$discussion->setLastPost($post);
$this->dispatchEventsFor($discussion, $actor);

View File

@ -46,7 +46,7 @@ use Flarum\Util\Str;
* @property \Illuminate\Database\Eloquent\Collection $posts
* @property \Illuminate\Database\Eloquent\Collection $comments
* @property \Illuminate\Database\Eloquent\Collection $participants
* @property Post|null $startPost
* @property Post|null $firstPost
* @property User|null $startUser
* @property Post|null $lastPost
* @property User|null $lastUser
@ -184,12 +184,12 @@ class Discussion extends AbstractModel
}
/**
* Set the discussion's start post details.
* Set the discussion's first post details.
*
* @param Post $post
* @return $this
*/
public function setStartPost(Post $post)
public function setFirstPost(Post $post)
{
$this->created_at = $post->created_at;
$this->user_id = $post->user_id;
@ -329,7 +329,7 @@ class Discussion extends AbstractModel
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function startPost()
public function firstPost()
{
return $this->belongsTo(Post::class, 'first_post_id');
}

View File

@ -31,8 +31,8 @@ trait ManagesContent
$post->save();
if (! $this->discussion->startPost) {
$this->discussion->setStartPost($post);
if (! $this->discussion->firstPost) {
$this->discussion->setFirstPost($post);
$this->discussion->setLastPost($post);
$this->discussion->save();