mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
provide information of the observing status of the post after creating a comment (#8310)
This commit is contained in:
parent
538f409086
commit
316c12bd35
@ -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',
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -135,5 +135,7 @@ export const commentFragment = gql`
|
||||
deleted
|
||||
content
|
||||
contentExcerpt
|
||||
isPostObservedByMe
|
||||
postObservingUsersCount
|
||||
}
|
||||
`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user