mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement right order of notifications middleware
This commit is contained in:
parent
4a6ef3f9f6
commit
f86e98b32e
@ -20,9 +20,9 @@ export default schema => {
|
|||||||
validUrlMiddleware,
|
validUrlMiddleware,
|
||||||
sluggifyMiddleware,
|
sluggifyMiddleware,
|
||||||
excerptMiddleware,
|
excerptMiddleware,
|
||||||
|
notificationsMiddleware,
|
||||||
xssMiddleware,
|
xssMiddleware,
|
||||||
fixImageUrlsMiddleware,
|
fixImageUrlsMiddleware,
|
||||||
notificationsMiddleware,
|
|
||||||
softDeleteMiddleware,
|
softDeleteMiddleware,
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
includedFieldsMiddleware,
|
includedFieldsMiddleware,
|
||||||
|
|||||||
@ -1,20 +1,20 @@
|
|||||||
import extractIds from './extractMentions'
|
import extractIds from './extractMentions'
|
||||||
|
|
||||||
const notify = async (resolve, root, args, context, resolveInfo) => {
|
const notify = async (resolve, root, args, context, resolveInfo) => {
|
||||||
|
const ids = extractIds(args.content) // before mention class gets removed
|
||||||
const post = await resolve(root, args, context, resolveInfo)
|
const post = await resolve(root, args, context, resolveInfo)
|
||||||
|
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const { content, id: postId } = post
|
const { content, id: postId } = post
|
||||||
const slugs = extractIds(content)
|
|
||||||
const createdAt = (new Date()).toISOString()
|
const createdAt = (new Date()).toISOString()
|
||||||
const cypher = `
|
const cypher = `
|
||||||
match(u:User) where u.slug in $slugs
|
match(u:User) where u.id in $ids
|
||||||
match(p:Post) where p.id = $postId
|
match(p:Post) where p.id = $postId
|
||||||
create(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt})
|
create(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt})
|
||||||
merge (n)-[:NOTIFIED]->(u)
|
merge (n)-[:NOTIFIED]->(u)
|
||||||
merge (p)-[:NOTIFIED]->(n)
|
merge (p)-[:NOTIFIED]->(n)
|
||||||
`
|
`
|
||||||
await session.run(cypher, { slugs, createdAt, postId })
|
await session.run(cypher, { ids, createdAt, postId })
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
return post
|
return post
|
||||||
|
|||||||
@ -54,26 +54,31 @@ describe('currentUser { notifications }', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('who mentions me in a post', () => {
|
describe('who mentions me in a post', () => {
|
||||||
|
let post
|
||||||
|
const title = 'Mentioning Al Capone'
|
||||||
|
const content = 'Hey <a class="mention" href="/profile/you/al-capone">@al-capone</a> how do you do?'
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const content = 'Hey @al-capone how do you do?'
|
|
||||||
const title = 'Mentioning Al Capone'
|
|
||||||
const createPostMutation = `
|
const createPostMutation = `
|
||||||
mutation($title: String!, $content: String!) {
|
mutation($title: String!, $content: String!) {
|
||||||
CreatePost(title: $title, content: $content) {
|
CreatePost(title: $title, content: $content) {
|
||||||
|
id
|
||||||
title
|
title
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
authorClient = new GraphQLClient(host, { headers: authorHeaders })
|
authorClient = new GraphQLClient(host, { headers: authorHeaders })
|
||||||
await authorClient.request(createPostMutation, { title, content })
|
const { CreatePost } = await authorClient.request(createPostMutation, { title, content })
|
||||||
|
post = CreatePost
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends you a notification', async () => {
|
it('sends you a notification', async () => {
|
||||||
|
const newContent = 'Hey <a href="/profile/you/al-capone" target=\"_blank\">@al-capone</a> how do you do?'
|
||||||
const expected = {
|
const expected = {
|
||||||
currentUser: {
|
currentUser: {
|
||||||
notifications: [
|
notifications: [
|
||||||
{ read: false, post: { content: 'Hey @al-capone how do you do?' } }
|
{ read: false, post: { content: newContent } }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user