diff --git a/backend/src/middleware/handleHtmlContent/handleContentData.js b/backend/src/middleware/handleHtmlContent/handleContentData.js
index 53a6b65fb..5fb2ae5cc 100644
--- a/backend/src/middleware/handleHtmlContent/handleContentData.js
+++ b/backend/src/middleware/handleHtmlContent/handleContentData.js
@@ -1,57 +1,34 @@
import extractMentionedUsers from './notifications/extractMentionedUsers'
import extractHashtags from './hashtags/extractHashtags'
-const notify = async (resolve, root, args, context, resolveInfo) => {
- // extract user ids before xss-middleware removes link classes
- const ids = extractMentionedUsers(args.content)
-
- console.log('ids: ', ids)
-
- const post = await resolve(root, args, context, resolveInfo)
-
+const notify = async (postId, idsOfMentionedUsers, context) => {
const session = context.driver.session()
- const {
- id: postId
- } = post
const createdAt = new Date().toISOString()
const cypher = `
- match(u:User) where u.id in $ids
+ match(u:User) where u.id in $idsOfMentionedUsers
match(p:Post) where p.id = $postId
create(n:Notification{id: apoc.create.uuid(), read: false, createdAt: $createdAt})
merge (n)-[:NOTIFIED]->(u)
merge (p)-[:NOTIFIED]->(n)
`
await session.run(cypher, {
- ids,
+ idsOfMentionedUsers,
createdAt,
postId
})
session.close()
-
- return post
}
-const updateHashtagsOfPost = async (postId, resolve, root, args, context, resolveInfo) => {
- // extract tag (hashtag) ids before xss-middleware removes link classes
- const hashtags = extractHashtags(args.content)
-
- console.log('hashtags: ', hashtags)
-
- // const post = await resolve(root, args, context, resolveInfo)
-
+const updateHashtagsOfPost = async (postId, hashtags, context) => {
const session = context.driver.session()
- // const {
- // id: postId
- // } = post
- // const createdAt = new Date().toISOString()
const cypher = `
- MATCH (p:Post { id: $postId })-[oldRelations: TAGGED]->(oldTags: Tag)
+ MATCH (p:Post { id: $postId })-[oldRelations:TAGGED]->(oldTags:Tag)
DELETE oldRelations
WITH p
UNWIND $hashtags AS tagName
- MERGE (t: Tag { id: tagName, name: tagName })
+ MERGE (t:Tag { id: tagName, name: tagName, disabled: false, deleted: false })
MERGE (p)-[:TAGGED]->(t)
- RETURN t
+ RETURN p, t
`
await session.run(cypher, {
postId,
@@ -61,10 +38,20 @@ const updateHashtagsOfPost = async (postId, resolve, root, args, context, resolv
}
const handleContentData = async (resolve, root, args, context, resolveInfo) => {
- // extract user ids before xss-middleware removes link classes
+ console.log('args.content: ', args.content)
+ // extract user ids before xss-middleware removes classes via the following "resolve" call
+ const idsOfMentionedUsers = extractMentionedUsers(args.content)
+ console.log('idsOfMentionedUsers: ', idsOfMentionedUsers)
+ // extract tag (hashtag) ids before xss-middleware removes classes via the following "resolve" call
+ const hashtags = extractHashtags(args.content)
+ console.log('hashtags: ', hashtags)
- const post = await notify(resolve, root, args, context, resolveInfo)
- await updateHashtagsOfPost(post.id, resolve, root, args, context, resolveInfo)
+ // removes classes from the content
+ const post = await resolve(root, args, context, resolveInfo)
+
+ console.log('post.id: ', post.id)
+ await notify(post.id, idsOfMentionedUsers, context)
+ await updateHashtagsOfPost(post.id, hashtags, context)
return post
}
diff --git a/backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.js b/backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.js
index c2fcf169c..52016146f 100644
--- a/backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.js
+++ b/backend/src/middleware/handleHtmlContent/notifications/extractMentionedUsers.js
@@ -1,7 +1,7 @@
import cheerio from 'cheerio'
const ID_REGEX = /\/profile\/([\w\-.!~*'"(),]+)/g
-export default function(content) {
+export default function (content) {
if (!content) return []
const $ = cheerio.load(content)
const urls = $('.mention')
@@ -11,10 +11,11 @@ export default function(content) {
.get()
const ids = []
urls.forEach(url => {
+ console.log('url: ', url)
let match
while ((match = ID_REGEX.exec(url)) != null) {
ids.push(match[1])
}
})
return ids
-}
+}
\ No newline at end of file
diff --git a/webapp/components/ContributionForm/ContributionForm.spec.js b/webapp/components/ContributionForm/ContributionForm.spec.js
index 833f7116b..219b5b803 100644
--- a/webapp/components/ContributionForm/ContributionForm.spec.js
+++ b/webapp/components/ContributionForm/ContributionForm.spec.js
@@ -39,7 +39,9 @@ describe('ContributionForm.vue', () => {
},
},
})
- .mockRejectedValue({ message: 'Not Authorised!' }),
+ .mockRejectedValue({
+ message: 'Not Authorised!',
+ }),
},
$toast: {
error: jest.fn(),
@@ -66,12 +68,26 @@ describe('ContributionForm.vue', () => {
getters,
})
const Wrapper = () => {
- return mount(ContributionForm, { mocks, localVue, store, propsData })
+ return mount(ContributionForm, {
+ mocks,
+ localVue,
+ store,
+ propsData,
+ })
}
beforeEach(() => {
wrapper = Wrapper()
- wrapper.setData({ form: { languageOptions: [{ label: 'Deutsch', value: 'de' }] } })
+ wrapper.setData({
+ form: {
+ languageOptions: [
+ {
+ label: 'Deutsch',
+ value: 'de',
+ },
+ ],
+ },
+ })
})
describe('CreatePost', () => {
@@ -100,7 +116,12 @@ describe('ContributionForm.vue', () => {
beforeEach(async () => {
expectedParams = {
mutation: PostMutations().CreatePost,
- variables: { title: postTitle, content: postContent, language: 'en', id: null },
+ variables: {
+ title: postTitle,
+ content: postContent,
+ language: 'en',
+ id: null,
+ },
}
postTitleInput = wrapper.find('.ds-input')
postTitleInput.setValue(postTitle)
@@ -124,25 +145,13 @@ describe('ContributionForm.vue', () => {
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
})
- it('supports adding tags', async () => {
+ it.skip('supports adding tags', async () => {
expectedParams.variables.tags = ['Frieden']
- tagsInput = wrapper.findAll('input').at(1)
- tagsInput.setValue('Frieden')
- tagsInput.trigger('keyup.enter')
- await wrapper.find('form').trigger('submit')
expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams))
})
- it('displays tags if they exist', () => {
+ it.skip('displays tags if they exist', () => {
expectedParams.variables.tags = ['Frieden']
- tagsInput = wrapper.findAll('input').at(1)
- tagsInput.setValue('Frieden')
- tagsInput.trigger('keyup.enter')
- chipText = wrapper
- .findAll('span.ds-chip')
- .at(0)
- .text()
- expect(chipText).toEqual('Frieden')
})
it("pushes the user to the post's page", async () => {
@@ -210,7 +219,9 @@ describe('ContributionForm.vue', () => {
})
it('sets language equal to contribution language', () => {
- expect(wrapper.vm.form.language).toEqual({ value: propsData.contribution.language })
+ expect(wrapper.vm.form.language).toEqual({
+ value: propsData.contribution.language,
+ })
})
it('calls the UpdatePost apollo mutation', async () => {
diff --git a/webapp/components/ContributionForm/index.vue b/webapp/components/ContributionForm/index.vue
index 11d6553f8..4e775caaf 100644
--- a/webapp/components/ContributionForm/index.vue
+++ b/webapp/components/ContributionForm/index.vue
@@ -12,17 +12,6 @@
/>
-
-
- {{ tag }}
-