Change "renamed" post type to more descriptive "discussionRenamed"

This commit is contained in:
Toby Zerner 2015-03-28 13:38:44 +10:30
parent 89eca757e6
commit 49c3fa09e6
7 changed files with 16 additions and 17 deletions

View File

@ -6,12 +6,12 @@ import HasItemLists from 'flarum/mixins/has-item-lists';
var precompileTemplate = Ember.Handlebars.compile;
/**
Component for a `renamed`-typed post.
Component for a `discussionRenamed`-typed post.
*/
export default Ember.Component.extend(FadeIn, HasItemLists, {
layoutName: 'components/discussion/post-renamed',
layoutName: 'components/discussion/post-discussion-renamed',
tagName: 'article',
classNames: ['post', 'post-renamed', 'post-activity'],
classNames: ['post', 'post-discussion-renamed', 'post-activity'],
itemLists: ['controls'],
// The stream-content component instansiates this component and sets the

View File

@ -267,7 +267,7 @@
font-size: 15px;
margin-bottom: 5px;
}
.post-renamed {
.post-discussion-renamed {
& .old-title, & .new-title {
font-weight: normal;
font-style: italic;

View File

@ -121,7 +121,7 @@ class CoreServiceProvider extends ServiceProvider
public function registerPostTypes()
{
Post::addType('comment', 'Flarum\Core\Models\CommentPost');
Post::addType('renamed', 'Flarum\Core\Models\RenamedPost');
Post::addType('discussionRenamed', 'Flarum\Core\Models\DiscussionRenamedPost');
CommentPost::setFormatter($this->app['flarum.formatter']);
}

View File

@ -1,8 +1,8 @@
<?php namespace Flarum\Core\Handlers\Events;
use Flarum\Core\Events\DiscussionWasRenamed;
use Flarum\Core\Models\RenamedPost;
use Flarum\Core\Models\Notification;
use Flarum\Core\Models\DiscussionRenamedPost;
class DiscussionRenamedNotifier
{
@ -19,16 +19,18 @@ class DiscussionRenamedNotifier
public function whenDiscussionWasRenamed(DiscussionWasRenamed $event)
{
$post = $this->createRenamedPost($event);
$post = $this->createPost($event);
$event->discussion->postWasAdded($post);
$this->createRenamedNotification($event, $post);
if ($event->discussion->start_user_id !== $event->user->id) {
$this->sendNotification($event, $post);
}
}
protected function createRenamedPost(DiscussionWasRenamed $event)
protected function createPost(DiscussionWasRenamed $event)
{
$post = RenamedPost::reply(
$post = DiscussionRenamedPost::reply(
$event->discussion->id,
$event->user->id,
$event->oldTitle,
@ -40,11 +42,8 @@ class DiscussionRenamedNotifier
return $post;
}
protected function createRenamedNotification(DiscussionWasRenamed $event, RenamedPost $post)
protected function sendNotification(DiscussionWasRenamed $event, DiscussionRenamedPost $post)
{
if ($event->discussion->start_user_id === $event->user->id) {
return false;
}
$notification = Notification::notify(
$event->discussion->start_user_id,

View File

@ -1,6 +1,6 @@
<?php namespace Flarum\Core\Models;
class RenamedPost extends Post
class DiscussionRenamedPost extends Post
{
/**
* Create a new instance in reply to a discussion.
@ -19,7 +19,7 @@ class RenamedPost extends Post
$post->time = time();
$post->discussion_id = $discussionId;
$post->user_id = $userId;
$post->type = 'renamed';
$post->type = 'discussionRenamed';
return $post;
}

View File

@ -64,7 +64,7 @@ class DiscussionsTableSeeder extends Seeder
'discussion_id' => $discussion->id,
'time' => $startTime = date_add($startTime, date_interval_create_from_date_string('1 second')),
'user_id' => rand(1, $users),
'type' => 'renamed',
'type' => 'discussionRenamed',
'content' => json_encode(array($faker->realText(rand(20, 40)), $discussion->title))
]);
} else {