mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
drastically improved queries involving actions + comments
This commit is contained in:
@@ -119,7 +119,7 @@ const getCountsByParentID = (context, parent_ids) => {
|
||||
* @return {Promise} resolves to the counts of the comments from the
|
||||
* query
|
||||
*/
|
||||
const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id, author_id, tags}) => {
|
||||
const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id, author_id, tags, action_type}) => {
|
||||
let query = CommentModel.find();
|
||||
|
||||
if (ids) {
|
||||
@@ -142,6 +142,16 @@ const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id, au
|
||||
query = query.where({author_id});
|
||||
}
|
||||
|
||||
if (context.user != null && context.user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
|
||||
query = query.where({
|
||||
action_counts: {
|
||||
[action_type.toLowerCase()]: {
|
||||
$gt: 0,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (tags) {
|
||||
query = query.find({
|
||||
'tags.tag.name': {
|
||||
@@ -161,7 +171,7 @@ const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id, au
|
||||
* @param {Object} context graph context
|
||||
* @param {Object} query query terms to apply to the comments query
|
||||
*/
|
||||
const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, author_id, limit, cursor, sort, excludeIgnored, tags}) => {
|
||||
const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, author_id, limit, cursor, sort, excludeIgnored, tags, action_type}) => {
|
||||
let comments = CommentModel.find();
|
||||
|
||||
// Only administrators can search for comments with statuses that are not
|
||||
@@ -180,6 +190,16 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
});
|
||||
}
|
||||
|
||||
if (user != null && user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
|
||||
comments = comments.where({
|
||||
action_counts: {
|
||||
[action_type.toLowerCase()]: {
|
||||
$gt: 0,
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (ids) {
|
||||
comments = comments.find({
|
||||
id: {
|
||||
|
||||
@@ -26,13 +26,7 @@ const RootQuery = {
|
||||
|
||||
// This endpoint is used for loading moderation queues, so hide it in the
|
||||
// event that we aren't an admin.
|
||||
async comments(_, {query}, {user, loaders: {Comments, Actions}}) {
|
||||
let {action_type} = query;
|
||||
|
||||
if (user != null && user.can(SEARCH_OTHERS_COMMENTS) && action_type) {
|
||||
query.ids = await Actions.getByTypes({action_type, item_type: 'COMMENTS'});
|
||||
}
|
||||
|
||||
async comments(_, {query}, {loaders: {Comments}}) {
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
|
||||
@@ -40,19 +34,13 @@ const RootQuery = {
|
||||
return Comments.get.load(id);
|
||||
},
|
||||
|
||||
async commentCount(_, {query}, {user, loaders: {Actions, Comments, Assets}}) {
|
||||
|
||||
async commentCount(_, {query}, {user, loaders: {Comments, Assets}}) {
|
||||
if (user == null || !user.can(SEARCH_OTHERS_COMMENTS)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {action_type, asset_url} = query;
|
||||
|
||||
if (action_type) {
|
||||
query.ids = await Actions.getByTypes({action_type, item_type: 'COMMENTS'});
|
||||
}
|
||||
|
||||
if (asset_url) {
|
||||
const {asset_url} = query;
|
||||
if (asset_url && asset_url.length > 0) {
|
||||
let asset = await Assets.findByUrl(asset_url);
|
||||
if (asset) {
|
||||
query.asset_id = asset.id;
|
||||
|
||||
Reference in New Issue
Block a user