Merge pull request #15 from sijad/mentions-tab

Add Mentions section to user profile
This commit is contained in:
Toby Zerner 2016-02-07 10:32:06 +10:30
commit 040002b7a2
5 changed files with 148 additions and 2 deletions

View File

@ -20,6 +20,7 @@ return function (Dispatcher $events, Factory $views) {
$events->subscribe(Listener\FormatUserMentions::class); $events->subscribe(Listener\FormatUserMentions::class);
$events->subscribe(Listener\UpdatePostMentionsMetadata::class); $events->subscribe(Listener\UpdatePostMentionsMetadata::class);
$events->subscribe(Listener\UpdateUserMentionsMetadata::class); $events->subscribe(Listener\UpdateUserMentionsMetadata::class);
$events->subscribe(Listener\AddFilterByMentions::class);
$views->addNamespace('flarum-mentions', __DIR__.'/views'); $views->addNamespace('flarum-mentions', __DIR__.'/views');
}; };

View File

@ -924,10 +924,10 @@ System.register('flarum/mentions/components/UserMentionedNotification', ['flarum
} }
}; };
});; });;
System.register('flarum/mentions/main', ['flarum/extend', 'flarum/app', 'flarum/components/NotificationGrid', 'flarum/utils/string', 'flarum/mentions/addPostMentionPreviews', 'flarum/mentions/addMentionedByList', 'flarum/mentions/addPostReplyAction', 'flarum/mentions/addComposerAutocomplete', 'flarum/mentions/components/PostMentionedNotification', 'flarum/mentions/components/UserMentionedNotification'], function (_export) { System.register('flarum/mentions/main', ['flarum/extend', 'flarum/app', 'flarum/components/NotificationGrid', 'flarum/utils/string', 'flarum/mentions/addPostMentionPreviews', 'flarum/mentions/addMentionedByList', 'flarum/mentions/addPostReplyAction', 'flarum/mentions/addComposerAutocomplete', 'flarum/mentions/components/PostMentionedNotification', 'flarum/mentions/components/UserMentionedNotification', 'flarum/components/UserPage', 'flarum/components/LinkButton', 'flarum/mentions/components/MentionsUserPage'], function (_export) {
'use strict'; 'use strict';
var extend, app, NotificationGrid, getPlainContent, addPostMentionPreviews, addMentionedByList, addPostReplyAction, addComposerAutocomplete, PostMentionedNotification, UserMentionedNotification; var extend, app, NotificationGrid, getPlainContent, addPostMentionPreviews, addMentionedByList, addPostReplyAction, addComposerAutocomplete, PostMentionedNotification, UserMentionedNotification, UserPage, LinkButton, MentionsUserPage;
return { return {
setters: [function (_flarumExtend) { setters: [function (_flarumExtend) {
extend = _flarumExtend.extend; extend = _flarumExtend.extend;
@ -949,6 +949,12 @@ System.register('flarum/mentions/main', ['flarum/extend', 'flarum/app', 'flarum/
PostMentionedNotification = _flarumMentionsComponentsPostMentionedNotification['default']; PostMentionedNotification = _flarumMentionsComponentsPostMentionedNotification['default'];
}, function (_flarumMentionsComponentsUserMentionedNotification) { }, function (_flarumMentionsComponentsUserMentionedNotification) {
UserMentionedNotification = _flarumMentionsComponentsUserMentionedNotification['default']; UserMentionedNotification = _flarumMentionsComponentsUserMentionedNotification['default'];
}, function (_flarumComponentsUserPage) {
UserPage = _flarumComponentsUserPage['default'];
}, function (_flarumComponentsLinkButton) {
LinkButton = _flarumComponentsLinkButton['default'];
}, function (_flarumMentionsComponentsMentionsUserPage) {
MentionsUserPage = _flarumMentionsComponentsMentionsUserPage['default'];
}], }],
execute: function () { execute: function () {
@ -987,8 +993,69 @@ System.register('flarum/mentions/main', ['flarum/extend', 'flarum/app', 'flarum/
}); });
}); });
// Add add mentions tab in user profile
app.routes['user.mentions'] = { path: '/u/:username/mentions', component: MentionsUserPage.component() };
extend(UserPage.prototype, 'navItems', function (items) {
var user = this.user;
items.add('mentions', LinkButton.component({
href: app.route('user.mentions', { username: user.username() }),
name: 'mentions',
children: [app.translator.trans('flarum-mentions.forum.user.mentions_link')],
icon: 'at'
}), 80);
});
getPlainContent.removeSelectors.push('a.PostMention'); getPlainContent.removeSelectors.push('a.PostMention');
}); });
} }
}; };
});;
System.register('flarum/mentions/components/MentionsUserPage', ['flarum/components/PostsUserPage'], function (_export) {
/**
* The `MentionsUserPage` component shows post which user Mentioned at
*/
'use strict';
var PostsUserPage, MentionsUserPage;
return {
setters: [function (_flarumComponentsPostsUserPage) {
PostsUserPage = _flarumComponentsPostsUserPage['default'];
}],
execute: function () {
MentionsUserPage = (function (_PostsUserPage) {
babelHelpers.inherits(MentionsUserPage, _PostsUserPage);
function MentionsUserPage() {
babelHelpers.classCallCheck(this, MentionsUserPage);
babelHelpers.get(Object.getPrototypeOf(MentionsUserPage.prototype), 'constructor', this).apply(this, arguments);
}
babelHelpers.createClass(MentionsUserPage, [{
key: 'loadResults',
/**
* Load a new page of the user's activity feed.
*
* @param {Integer} [offset] The position to start getting results from.
* @return {Promise}
* @protected
*/
value: function loadResults(offset) {
return app.store.find('posts', {
filter: {
type: 'comment',
mentioned: this.user.id()
},
page: { offset: offset, limit: this.loadLimit },
sort: '-time'
});
}
}]);
return MentionsUserPage;
})(PostsUserPage);
_export('default', MentionsUserPage);
}
};
}); });

