Avoid to send out notifications for email adresses

This commit is contained in:
Robert Schäfer 2019-04-08 12:01:09 +02:00
parent 93097d586c
commit f372cdcbdb
3 changed files with 27 additions and 6 deletions

View File

@ -0,0 +1,10 @@
const MENTION_REGEX = /\s@(\S+)/g
export function extractSlugs(content) {
let slugs = []
let match
while ((match = MENTION_REGEX.exec(content)) != null) {
slugs.push(match[1])
}
return slugs
}

View File

@ -0,0 +1,15 @@
import { extractSlugs } from './mentions'
describe('extract', () => {
describe('finds mentions in the form of', () => {
it('@user', () => {
const content = 'Hello @user'
expect(extractSlugs(content)).toEqual(['user'])
})
})
it('ignores email addresses', () => {
const content = 'Hello somebody@example.org'
expect(extractSlugs(content)).toEqual([])
})
})

View File

@ -1,16 +1,12 @@
const MENTION_REGEX = /@(\S+)/g
import { extractSlugs } from './notifications/mentions'
const notify = async (resolve, root, args, context, resolveInfo) => {
const post = await resolve(root, args, context, resolveInfo)
const session = context.driver.session()
const { content, id: postId } = post
const slugs = []
const slugs = extractSlugs(content)
const createdAt = (new Date()).toISOString()
let match
while ((match = MENTION_REGEX.exec(content)) != null) {
slugs.push(match[1])
}
const cypher = `
match(u:User) where u.slug in $slugs
match(p:Post) where p.id = $postId