mirror of
https://github.com/flarum/core.git
synced 2025-07-20 16:21:18 +02:00
New user activity feed API.
Originally the user activity feed was implemented using UNIONs. I was looking at make an API to add activity “sources”, or extra UNION queries (select from posts, mentions, etc.) but quickly realised that this is too slow and there’s no way to make it scale. So I’ve implemented an API which is very similar to how notifications work (see previous commit). The `activity` table is an aggregation of stuff that happens, and it’s kept in sync by an ActivitySyncer which is used whenever a post it created/edited/deleted, a user is mentioned/unmentioned, etc. Again, the API is very simple (see Core\Activity\PostedActivity + Core\Handlers\Events\UserActivitySyncer)
This commit is contained in:
@@ -2,7 +2,7 @@ import Component from 'flarum/component';
|
||||
import humanTime from 'flarum/helpers/human-time';
|
||||
import avatar from 'flarum/helpers/avatar';
|
||||
|
||||
export default class JoinActivity extends Component {
|
||||
export default class JoinedActivity extends Component {
|
||||
view() {
|
||||
var activity = this.props.activity;
|
||||
var user = activity.user();
|
@@ -4,11 +4,11 @@ import avatar from 'flarum/helpers/avatar';
|
||||
import listItems from 'flarum/helpers/list-items';
|
||||
import ItemList from 'flarum/utils/item-list';
|
||||
|
||||
export default class PostActivity extends Component {
|
||||
export default class PostedActivity extends Component {
|
||||
view() {
|
||||
var activity = this.props.activity;
|
||||
var user = activity.user();
|
||||
var post = activity.post();
|
||||
var post = activity.subject();
|
||||
var discussion = post.discussion();
|
||||
|
||||
return m('div', [
|
||||
@@ -23,7 +23,7 @@ export default class PostActivity extends Component {
|
||||
near: post.number()
|
||||
}), config: m.route}, [
|
||||
m('ul.list-inline', listItems(this.headerItems().toArray())),
|
||||
m('div.body', m.trust(post.contentHtml()))
|
||||
m('div.body', m.trust(post.excerpt()))
|
||||
])
|
||||
]);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export default class PostActivity extends Component {
|
||||
headerItems() {
|
||||
var items = new ItemList();
|
||||
|
||||
items.add('title', m('h3.title', this.props.activity.post().discussion().title()));
|
||||
items.add('title', m('h3.title', this.props.activity.subject().discussion().title()));
|
||||
|
||||
return items;
|
||||
}
|
@@ -1,21 +1,22 @@
|
||||
import CommentPost from 'flarum/components/comment-post';
|
||||
import DiscussionRenamedPost from 'flarum/components/discussion-renamed-post';
|
||||
import PostActivity from 'flarum/components/post-activity';
|
||||
import JoinActivity from 'flarum/components/join-activity';
|
||||
import PostedActivity from 'flarum/components/posted-activity';
|
||||
import JoinedActivity from 'flarum/components/joined-activity';
|
||||
import DiscussionRenamedNotification from 'flarum/components/discussion-renamed-notification';
|
||||
|
||||
export default function(app) {
|
||||
app.postComponentRegistry = {
|
||||
comment: CommentPost,
|
||||
discussionRenamed: DiscussionRenamedPost
|
||||
'comment': CommentPost,
|
||||
'discussionRenamed': DiscussionRenamedPost
|
||||
};
|
||||
|
||||
app.activityComponentRegistry = {
|
||||
post: PostActivity,
|
||||
join: JoinActivity
|
||||
'posted': PostedActivity,
|
||||
'startedDiscussion': PostedActivity,
|
||||
'joined': JoinedActivity
|
||||
};
|
||||
|
||||
app.notificationComponentRegistry = {
|
||||
discussionRenamed: DiscussionRenamedNotification
|
||||
'discussionRenamed': DiscussionRenamedNotification
|
||||
};
|
||||
}
|
||||
|
@@ -13,8 +13,8 @@ export default function(app) {
|
||||
|
||||
'user': ['/u/:username', ActivityPage.component()],
|
||||
'user.activity': ['/u/:username', ActivityPage.component()],
|
||||
'user.discussions': ['/u/:username/discussions', ActivityPage.component({filter: 'discussion'})],
|
||||
'user.posts': ['/u/:username/posts', ActivityPage.component({filter: 'post'})],
|
||||
'user.discussions': ['/u/:username/discussions', ActivityPage.component({filter: 'startedDiscussion'})],
|
||||
'user.posts': ['/u/:username/posts', ActivityPage.component({filter: 'posted'})],
|
||||
|
||||
'settings': ['/settings', SettingsPage.component()]
|
||||
};
|
||||
|
@@ -8,7 +8,6 @@ Activity.prototype.content = Model.prop('content');
|
||||
Activity.prototype.time = Model.prop('time', Model.date);
|
||||
|
||||
Activity.prototype.user = Model.one('user');
|
||||
Activity.prototype.sender = Model.one('sender');
|
||||
Activity.prototype.post = Model.one('post');
|
||||
Activity.prototype.subject = Model.one('subject');
|
||||
|
||||
export default Activity;
|
||||
|
Reference in New Issue
Block a user