mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2026-04-06 01:25:31 +00:00
Follow @Tirokk's suggestion
This commit is contained in:
parent
c29ee5e3d3
commit
cbcba8f08d
@ -4,13 +4,13 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
if (!idsOfUsers.length) return
|
if (!idsOfUsers.length) return
|
||||||
|
|
||||||
// Checked here, because it does not go through GraphQL checks at all in this file.
|
// Checked here, because it does not go through GraphQL checks at all in this file.
|
||||||
const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'comment_on_post']
|
const reasonsAllowed = ['mentioned_in_post', 'mentioned_in_comment', 'commented_on_post']
|
||||||
if (!reasonsAllowed.includes(reason)) {
|
if (!reasonsAllowed.includes(reason)) {
|
||||||
throw new Error('Notification reason is not allowed!')
|
throw new Error('Notification reason is not allowed!')
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(label === 'Post' && reason !== 'mentioned_in_post') ||
|
(label === 'Post' && reason !== 'mentioned_in_post') ||
|
||||||
(label === 'Comment' && !['mentioned_in_comment', 'comment_on_post'].includes(reason))
|
(label === 'Comment' && !['mentioned_in_comment', 'commented_on_post'].includes(reason))
|
||||||
) {
|
) {
|
||||||
throw new Error('Notification does not fit the reason!')
|
throw new Error('Notification does not fit the reason!')
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ const notifyUsers = async (label, id, idsOfUsers, reason, context) => {
|
|||||||
`
|
`
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'comment_on_post': {
|
case 'commented_on_post': {
|
||||||
cypher = `
|
cypher = `
|
||||||
MATCH (postAuthor: User)-[:WROTE]->(post: Post)<-[:COMMENTS]-(comment: Comment { id: $id })<-[:WROTE]-(author: User)
|
MATCH (postAuthor: User)-[:WROTE]->(post: Post)<-[:COMMENTS]-(comment: Comment { id: $id })<-[:WROTE]-(author: User)
|
||||||
MATCH (user: User)
|
MATCH (user: User)
|
||||||
@ -108,7 +108,7 @@ const handleCreateComment = async (resolve, root, args, context, resolveInfo) =>
|
|||||||
return record.get('user')
|
return record.get('user')
|
||||||
})
|
})
|
||||||
if (context.user.id !== postAuthor.id) {
|
if (context.user.id !== postAuthor.id) {
|
||||||
await notifyUsers('Comment', comment.id, [postAuthor.id], 'comment_on_post', context)
|
await notifyUsers('Comment', comment.id, [postAuthor.id], 'commented_on_post', context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ describe('notifications', () => {
|
|||||||
{
|
{
|
||||||
read: false,
|
read: false,
|
||||||
createdAt: expect.any(String),
|
createdAt: expect.any(String),
|
||||||
reason: 'comment_on_post',
|
reason: 'commented_on_post',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Comment',
|
__typename: 'Comment',
|
||||||
id: 'c47',
|
id: 'c47',
|
||||||
|
|||||||
@ -16,7 +16,7 @@ const transformReturnType = record => {
|
|||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
notifications: async (parent, args, context, resolveInfo) => {
|
notifications: async (parent, args, context, resolveInfo) => {
|
||||||
const { user } = context
|
const { user: currentUser } = context
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
let notifications
|
let notifications
|
||||||
let whereClause
|
let whereClause
|
||||||
@ -49,7 +49,7 @@ export default {
|
|||||||
RETURN resource, notification, user
|
RETURN resource, notification, user
|
||||||
${orderByClause}
|
${orderByClause}
|
||||||
`
|
`
|
||||||
const result = await session.run(cypher, { id: user.id })
|
const result = await session.run(cypher, { id: currentUser.id })
|
||||||
notifications = await result.records.map(transformReturnType)
|
notifications = await result.records.map(transformReturnType)
|
||||||
} finally {
|
} finally {
|
||||||
session.close()
|
session.close()
|
||||||
@ -59,7 +59,7 @@ export default {
|
|||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
markAsRead: async (parent, args, context, resolveInfo) => {
|
markAsRead: async (parent, args, context, resolveInfo) => {
|
||||||
const { user } = context
|
const { user: currentUser } = context
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
let notification
|
let notification
|
||||||
try {
|
try {
|
||||||
@ -68,7 +68,7 @@ export default {
|
|||||||
SET notification.read = TRUE
|
SET notification.read = TRUE
|
||||||
RETURN resource, notification, user
|
RETURN resource, notification, user
|
||||||
`
|
`
|
||||||
const result = await session.run(cypher, { resourceId: args.id, id: user.id })
|
const result = await session.run(cypher, { resourceId: args.id, id: currentUser.id })
|
||||||
const notifications = await result.records.map(transformReturnType)
|
const notifications = await result.records.map(transformReturnType)
|
||||||
notification = notifications[0]
|
notification = notifications[0]
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
enum ReasonNotification {
|
enum ReasonNotification {
|
||||||
mentioned_in_post
|
mentioned_in_post
|
||||||
mentioned_in_comment
|
mentioned_in_comment
|
||||||
comment_on_post
|
commented_on_post
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ enum NotificationOrdering {
|
|||||||
enum NotificationReason {
|
enum NotificationReason {
|
||||||
mentioned_in_post
|
mentioned_in_post
|
||||||
mentioned_in_comment
|
mentioned_in_comment
|
||||||
comment_on_post
|
commented_on_post
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ describe('Notification', () => {
|
|||||||
describe('given a notification about a comment on a post', () => {
|
describe('given a notification about a comment on a post', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
propsData.notification = {
|
propsData.notification = {
|
||||||
reason: 'comment_on_post',
|
reason: 'commented_on_post',
|
||||||
from: {
|
from: {
|
||||||
__typename: 'Comment',
|
__typename: 'Comment',
|
||||||
id: 'comment-1',
|
id: 'comment-1',
|
||||||
@ -56,7 +56,7 @@ describe('Notification', () => {
|
|||||||
it('renders reason', () => {
|
it('renders reason', () => {
|
||||||
wrapper = Wrapper()
|
wrapper = Wrapper()
|
||||||
expect(wrapper.find('.reason-text-for-test').text()).toEqual(
|
expect(wrapper.find('.reason-text-for-test').text()).toEqual(
|
||||||
'notifications.menu.comment_on_post',
|
'notifications.menu.commented_on_post',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
it('renders title', () => {
|
it('renders title', () => {
|
||||||
|
|||||||
@ -134,7 +134,7 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"mentioned_in_post": "Hat dich in einem Beitrag erwähnt …",
|
"mentioned_in_post": "Hat dich in einem Beitrag erwähnt …",
|
||||||
"mentioned_in_comment": "Hat dich in einem Kommentar erwähnt …",
|
"mentioned_in_comment": "Hat dich in einem Kommentar erwähnt …",
|
||||||
"comment_on_post": "Hat deinen Beitrag kommentiert …"
|
"commented_on_post": "Hat deinen Beitrag kommentiert …"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"search": {
|
"search": {
|
||||||
|
|||||||
@ -134,7 +134,7 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"mentioned_in_post": "Mentioned you in a post …",
|
"mentioned_in_post": "Mentioned you in a post …",
|
||||||
"mentioned_in_comment": "Mentioned you in a comment …",
|
"mentioned_in_comment": "Mentioned you in a comment …",
|
||||||
"comment_on_post": "Commented on your post …"
|
"commented_on_post": "Commented on your post …"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"search": {
|
"search": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user