mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Avoid to send out notifications for email adresses
This commit is contained in:
parent
93097d586c
commit
f372cdcbdb
10
backend/src/middleware/notifications/mentions.js
Normal file
10
backend/src/middleware/notifications/mentions.js
Normal 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
|
||||
}
|
||||
15
backend/src/middleware/notifications/mentions.spec.js
Normal file
15
backend/src/middleware/notifications/mentions.spec.js
Normal 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([])
|
||||
})
|
||||
})
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user