Skip to content

Commit 7b2d03a

Browse files
authoredSep 30, 2024··
Merge pull request #349 from cofacts/reply-status
Add status field to Reply
2 parents 5f41b03 + 7230a58 commit 7b2d03a

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed
 

‎src/graphql/models/Reply.js

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ const Reply = new GraphQLObjectType({
3737
},
3838
text: { type: GraphQLString },
3939
type: { type: new GraphQLNonNull(ReplyTypeEnum) },
40+
status: {
41+
type: new GraphQLNonNull(ArticleReplyStatusEnum),
42+
description:
43+
'The status of this reply, calculated from its author and article replies.',
44+
async resolve(reply, args, context) {
45+
const user = await userFieldResolver(reply, args, context);
46+
if (user && user.blockedReason) return 'BLOCKED';
47+
48+
const articleReplies =
49+
await context.loaders.articleRepliesByReplyIdLoader.load(reply.id);
50+
return articleReplies.every((ar) => ar.status !== 'NORMAL')
51+
? 'DELETED'
52+
: 'NORMAL';
53+
},
54+
},
4055
reference: { type: GraphQLString },
4156
articleReplies: {
4257
type: new GraphQLNonNull(

‎src/graphql/queries/__fixtures__/GetReplyAndArticle.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252
positiveFeedbackCount: 0,
5353
negativeFeedbackCount: 1,
5454
userId: 'blocked-user',
55-
appId: 'app1',
55+
appId: 'WEBSITE',
5656
},
5757
],
5858
normalArticleReplyCount: 1,
@@ -166,6 +166,12 @@ export default {
166166
reference: 'barbar2',
167167
type: 'NOT_ARTICLE',
168168
},
169+
'/replies/doc/bar5': {
170+
text: 'spam content',
171+
type: 'NOT_ARTICLE',
172+
userId: 'blocked-user',
173+
appId: 'WEBSITE',
174+
},
169175
'/replies/doc/fofo': {
170176
text: 'fofo',
171177
reference: 'barfofo',
@@ -247,6 +253,10 @@ export default {
247253
title: '免費訊息詐騙',
248254
description: '詐騙貼圖、假行銷手法。',
249255
},
256+
'/users/doc/blocked-user': {
257+
appId: 'WEBSITE',
258+
blockedReason: 'https://announcement.url',
259+
},
250260

251261
...Array.from(new Array(11)).reduce((mockMap, _, i) => {
252262
mockMap[`/replyrequests/doc/popular${i}`] = {

‎src/graphql/queries/__tests__/GetReplyAndGetArticle.js

+21
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ describe('GetReplyAndGetArticle', () => {
505505
text
506506
}
507507
}
508+
status
508509
}
509510
}
510511
`()
@@ -599,6 +600,26 @@ describe('GetReplyAndGetArticle', () => {
599600
`()
600601
).toMatchSnapshot('similarReply sorting test');
601602
});
603+
604+
it('sets status to BLOCKED when the author is blocked', async () => {
605+
expect(
606+
await gql`
607+
{
608+
GetReply(id: "bar5") {
609+
status
610+
}
611+
}
612+
`()
613+
).toMatchInlineSnapshot(`
614+
Object {
615+
"data": Object {
616+
"GetReply": Object {
617+
"status": "BLOCKED",
618+
},
619+
},
620+
}
621+
`);
622+
});
602623
});
603624

604625
afterAll(() => unloadFixtures(fixtures));

‎src/graphql/queries/__tests__/__snapshots__/GetReplyAndGetArticle.js.snap

+5-4
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ Object {
450450
},
451451
],
452452
"reference": "barbar",
453+
"status": "NORMAL",
453454
"text": "bar",
454455
"type": "NOT_ARTICLE",
455456
},
@@ -464,7 +465,7 @@ Object {
464465
"similarReplies": Object {
465466
"edges": Array [
466467
Object {
467-
"cursor": "WzEuODg5MTY5Mywic2ltaWxhci10by1iYXIiXQ==",
468+
"cursor": "WzIuMTE2NjU0LCJzaW1pbGFyLXRvLWJhciJd",
468469
"highlight": Object {
469470
"hyperlinks": Array [],
470471
"reference": "<HIGHLIGHT>barbar</HIGHLIGHT>",
@@ -473,7 +474,7 @@ Object {
473474
"node": Object {
474475
"id": "similar-to-bar",
475476
},
476-
"score": 1.8891693,
477+
"score": 2.116654,
477478
},
478479
Object {
479480
"cursor": "WzAuNTY2MzE3Miwic2ltaWxhci10by1iYXIyIl0=",
@@ -523,7 +524,7 @@ Object {
523524
"score": 0.5663172,
524525
},
525526
Object {
526-
"cursor": "WzEuODg5MTY5Mywic2ltaWxhci10by1iYXIiXQ==",
527+
"cursor": "WzIuMTE2NjU0LCJzaW1pbGFyLXRvLWJhciJd",
527528
"highlight": Object {
528529
"hyperlinks": Array [],
529530
"reference": "<HIGHLIGHT>barbar</HIGHLIGHT>",
@@ -532,7 +533,7 @@ Object {
532533
"node": Object {
533534
"id": "similar-to-bar",
534535
},
535-
"score": 1.8891693,
536+
"score": 2.116654,
536537
},
537538
],
538539
},

0 commit comments

Comments
 (0)
Please sign in to comment.