Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status field to Reply #349

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/graphql/models/Reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ const Reply = new GraphQLObjectType({
},
text: { type: GraphQLString },
type: { type: new GraphQLNonNull(ReplyTypeEnum) },
status: {
type: new GraphQLNonNull(ArticleReplyStatusEnum),
description:
'The status of this reply, calculated from its author and article replies.',
async resolve(reply, args, context) {
const user = await userFieldResolver(reply, args, context);
if (user && user.blockedReason) return 'BLOCKED';

const articleReplies =
await context.loaders.articleRepliesByReplyIdLoader.load(reply.id);
return articleReplies.every((ar) => ar.status !== 'NORMAL')
? 'DELETED'
: 'NORMAL';
},
},
reference: { type: GraphQLString },
articleReplies: {
type: new GraphQLNonNull(
Expand Down
12 changes: 11 additions & 1 deletion src/graphql/queries/__fixtures__/GetReplyAndArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
positiveFeedbackCount: 0,
negativeFeedbackCount: 1,
userId: 'blocked-user',
appId: 'app1',
appId: 'WEBSITE',
},
],
normalArticleReplyCount: 1,
Expand Down Expand Up @@ -166,6 +166,12 @@ export default {
reference: 'barbar2',
type: 'NOT_ARTICLE',
},
'/replies/doc/bar5': {
text: 'spam content',
type: 'NOT_ARTICLE',
userId: 'blocked-user',
appId: 'WEBSITE',
},
'/replies/doc/fofo': {
text: 'fofo',
reference: 'barfofo',
Expand Down Expand Up @@ -247,6 +253,10 @@ export default {
title: '免費訊息詐騙',
description: '詐騙貼圖、假行銷手法。',
},
'/users/doc/blocked-user': {
appId: 'WEBSITE',
blockedReason: 'https://announcement.url',
},

...Array.from(new Array(11)).reduce((mockMap, _, i) => {
mockMap[`/replyrequests/doc/popular${i}`] = {
Expand Down
21 changes: 21 additions & 0 deletions src/graphql/queries/__tests__/GetReplyAndGetArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ describe('GetReplyAndGetArticle', () => {
text
}
}
status
}
}
`()
Expand Down Expand Up @@ -599,6 +600,26 @@ describe('GetReplyAndGetArticle', () => {
`()
).toMatchSnapshot('similarReply sorting test');
});

it('sets status to BLOCKED when the author is blocked', async () => {
expect(
await gql`
{
GetReply(id: "bar5") {
status
}
}
`()
).toMatchInlineSnapshot(`
Object {
"data": Object {
"GetReply": Object {
"status": "BLOCKED",
},
},
}
`);
});
});

afterAll(() => unloadFixtures(fixtures));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ Object {
},
],
"reference": "barbar",
"status": "NORMAL",
"text": "bar",
"type": "NOT_ARTICLE",
},
Expand All @@ -464,7 +465,7 @@ Object {
"similarReplies": Object {
"edges": Array [
Object {
"cursor": "WzEuODg5MTY5Mywic2ltaWxhci10by1iYXIiXQ==",
"cursor": "WzIuMTE2NjU0LCJzaW1pbGFyLXRvLWJhciJd",
"highlight": Object {
"hyperlinks": Array [],
"reference": "<HIGHLIGHT>barbar</HIGHLIGHT>",
Expand All @@ -473,7 +474,7 @@ Object {
"node": Object {
"id": "similar-to-bar",
},
"score": 1.8891693,
"score": 2.116654,
},
Object {
"cursor": "WzAuNTY2MzE3Miwic2ltaWxhci10by1iYXIyIl0=",
Expand Down Expand Up @@ -523,7 +524,7 @@ Object {
"score": 0.5663172,
},
Object {
"cursor": "WzEuODg5MTY5Mywic2ltaWxhci10by1iYXIiXQ==",
"cursor": "WzIuMTE2NjU0LCJzaW1pbGFyLXRvLWJhciJd",
"highlight": Object {
"hyperlinks": Array [],
"reference": "<HIGHLIGHT>barbar</HIGHLIGHT>",
Expand All @@ -532,7 +533,7 @@ Object {
"node": Object {
"id": "similar-to-bar",
},
"score": 1.8891693,
"score": 2.116654,
},
],
},
Expand Down
Loading