mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 13:16:29 +08:00
Merge pull request #790 from coralproject/commentsid
Search Comment in an Asset
This commit is contained in:
@@ -81,7 +81,7 @@ class Stream extends React.Component {
|
||||
setActiveReplyBox,
|
||||
appendItemArray,
|
||||
commentClassNames,
|
||||
root: {asset, asset: {comments, totalCommentCount}, comment, me},
|
||||
root: {asset, asset: {comment, comments, totalCommentCount}, me},
|
||||
postComment,
|
||||
addNotification,
|
||||
editComment,
|
||||
|
||||
@@ -3,6 +3,7 @@ import {compose, gql} from 'react-apollo';
|
||||
import {connect} from 'react-redux';
|
||||
import {bindActionCreators} from 'redux';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import get from 'lodash/get';
|
||||
import branch from 'recompose/branch';
|
||||
import renderComponent from 'recompose/renderComponent';
|
||||
|
||||
@@ -91,7 +92,7 @@ class EmbedContainer extends React.Component {
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (!prevProps.root.comment && this.props.root.comment) {
|
||||
if (!get(prevProps, 'root.asset.comment') && get(this.props, 'root.asset.comment')) {
|
||||
|
||||
// Scroll to a permalinked comment if one is in the URL once the page is done rendering.
|
||||
setTimeout(() => pym.scrollParentToChildEl('talk-embed-stream-container'), 0);
|
||||
|
||||
@@ -237,16 +237,16 @@ const slots = [
|
||||
const fragments = {
|
||||
root: gql`
|
||||
fragment CoralEmbedStream_Stream_root on RootQuery {
|
||||
comment(id: $commentId) @include(if: $hasComment) {
|
||||
...CoralEmbedStream_Stream_comment
|
||||
${nest(`
|
||||
parent {
|
||||
...CoralEmbedStream_Stream_comment
|
||||
...nest
|
||||
}
|
||||
`, THREADING_LEVEL)}
|
||||
}
|
||||
asset(id: $assetId, url: $assetUrl) {
|
||||
comment(id: $commentId) @include(if: $hasComment) {
|
||||
...CoralEmbedStream_Stream_comment
|
||||
${nest(`
|
||||
parent {
|
||||
...CoralEmbedStream_Stream_comment
|
||||
...nest
|
||||
}
|
||||
`, THREADING_LEVEL)}
|
||||
}
|
||||
id
|
||||
title
|
||||
url
|
||||
|
||||
@@ -12,8 +12,8 @@ function determineCommentDepth(comment) {
|
||||
}
|
||||
|
||||
function applyToCommentsOrigin(root, callback) {
|
||||
if (root.comment) {
|
||||
let comment = root.comment;
|
||||
if (root.asset.comment) {
|
||||
let comment = root.asset.comment;
|
||||
for (let depth = 0; depth <= determineCommentDepth(comment); depth++) {
|
||||
let changes = {$apply: (node) => node ? callback(node) : node};
|
||||
for (let i = 0; i < depth; i++) {
|
||||
@@ -24,7 +24,10 @@ function applyToCommentsOrigin(root, callback) {
|
||||
|
||||
return {
|
||||
...root,
|
||||
comment,
|
||||
asset: {
|
||||
...root.asset,
|
||||
comment,
|
||||
},
|
||||
};
|
||||
}
|
||||
return update(root, {
|
||||
@@ -135,8 +138,8 @@ export function findCommentInEmbedQuery(root, callbackOrId) {
|
||||
if (typeof callbackOrId === 'string') {
|
||||
callback = (node) => node.id === callbackOrId;
|
||||
}
|
||||
if (root.comment) {
|
||||
return findComment([getTopLevelParent(root.comment)], callback);
|
||||
if (root.asset.comment) {
|
||||
return findComment([getTopLevelParent(root.asset.comment)], callback);
|
||||
}
|
||||
if (!root.asset.comments) {
|
||||
return false;
|
||||
|
||||
@@ -445,12 +445,12 @@ const genRecentComments = (_, ids) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* genComments returns the comments by the id's. Only admins can see non-public comments.
|
||||
* getComments returns the comments by the id's. Only admins can see non-public comments.
|
||||
* @param {Object} context graph context
|
||||
* @param {Array<String>} ids the comment id's to fetch
|
||||
* @return {Promise} resolves to the comments
|
||||
*/
|
||||
const genComments = ({user}, ids) => {
|
||||
const getComments = ({user}, ids) => {
|
||||
let comments;
|
||||
if (user && user.can(SEARCH_OTHERS_COMMENTS)) {
|
||||
comments = CommentModel.find({
|
||||
@@ -478,7 +478,7 @@ const genComments = ({user}, ids) => {
|
||||
*/
|
||||
module.exports = (context) => ({
|
||||
Comments: {
|
||||
get: new DataLoader((ids) => genComments(context, ids)),
|
||||
get: new DataLoader((ids) => getComments(context, ids)),
|
||||
getByQuery: (query) => getCommentsByQuery(context, query),
|
||||
getCountByQuery: (query) => getCommentCountByQuery(context, query),
|
||||
countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', 3600, (ids) => getCountsByAssetID(context, ids)),
|
||||
|
||||
@@ -4,6 +4,14 @@ const Asset = {
|
||||
recentComments({id}, _, {loaders: {Comments}}) {
|
||||
return Comments.genRecentComments.load(id);
|
||||
},
|
||||
async comment({id}, {id: commentId}, {loaders: {Comments}}) {
|
||||
const comments = await Comments.getByQuery({
|
||||
asset_id: id,
|
||||
ids: commentId
|
||||
});
|
||||
|
||||
return comments.nodes[0];
|
||||
},
|
||||
comments({id}, {sort, limit, deep, excludeIgnored, tags}, {loaders: {Comments}}) {
|
||||
return Comments.getByQuery({
|
||||
asset_id: id,
|
||||
|
||||
@@ -580,6 +580,9 @@ type Asset {
|
||||
deep: Boolean,
|
||||
): CommentConnection!
|
||||
|
||||
# A Comment from the Asset by comment's ID
|
||||
comment(id: ID!): Comment
|
||||
|
||||
# The count of top level comments on the asset.
|
||||
commentCount(excludeIgnored: Boolean, tags: [String!]): Int
|
||||
|
||||
|
||||
Reference in New Issue
Block a user