provide information of the observing status of the post after creating a comment (#8310)

This commit is contained in:
Moriz Wahl 2025-03-31 20:41:39 +02:00 committed by GitHub
parent 538f409086
commit 316c12bd35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 11 deletions

View File

@ -100,6 +100,14 @@ export default {
author: '<-[:WROTE]-(related:User)',
post: '-[:COMMENTS]->(related:Post)',
},
count: {
postObservingUsersCount:
'-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(related:User) WHERE obs.active = true AND NOT related.deleted AND NOT related.disabled',
},
boolean: {
isPostObservedByMe:
'MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(related:User {id: $cypherParams.currentUserId}) WHERE obs.active = true RETURN COUNT(related) >= 1',
},
}),
},
}

View File

@ -22,6 +22,8 @@ const createCommentMutation = gql`
mutation ($id: ID, $postId: ID!, $content: String!) {
CreateComment(id: $id, postId: $postId, content: $content) {
id
isPostObservedByMe
postObservingUsersCount
}
}
`
@ -122,11 +124,20 @@ describe('observing posts', () => {
})
it('has another user observing the post AFTER commenting it', async () => {
await mutate({
mutation: createCommentMutation,
variables: {
postId: 'p2',
content: 'After commenting the post, I should observe the post automatically',
await expect(
mutate({
mutation: createCommentMutation,
variables: {
postId: 'p2',
content: 'After commenting the post, I should observe the post automatically',
},
}),
).resolves.toMatchObject({
data: {
CreateComment: {
isPostObservedByMe: true,
postObservingUsersCount: 2,
},
},
})
@ -187,12 +198,21 @@ describe('observing posts', () => {
describe('comment the post again', () => {
it('does NOT alter the observation state', async () => {
await mutate({
mutation: createCommentMutation,
variables: {
postId: 'p2',
content:
'After commenting the post I do not observe again, I should NOT observe the post',
await expect(
mutate({
mutation: createCommentMutation,
variables: {
postId: 'p2',
content:
'After commenting the post I do not observe again, I should NOT observe the post',
},
}),
).resolves.toMatchObject({
data: {
CreateComment: {
isPostObservedByMe: false,
postObservingUsersCount: 1,
},
},
})

View File

@ -47,6 +47,12 @@ type Comment {
updatedAt: String
deleted: Boolean
disabled: Boolean
isPostObservedByMe: Boolean!
@cypher(
statement: "MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(u:User {id: $cypherParams.currentUserId}) WHERE obs.active = true RETURN COUNT(u) >= 1"
)
postObservingUsersCount: Int!
@cypher(statement: "MATCH (this)-[:COMMENTS]->(:Post)<-[obs:OBSERVES]-(u:User) WHERE obs.active = true AND NOT u.disabled = true AND NOT u.deleted = true RETURN COUNT(DISTINCT u)")
}
type Query {

View File

@ -135,5 +135,7 @@ export const commentFragment = gql`
deleted
content
contentExcerpt
isPostObservedByMe
postObservingUsersCount
}
`