diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index 27e2dc878..d73ecdd3a 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -24,10 +24,10 @@ export default { switch (args.read) { case true: - whereClause = 'WHERE notification.read = TRUE' + whereClause = 'AND notification.read = TRUE' break case false: - whereClause = 'WHERE notification.read = FALSE' + whereClause = 'AND notification.read = FALSE' break default: whereClause = '' @@ -48,17 +48,18 @@ export default { const readTxResultPromise = session.readTransaction(async transaction => { 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, - [(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)} - ${orderByClause} - ${offset} ${limit} + MATCH (resource)-[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, + [(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author)} ] as posts, + [(reportedResource)<-[:BELONGS_TO]-(resource)<-[file:FILED]-(user) | file {.*, reportedResource: apoc.map.merge(properties(reportedResource), {__typename: labels(reportedResource)[0]})} ] as files + WITH resource, user, notification, authors, posts, files, + resource {.*, __typename: labels(resource)[0], author: authors[0], post: posts[0], filed: files} as finalResource + RETURN notification {.*, from: finalResource, to: properties(user)} + ${orderByClause} + ${offset} ${limit} `, { id: currentUser.id }, ) diff --git a/backend/src/schema/types/type/FILED.gql b/backend/src/schema/types/type/FILED.gql index cdce62116..7b3c78056 100644 --- a/backend/src/schema/types/type/FILED.gql +++ b/backend/src/schema/types/type/FILED.gql @@ -3,6 +3,7 @@ type FILED { reasonCategory: ReasonCategory! reasonDescription: String! submitter: User + reportedResource: ReportedResource } # this list equals the strings of an array in file "webapp/constants/modals.js" diff --git a/backend/src/schema/types/type/NOTIFIED.gql b/backend/src/schema/types/type/NOTIFIED.gql index 15fa17c3f..beb4161df 100644 --- a/backend/src/schema/types/type/NOTIFIED.gql +++ b/backend/src/schema/types/type/NOTIFIED.gql @@ -1,11 +1,11 @@ type NOTIFIED { id: ID! - from: NotificationSource - to: User createdAt: String! updatedAt: String! - read: Boolean - reason: NotificationReason + read: Boolean! + reason: NotificationReason! + from: NotificationSource! + to: User! } union NotificationSource = Post | Comment | Report diff --git a/webapp/plugins/apollo-config/fragmentTypes.json b/webapp/plugins/apollo-config/fragmentTypes.json index 777189693..c2ad4a837 100644 --- a/webapp/plugins/apollo-config/fragmentTypes.json +++ b/webapp/plugins/apollo-config/fragmentTypes.json @@ -5,6 +5,24 @@ "kind": "UNION", "name": "NotificationSource", "possibleTypes": [ + { + "name": "Post" + }, + { + "name": "Comment" + }, + { + "name": "Report" + } + ] + }, + { + "kind": "UNION", + "name": "ReportedResource", + "possibleTypes": [ + { + "name": "User" + }, { "name": "Post" },