View File

@ -0,0 +1,24 @@
import PostsUserPage from 'flarum/components/PostsUserPage';
/**
* The `MentionsUserPage` component shows post which user Mentioned at
*/
export default class MentionsUserPage extends PostsUserPage {
/**
* Load a new page of the user's activity feed.
*
* @param {Integer} [offset] The position to start getting results from.
* @return {Promise}
* @protected
*/
loadResults(offset) {
return app.store.find('posts', {
filter: {
type: 'comment',
mentioned: this.user.id()
},
page: {offset, limit: this.loadLimit},
sort: '-time'
});
}
}

View File

@ -9,6 +9,9 @@ import addPostReplyAction from 'flarum/mentions/addPostReplyAction';
import addComposerAutocomplete from 'flarum/mentions/addComposerAutocomplete'; import addComposerAutocomplete from 'flarum/mentions/addComposerAutocomplete';
import PostMentionedNotification from 'flarum/mentions/components/PostMentionedNotification'; import PostMentionedNotification from 'flarum/mentions/components/PostMentionedNotification';
import UserMentionedNotification from 'flarum/mentions/components/UserMentionedNotification'; import UserMentionedNotification from 'flarum/mentions/components/UserMentionedNotification';
import UserPage from 'flarum/components/UserPage'
import LinkButton from 'flarum/components/LinkButton';
import MentionsUserPage from 'flarum/mentions/components/MentionsUserPage';
app.initializers.add('flarum-mentions', function() { app.initializers.add('flarum-mentions', function() {
// For every mention of a post inside a post's content, set up a hover handler // For every mention of a post inside a post's content, set up a hover handler
@ -45,5 +48,20 @@ app.initializers.add('flarum-mentions', function() {
}); });
}); });
// Add add mentions tab in user profile
app.routes['user.mentions'] = {path: '/u/:username/mentions', component: MentionsUserPage.component()};
extend(UserPage.prototype, 'navItems', function(items) {
const user = this.user;
items.add('mentions',
LinkButton.component({
href: app.route('user.mentions', {username: user.username()}),
name: 'mentions',
children: [app.translator.trans('flarum-mentions.forum.user.mentions_link')],
icon: 'at'
}),
80
);
});
getPlainContent.removeSelectors.push('a.PostMention'); getPlainContent.removeSelectors.push('a.PostMention');
}); });

View File

@ -0,0 +1,36 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Mentions\Listener;
use Flarum\Event\ConfigurePostsQuery;
use Illuminate\Contracts\Events\Dispatcher;
class AddFilterByMentions
{
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigurePostsQuery::class, [$this, 'addFilter']);
}
/**
* @param ConfigurePostsQuery $event
*/
public function addFilter(ConfigurePostsQuery $event)
{
if ($mentionedId = array_get($event->filter, 'mentioned')) {
$event->query->join('mentions_users', 'posts.id', '=', 'mentions_users.post_id')
->where('mentions_users.mentions_id', '=', $mentionedId);
}
}
}