diff --git a/backend/src/middleware/notifications/notificationsMiddleware.js b/backend/src/middleware/notifications/notificationsMiddleware.js index 8d309d9c4..bf934fb77 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.js @@ -1,6 +1,8 @@ import extractMentionedUsers from './mentions/extractMentionedUsers' import { validateNotifyUsers } from '../validation/validationMiddleware' +const debug = require('debug')('backend:notificationsMiddleware') + const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => { const idsOfUsers = extractMentionedUsers(args.content) const post = await resolve(root, args, context, resolveInfo) @@ -36,6 +38,8 @@ const postAuthorOfComment = async (commentId, { context }) => { ) }) return postAuthorId.records.map(record => record.get('authorId')) + } catch (error) { + debug(error) } finally { session.close() } @@ -77,6 +81,8 @@ const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { await session.writeTransaction(transaction => { return transaction.run(mentionedCypher, { id, idsOfUsers, reason }) }) + } catch (error) { + debug(error) } finally { session.close() } @@ -100,6 +106,8 @@ const notifyUsersOfComment = async (label, commentId, postAuthorId, reason, cont { commentId, postAuthorId, reason }, ) }) + } catch (error) { + debug(error) } finally { session.close() } @@ -123,7 +131,7 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => { try { await session.writeTransaction(async transaction => { await transaction.run( - ` + /* Wolle` MATCH (resource {id: $resourceId})<-[:BELONGS_TO]-(:Report {id: $reportId})<-[:FILED]-(submitter:User {id: $submitterId}) WHERE resource: User OR resource: Post OR resource: Comment // Wolle MERGE (resource)-[notification:NOTIFIED {reason: $reason, reportId: $reportId}]->(submitter) @@ -131,6 +139,15 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => { ON CREATE SET notification.createdAt = toString(datetime()), notification.updatedAt = notification.createdAt ON MATCH SET notification.updatedAt = toString(datetime()) SET notification.read = FALSE + `,*/ + ` + MATCH (resource {id: $resourceId})<-[:BELONGS_TO]-(report:Report {id: $reportId})<-[:FILED]-(submitter:User {id: $submitterId}) + WHERE resource: User OR resource: Post OR resource: Comment + // Wolle MERGE (resource)-[notification:NOTIFIED {reason: $reason, reportId: $reportId}]->(submitter) + MERGE (report)-[notification:NOTIFIED {reason: $reason}]->(submitter) + ON CREATE SET notification.createdAt = toString(datetime()), notification.updatedAt = notification.createdAt + ON MATCH SET notification.updatedAt = toString(datetime()) + SET notification.read = FALSE `, { reportId, @@ -143,7 +160,9 @@ const notifyReportFiler = async (resolve, root, args, context, resolveInfo) => { ) console.log('success !!!') }) - } finally { + } catch (error) { + debug(error) + } finally { session.close() } } diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index 31369a8c7..27e2dc878 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -49,6 +49,7 @@ export default { const notificationsTransactionResponse = await transaction.run( ` MATCH (resource {deleted: false, disabled: false})-[notification:NOTIFIED]->(user:User {id:$id}) + WHERE (labels(resource)[0] in [Post, Comment] AND NOT resource.deleted AND NOT resource.disabled) OR labels(resource)[0] in [Report] ${whereClause} WITH user, notification, resource, [(resource)<-[:WROTE]-(author:User) | author {.*}] as authors, diff --git a/backend/src/schema/types/type/NOTIFIED.gql b/backend/src/schema/types/type/NOTIFIED.gql index 9926d39cc..15fa17c3f 100644 --- a/backend/src/schema/types/type/NOTIFIED.gql +++ b/backend/src/schema/types/type/NOTIFIED.gql @@ -8,7 +8,7 @@ type NOTIFIED { reason: NotificationReason } -union NotificationSource = Post | Comment +union NotificationSource = Post | Comment | Report enum NotificationOrdering { createdAt_asc