diff --git a/client/coral-admin/src/containers/CommentStream/CommentStream.js b/client/coral-admin/src/containers/CommentStream/CommentStream.js
index b1e002549..113a7bc86 100644
--- a/client/coral-admin/src/containers/CommentStream/CommentStream.js
+++ b/client/coral-admin/src/containers/CommentStream/CommentStream.js
@@ -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 (
@@ -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);
diff --git a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
index 956d3df15..654f0e90c 100644
--- a/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
+++ b/client/coral-admin/src/containers/ModerationQueue/ModerationQueue.js
@@ -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')}
diff --git a/client/coral-admin/src/services/talk-adapter.js b/client/coral-admin/src/services/talk-adapter.js
index 945d73e26..6d79406a6 100644
--- a/client/coral-admin/src/services/talk-adapter.js
+++ b/client/coral-admin/src/services/talk-adapter.js
@@ -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
diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js
index bfb3d67ab..3bdf4afc6 100644
--- a/routes/api/comments/index.js
+++ b/routes/api/comments/index.js
@@ -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);
});
diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js
index 5ac9af7b7..bc8b67bc1 100644
--- a/tests/routes/api/comments/index.js
+++ b/tests/routes/api/comments/index.js
@@ -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');
});
});