diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 60602d792..925f8d459 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -106,6 +106,10 @@ describe('notifications', () => { reasonDescription reportedResource { __typename + ...on User { + id + name + } ... on Post { id content @@ -114,10 +118,6 @@ describe('notifications', () => { id content } - ... on User { - id - name - } } } } diff --git a/backend/src/schema/resolvers/notifications.spec.js b/backend/src/schema/resolvers/notifications.spec.js index 8e06c37aa..833927da5 100644 --- a/backend/src/schema/resolvers/notifications.spec.js +++ b/backend/src/schema/resolvers/notifications.spec.js @@ -199,6 +199,10 @@ describe('given some notifications', () => { reasonDescription reportedResource { __typename + ...on User { + id + name + } ...on Post { id title @@ -208,10 +212,6 @@ describe('given some notifications', () => { id content } - ...on User { - id - name - } } } } diff --git a/backend/src/seed/seed-db.js b/backend/src/seed/seed-db.js index e219d287e..2e9f9215d 100644 --- a/backend/src/seed/seed-db.js +++ b/backend/src/seed/seed-db.js @@ -711,7 +711,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] }), reportAgainstDewey.relateTo(dewey, 'belongsTo'), ]) - // notify first reports + // notify first report filers await Promise.all([ reportAgainstDagobert.relateTo(jennyRostock, 'notified', { read: false, @@ -754,7 +754,7 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl'] }), reportAgainstTrollingComment.relateTo(trollingComment, 'belongsTo'), ]) - // notify second reports + // notify second report filers await Promise.all([ reportAgainstDagobert.relateTo(louie, 'notified', { read: false, diff --git a/webapp/components/Notification/Notification.vue b/webapp/components/Notification/Notification.vue index 446c5321a..dadee672e 100644 --- a/webapp/components/Notification/Notification.vue +++ b/webapp/components/Notification/Notification.vue @@ -55,15 +55,49 @@ export default { isComment() { return this.from.__typename === 'Comment' }, - params() { - const post = this.isComment ? this.from.post : this.from - return { - id: post.id, - slug: post.slug, + sourceData() { + let user = null + let post = null + let comment = null + let report = null + if (this.from.__typename === 'Post') { + post = this.from + } else if (this.from.__typename === 'Comment') { + comment = this.from + post = this.from.post + } else if (this.from.__typename === 'Report') { + report = { + reasonCategory: this.from.filed.reasonCategory, + reasonDescription: this.from.filed.reasonDescription, + } + if (this.from.filed.reportedResource.__typename === 'User') { + user = this.from.filed.reportedResource + } else if (this.from.filed.reportedResource.__typename === 'Post') { + post = this.from.filed.reportedResource + } else if (this.from.filed.reportedResource.__typename === 'Comment') { + comment = this.from.filed.reportedResource + post = this.from.filed.reportedResource.post + } } + return { user, post, comment, report } + }, + params() { + // Wolle const post = this.isComment ? this.from.post : this.from + return this.sourceData.user + ? { + id: this.sourceData.user.id, + slug: this.sourceData.user.slug, + } + : this.sourceData.post + ? { + id: this.sourceData.post.id, + slug: this.sourceData.post.slug, + } + : {} }, hashParam() { - return this.isComment ? { hash: `#commentId-${this.from.id}` } : {} + // Wolle return this.isComment ? { hash: `#commentId-${this.from.id}` } : {} + return this.sourceData.comment ? { hash: `#commentId-${this.sourceData.comment.id}` } : {} }, }, } diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index 4ed832ad3..404fea8cb 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -89,6 +89,36 @@ export const notificationQuery = i18n => { } } } + ... on Report { + filed { + reasonCategory + reasonDescription + reportedResource { + __typename + ... on User { + ...user + } + ... on Post { + ...post + author { + ...user + } + } + ... on Comment { + ...comment + author { + ...user + } + post { + ...post + author { + ...user + } + } + } + } + } + } } } }