mirror of
https://github.com/wassname/talk.git
synced 2026-07-23 13:10:20 +08:00
Adding user and action data to rejected and flagged comments.
This commit is contained in:
@@ -40,7 +40,7 @@ class CommentStream extends React.Component {
|
||||
}
|
||||
|
||||
// Render the comment box along with the CommentList
|
||||
render ({comments}, {snackbar, snackbarMsg}) {
|
||||
render ({comments, users}, {snackbar, snackbarMsg}) {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<CommentBox onSubmit={this.onSubmit} />
|
||||
@@ -48,6 +48,7 @@ class CommentStream extends React.Component {
|
||||
singleView={false}
|
||||
commentIds={comments.get('ids')}
|
||||
comments={comments.get('byId')}
|
||||
users={users.get('byId')}
|
||||
onClickAction={this.onClickAction}
|
||||
actions={['flag']}
|
||||
loading={comments.loading} />
|
||||
@@ -57,4 +58,4 @@ class CommentStream extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(({comments}) => ({comments}))(CommentStream);
|
||||
export default connect(({comments, users}) => ({comments, users}))(CommentStream);
|
||||
|
||||
@@ -82,8 +82,8 @@ class ModerationQueue extends React.Component {
|
||||
commentIds={
|
||||
comments.get('ids')
|
||||
.filter(id => !comments.get('byId')
|
||||
.get(id)
|
||||
.get('status'))
|
||||
.get(id)
|
||||
.get('flagged'))
|
||||
}
|
||||
comments={comments.get('byId')}
|
||||
users={users.get('byId')}
|
||||
|
||||
@@ -34,19 +34,33 @@ Promise.all([
|
||||
coralApi('/comments?status=rejected'),
|
||||
coralApi('/comments?action_type=flag')
|
||||
])
|
||||
.then(res => Promise.all(res.map(coralApi.handleResp)))
|
||||
.then(([pending, rejected, flagged]) => {
|
||||
flagged = flagged.map(comment => comment.flagged = true);
|
||||
pending.comments = pending.comments.concat(rejected).concat(flagged);
|
||||
return pending;
|
||||
/* Combine seperate calls into a single object */
|
||||
let all = {};
|
||||
all.comments = pending.comments
|
||||
.concat(rejected.comments)
|
||||
.concat(flagged.comments.map(comment => {
|
||||
comment.flagged = true;
|
||||
return comment;
|
||||
}));
|
||||
all.users = pending.users
|
||||
.concat(rejected.users)
|
||||
.concat(flagged.users);
|
||||
all.actions = pending.actions
|
||||
.concat(rejected.actions)
|
||||
.concat(flagged.actions);
|
||||
return all;
|
||||
})
|
||||
.then(res => {
|
||||
.then(all => {
|
||||
console.log('All', all);
|
||||
/* Post comments and users to redux store. Actions will be posted when they are needed. */
|
||||
store.dispatch({type: 'USERS_MODERATION_QUEUE_FETCH_SUCCESS',
|
||||
users: res.users});
|
||||
users: all.users});
|
||||
store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_SUCCESS',
|
||||
comments: res.comments});
|
||||
})
|
||||
.catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error}));
|
||||
comments: all.comments});
|
||||
|
||||
});
|
||||
// .catch(error => store.dispatch({type: 'COMMENTS_MODERATION_QUEUE_FETCH_FAILED', error}));
|
||||
|
||||
// Update a comment. Now to update a comment we need to send back the whole object
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
const express = require('express');
|
||||
const Comment = require('../../../models/comment');
|
||||
const User = require('../../../models/user');
|
||||
const Action = require('../../../models/action');
|
||||
const wordlist = require('../../../services/wordlist');
|
||||
const authorization = require('../../../middleware/authorization');
|
||||
const _ = require('lodash');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -16,9 +19,22 @@ router.get('/', authorization.needed('admin'), (req, res, next) => {
|
||||
query = Comment.all();
|
||||
}
|
||||
|
||||
query.then(comments => {
|
||||
res.json(comments);
|
||||
query.then((comments) => {
|
||||
return Promise.all([
|
||||
comments,
|
||||
User.findByIdArray(_.uniq(comments.map((comment) => comment.author_id))),
|
||||
Action.getActionSummaries(_.uniq([
|
||||
...comments.map((comment) => comment.id),
|
||||
...comments.map((comment) => comment.author_id)
|
||||
]))
|
||||
]);
|
||||
})
|
||||
.then(([comments, users, actions])=>
|
||||
res.status(200).json({
|
||||
comments,
|
||||
users,
|
||||
actions
|
||||
}))
|
||||
.catch((err) => {
|
||||
next(err);
|
||||
});
|
||||
|
||||
@@ -37,6 +37,7 @@ describe('/api/v1/comments', () => {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
author_id: '456',
|
||||
status: 'accepted'
|
||||
}];
|
||||
|
||||
@@ -90,7 +91,7 @@ describe('/api/v1/comments', () => {
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body[0]).to.have.property('id', 'def-rejected');
|
||||
expect(res.body.comments[0]).to.have.property('id', 'def-rejected');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -100,8 +101,8 @@ describe('/api/v1/comments', () => {
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body).to.have.length(1);
|
||||
expect(res.body[0]).to.have.property('id', 'hij');
|
||||
expect(res.body.comments).to.have.length(1);
|
||||
expect(res.body.comments[0]).to.have.property('id', 'hij');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -111,7 +112,7 @@ describe('/api/v1/comments', () => {
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body).to.have.length(2);
|
||||
expect(res.body.comments).to.have.length(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -122,8 +123,8 @@ describe('/api/v1/comments', () => {
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
|
||||
expect(res.body).to.have.length(1);
|
||||
expect(res.body[0]).to.have.property('id', 'abc');
|
||||
expect(res.body.comments).to.have.length(1);
|
||||
expect(res.body.comments[0]).to.have.property('id', 'abc');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user