Bring back sticky discussion excerpts

This commit is contained in:
Toby Zerner 2015-06-25 09:58:35 +09:30
parent 835c3eef71
commit 039606e325
2 changed files with 13 additions and 4 deletions

View File

@ -3,10 +3,12 @@ import Model from 'flarum/model';
import Discussion from 'flarum/models/discussion';
import DiscussionPage from 'flarum/components/discussion-page';
import DiscussionList from 'flarum/components/discussion-list';
import DiscussionListItem from 'flarum/components/discussion-list-item';
import Badge from 'flarum/components/badge';
import ActionButton from 'flarum/components/action-button';
import SettingsPage from 'flarum/components/settings-page';
import icon from 'flarum/helpers/icon';
import truncate from 'flarum/utils/truncate';
import app from 'flarum/app';
import DiscussionStickiedPost from 'flarum-sticky/components/discussion-stickied-post';
@ -57,20 +59,23 @@ app.initializers.add('sticky', function() {
items.add('discussionStickied', {
name: 'discussionStickied',
label: [icon('thumb-tack'), ' Someone stickies a discussion I started']
});
}, {after: 'discussionRenamed'});
});
extend(DiscussionList.prototype, 'params', function(params) {
params.include.push('startPost');
});
extend(DiscussionList.prototype, 'infoItems', function(items, discussion) {
extend(DiscussionListItem.prototype, 'infoItems', function(items) {
var discussion = this.props.discussion;
if (discussion.isSticky()) {
console.log(discussion.startPost())
var startPost = discussion.startPost();
if (startPost) {
var excerpt = m('span', startPost.excerpt());
var excerpt = m('span', truncate(startPost.contentPlain(), 200));
excerpt.wrapperClass = 'discussion-excerpt';
var item = items.add('excerpt', excerpt, {last: true});
items.add('excerpt', excerpt, {last: true});
}
}
});

View File

@ -28,6 +28,10 @@ class StickyServiceProvider extends ServiceProvider
$attributes['canSticky'] = (bool) $model->can($user, 'sticky');
}),
// include discussion start posts by default
(new Extend\ApiAction('Flarum\Api\Actions\Discussions\IndexAction'))
->addInclude('startPost'),
new Extend\DiscussionGambit('Flarum\Sticky\StickyGambit'),
(new Extend\NotificationType('Flarum\Sticky\DiscussionStickiedNotification', 'Flarum\Api\Serializers\DiscussionBasicSerializer'))