mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
feat: add mutation for new functionality (mark-all-as-read)
- Add mutation for markAllAsRead (notifications) - Add method to the schema that returns a list of all notifications - Add permissions rules to invoke this method (isAuthenticated) See #2660
This commit is contained in:
parent
21a9094a25
commit
0bffede021
@ -143,6 +143,7 @@ export default shield(
|
||||
blockUser: isAuthenticated,
|
||||
unblockUser: isAuthenticated,
|
||||
markAsRead: isAuthenticated,
|
||||
markAllAsRead: isAuthenticated,
|
||||
AddEmailAddress: isAuthenticated,
|
||||
VerifyEmailAddress: isAuthenticated,
|
||||
pinPost: isAdmin,
|
||||
|
||||
@ -99,6 +99,35 @@ export default {
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
markAllAsRead: async (parent, args, context, resolveInfo) => {
|
||||
const { user: currentUser } = context
|
||||
const session = context.driver.session()
|
||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||
const markAllNotificationAsReadTransactionResponse = await transaction.run(
|
||||
`
|
||||
MATCH (resource {deleted: false, disabled: false})-[notification:NOTIFIED {read: FALSE}]->(user:User {id:$id})
|
||||
SET notification.read = TRUE
|
||||
WITH user, notification, resource,
|
||||
[(resource)<-[:WROTE]-(author:User) | author {.*}] AS authors,
|
||||
[(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post{.*, author: properties(author)} ] AS posts
|
||||
WITH resource, user, notification, authors, posts,
|
||||
resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0]} AS finalResource
|
||||
RETURN notification {.*, from: finalResource, to: properties(user)}
|
||||
`,
|
||||
{ id: currentUser.id },
|
||||
)
|
||||
log(markAllNotificationAsReadTransactionResponse)
|
||||
return markAllNotificationAsReadTransactionResponse.records.map((record) =>
|
||||
record.get('notification'),
|
||||
)
|
||||
})
|
||||
try {
|
||||
const notifications = await writeTxResultPromise
|
||||
return notifications
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
},
|
||||
NOTIFIED: {
|
||||
id: async (parent) => {
|
||||
|
||||
@ -29,6 +29,7 @@ type Query {
|
||||
|
||||
type Mutation {
|
||||
markAsRead(id: ID!): NOTIFIED
|
||||
markAllAsRead: [NOTIFIED]
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
|
||||
@ -136,6 +136,42 @@ export const markAsReadMutation = (i18n) => {
|
||||
`
|
||||
}
|
||||
|
||||
export const markAllAsReadMutation = (i18n) => {
|
||||
return gql`
|
||||
${userFragment}
|
||||
${commentFragment}
|
||||
${postFragment}
|
||||
|
||||
mutation {
|
||||
markAllAsRead {
|
||||
id
|
||||
read
|
||||
reason
|
||||
createdAt
|
||||
updatedAt
|
||||
from {
|
||||
__typename
|
||||
... on Post {
|
||||
...post
|
||||
author {
|
||||
...user
|
||||
}
|
||||
}
|
||||
... on Comment {
|
||||
...comment
|
||||
post {
|
||||
...post
|
||||
author {
|
||||
...user
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
export const notificationAdded = () => {
|
||||
return gql`
|
||||
${userFragment}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user