mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Wrote and tested the mention of a blocked user on a post of a blocker
Co-Authored-By: mattwr18 <mattwr18@gmail.com>
This commit is contained in:
parent
efb5c75c24
commit
0b9a58e317
@ -6,16 +6,27 @@ const notifyMentions = async (label, id, idsOfMentionedUsers, context) => {
|
||||
|
||||
const session = context.driver.session()
|
||||
const createdAt = new Date().toISOString()
|
||||
const cypher = `
|
||||
MATCH (source)
|
||||
WHERE source.id = $id AND $label IN LABELS(source)
|
||||
MATCH (source)<-[:WROTE]-(author: User)
|
||||
let cypher
|
||||
if (label === 'Post') {
|
||||
cypher = `
|
||||
MATCH (post: Post { id: $id })<-[:WROTE]-(author: User)
|
||||
MATCH (user: User)
|
||||
WHERE user.id in $idsOfMentionedUsers
|
||||
AND NOT (user)<-[:BLOCKED]-(author)
|
||||
CREATE (notification: Notification {id: apoc.create.uuid(), read: false, createdAt: $createdAt })
|
||||
MERGE (source)-[:NOTIFIED]->(notification)-[:NOTIFIED]->(user)
|
||||
MERGE (post)-[:NOTIFIED]->(notification)-[:NOTIFIED]->(user)
|
||||
`
|
||||
} else {
|
||||
cypher = `
|
||||
MATCH (postAuthor: User)-[:WROTE]->(post: Post)<-[:COMMENTS]-(comment: Comment { id: $id })<-[:WROTE]-(author: User)
|
||||
MATCH (user: User)
|
||||
WHERE user.id in $idsOfMentionedUsers
|
||||
AND NOT (user)<-[:BLOCKED]-(author)
|
||||
AND NOT (user)<-[:BLOCKED]-(postAuthor)
|
||||
CREATE (notification: Notification {id: apoc.create.uuid(), read: false, createdAt: $createdAt })
|
||||
MERGE (comment)-[:NOTIFIED]->(notification)-[:NOTIFIED]->(user)
|
||||
`
|
||||
}
|
||||
// "author" of comment, blocked Peter: Jenny
|
||||
// "user" mentioned on post by Jenny: Peter
|
||||
// owner of post: Bob
|
||||
@ -58,12 +69,9 @@ const updateHashtagsOfPost = async (postId, hashtags, context) => {
|
||||
}
|
||||
|
||||
const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => {
|
||||
// extract user ids before xss-middleware removes classes via the following "resolve" call
|
||||
const idsOfMentionedUsers = extractMentionedUsers(args.content)
|
||||
// extract tag (hashtag) ids before xss-middleware removes classes via the following "resolve" call
|
||||
const hashtags = extractHashtags(args.content)
|
||||
|
||||
// removes classes from the content
|
||||
const post = await resolve(root, args, context, resolveInfo)
|
||||
|
||||
await notifyMentions('Post', post.id, idsOfMentionedUsers, context)
|
||||
@ -73,10 +81,7 @@ const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo
|
||||
}
|
||||
|
||||
const handleContentDataOfComment = async (resolve, root, args, context, resolveInfo) => {
|
||||
// extract user ids before xss-middleware removes classes via the following "resolve" call
|
||||
const idsOfMentionedUsers = extractMentionedUsers(args.content)
|
||||
|
||||
// removes classes from the content
|
||||
const comment = await resolve(root, args, context, resolveInfo)
|
||||
|
||||
await notifyMentions('Comment', comment.id, idsOfMentionedUsers, context)
|
||||
@ -89,6 +94,6 @@ export default {
|
||||
CreatePost: handleContentDataOfPost,
|
||||
UpdatePost: handleContentDataOfPost,
|
||||
CreateComment: handleContentDataOfComment,
|
||||
// UpdateComment: handleContentDataOfComment,
|
||||
UpdateComment: handleContentDataOfComment,
|
||||
},
|
||||
}
|
||||
@ -1,14 +1,7 @@
|
||||
import {
|
||||
gql
|
||||
} from '../../jest/helpers'
|
||||
import { gql } from '../../jest/helpers'
|
||||
import Factory from '../../seed/factories'
|
||||
import {
|
||||
createTestClient
|
||||
} from 'apollo-server-testing'
|
||||
import {
|
||||
neode,
|
||||
getDriver
|
||||
} from '../../bootstrap/neo4j'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
import { neode, getDriver } from '../../bootstrap/neo4j'
|
||||
import createServer from '../../server'
|
||||
|
||||
const factory = Factory()
|
||||
@ -59,6 +52,9 @@ describe('notifications', () => {
|
||||
post {
|
||||
content
|
||||
}
|
||||
comment {
|
||||
content
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,7 +96,7 @@ describe('notifications', () => {
|
||||
variables: {
|
||||
id: 'p47',
|
||||
title,
|
||||
content
|
||||
content,
|
||||
},
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
@ -113,24 +109,25 @@ describe('notifications', () => {
|
||||
const expected = expect.objectContaining({
|
||||
data: {
|
||||
currentUser: {
|
||||
notifications: [{
|
||||
notifications: [
|
||||
{
|
||||
read: false,
|
||||
post: {
|
||||
content: expectedContent
|
||||
}
|
||||
}]
|
||||
content: expectedContent,
|
||||
},
|
||||
comment: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
const {
|
||||
query
|
||||
} = createTestClient(server)
|
||||
const { query } = createTestClient(server)
|
||||
await expect(
|
||||
query({
|
||||
query: notificationQuery,
|
||||
variables: {
|
||||
read: false
|
||||
}
|
||||
read: false,
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(expected)
|
||||
})
|
||||
@ -179,17 +176,20 @@ describe('notifications', () => {
|
||||
const expected = expect.objectContaining({
|
||||
data: {
|
||||
currentUser: {
|
||||
notifications: [{
|
||||
notifications: [
|
||||
{
|
||||
read: false,
|
||||
post: {
|
||||
content: expectedContent
|
||||
}
|
||||
content: expectedContent,
|
||||
},
|
||||
comment: null,
|
||||
},
|
||||
{
|
||||
read: false,
|
||||
post: {
|
||||
content: expectedContent
|
||||
}
|
||||
content: expectedContent,
|
||||
},
|
||||
comment: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -199,8 +199,8 @@ describe('notifications', () => {
|
||||
query({
|
||||
query: notificationQuery,
|
||||
variables: {
|
||||
read: false
|
||||
}
|
||||
read: false,
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(expected)
|
||||
})
|
||||
@ -216,51 +216,50 @@ describe('notifications', () => {
|
||||
const expected = expect.objectContaining({
|
||||
data: {
|
||||
currentUser: {
|
||||
notifications: []
|
||||
}
|
||||
notifications: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
const {
|
||||
query
|
||||
} = createTestClient(server)
|
||||
const { query } = createTestClient(server)
|
||||
await expect(
|
||||
query({
|
||||
query: notificationQuery,
|
||||
variables: {
|
||||
read: false
|
||||
}
|
||||
read: false,
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe('but the author of the post blocked a user I mention in a comment', () => {
|
||||
describe('but the author of the post blocked me and a mentioner mentions me in a comment', () => {
|
||||
const createCommentOnPostAction = async () => {
|
||||
await createPostAction()
|
||||
const createCommentMutation = gql`
|
||||
mutation($id: ID, $title: String!, $content: String!) {
|
||||
mutation($id: ID, $postId: ID!, $commentContent: String!) {
|
||||
CreateComment(id: $id, postId: $postId, content: $commentContent) {
|
||||
id
|
||||
content
|
||||
}
|
||||
}
|
||||
`
|
||||
// authenticatedUser = await postAuthor.toJson()
|
||||
// authenticatedUser = await user.toJson()
|
||||
authenticatedUser = await commentMentioner.toJson()
|
||||
await mutate({
|
||||
mutation: createCommentMutation,
|
||||
variables: {
|
||||
id: 'c47',
|
||||
postId: 'p47',
|
||||
commentContent: 'One mention of me with <a data-mention-id="you" class="mention" href="/profile/you" target="_blank">.'
|
||||
commentContent:
|
||||
'One mention of me with <a data-mention-id="you" class="mention" href="/profile/you" target="_blank">.',
|
||||
},
|
||||
})
|
||||
authenticatedUser = await user.toJson()
|
||||
}
|
||||
let mentioner
|
||||
let commentMentioner
|
||||
|
||||
beforeEach(async () => {
|
||||
await postAuthor.relateTo(user, 'blocked')
|
||||
mentioner = await instance.create('User', {
|
||||
commentMentioner = await instance.create('User', {
|
||||
id: 'mentioner',
|
||||
name: 'Mr Mentioner',
|
||||
slug: 'mr-mentioner',
|
||||
@ -270,23 +269,21 @@ describe('notifications', () => {
|
||||
})
|
||||
|
||||
it('sends no notification', async () => {
|
||||
await createPostAction()
|
||||
await createCommentOnPostAction()
|
||||
const expected = expect.objectContaining({
|
||||
data: {
|
||||
currentUser: {
|
||||
notifications: []
|
||||
}
|
||||
notifications: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
const {
|
||||
query
|
||||
} = createTestClient(server)
|
||||
const { query } = createTestClient(server)
|
||||
await expect(
|
||||
query({
|
||||
query: notificationQuery,
|
||||
variables: {
|
||||
read: false
|
||||
}
|
||||
read: false,
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(expected)
|
||||
})
|
||||
@ -342,26 +339,29 @@ describe('Hashtags', () => {
|
||||
})
|
||||
|
||||
it('both Hashtags are created with the "id" set to their "name"', async () => {
|
||||
const expected = [{
|
||||
const expected = [
|
||||
{
|
||||
id: 'Democracy',
|
||||
name: 'Democracy'
|
||||
name: 'Democracy',
|
||||
},
|
||||
{
|
||||
id: 'Liberty',
|
||||
name: 'Liberty'
|
||||
name: 'Liberty',
|
||||
},
|
||||
]
|
||||
await expect(
|
||||
query({
|
||||
query: postWithHastagsQuery,
|
||||
variables: postWithHastagsVariables
|
||||
variables: postWithHastagsVariables,
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
Post: [{
|
||||
Post: [
|
||||
{
|
||||
tags: expect.arrayContaining(expected),
|
||||
}, ],
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
@ -391,26 +391,29 @@ describe('Hashtags', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const expected = [{
|
||||
const expected = [
|
||||
{
|
||||
id: 'Elections',
|
||||
name: 'Elections'
|
||||
name: 'Elections',
|
||||
},
|
||||
{
|
||||
id: 'Liberty',
|
||||
name: 'Liberty'
|
||||
name: 'Liberty',
|
||||
},
|
||||
]
|
||||
await expect(
|
||||
query({
|
||||
query: postWithHastagsQuery,
|
||||
variables: postWithHastagsVariables
|
||||
variables: postWithHastagsVariables,
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
data: {
|
||||
Post: [{
|
||||
tags: expect.arrayContaining(expected)
|
||||
}],
|
||||
Post: [
|
||||
{
|
||||
tags: expect.arrayContaining(expected),
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
@ -88,11 +88,9 @@
|
||||
{{ $t('login.hello') }}
|
||||
<b>{{ userName }}</b>
|
||||
<template v-if="user.role !== 'user'">
|
||||
<ds-text
|
||||
color="softer"
|
||||
size="small"
|
||||
style="margin-bottom: 0"
|
||||
>{{ user.role | camelCase }}</ds-text>
|
||||
<ds-text color="softer" size="small" style="margin-bottom: 0">
|
||||
{{ user.role | camelCase }}
|
||||
</ds-text>
|
||||
</template>
|
||||
<hr />
|
||||
<ds-menu :routes="routes" :matcher="matcher">
|
||||
@ -131,10 +129,14 @@
|
||||
<div id="footer" class="ds-footer">
|
||||
<a href="https://human-connection.org" target="_blank" v-html="$t('site.made')"></a>
|
||||
-
|
||||
<nuxt-link to="/imprint">{{ $t('site.imprint') }}</nuxt-link> ‑
|
||||
<nuxt-link to="/terms-and-conditions">{{ $t('site.termsAndConditions') }}</nuxt-link> ‑
|
||||
<nuxt-link to="/code-of-conduct">{{ $t('site.code-of-conduct') }}</nuxt-link> ‑
|
||||
<nuxt-link to="/data-privacy">{{ $t('site.data-privacy') }}</nuxt-link> ‑
|
||||
<nuxt-link to="/imprint">{{ $t('site.imprint') }}</nuxt-link>
|
||||
‑
|
||||
<nuxt-link to="/terms-and-conditions">{{ $t('site.termsAndConditions') }}</nuxt-link>
|
||||
‑
|
||||
<nuxt-link to="/code-of-conduct">{{ $t('site.code-of-conduct') }}</nuxt-link>
|
||||
‑
|
||||
<nuxt-link to="/data-privacy">{{ $t('site.data-privacy') }}</nuxt-link>
|
||||
‑
|
||||
<nuxt-link to="/changelog">{{ $t('site.changelog') }}</nuxt-link>
|
||||
</div>
|
||||
<div id="overlay" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user