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