diff --git a/backend/src/schema/resolvers/notifications.js b/backend/src/schema/resolvers/notifications.js index 424bbe8af..9e6eeaf48 100644 --- a/backend/src/schema/resolvers/notifications.js +++ b/backend/src/schema/resolvers/notifications.js @@ -7,13 +7,18 @@ const cypherReturnNotificationsWithCollectedResourceData = ` [ labels(resource)[0] = "Post", ' MATCH (resource)<-[:WROTE]-(author:User) - RETURN resource {.*, __typename: labels(resource)[0], author: author} AS finalResource', + RETURN resource {.*, __typename: labels(resource)[0], author: properties(author)} AS finalResource', labels(resource)[0] = "Comment", ' MATCH (author:User)-[:WROTE]->(resource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(postAuthor:User) - RETURN resource {.*, __typename: labels(resource)[0], author: author, post: apoc.map.merge(properties(post), {__typename: labels(post)[0], author: properties(postAuthor)})} AS finalResource', + RETURN resource {.*, __typename: labels(resource)[0], author: properties(author), post: apoc.map.merge(properties(post), {__typename: labels(post)[0], author: properties(postAuthor)})} AS finalResource', labels(resource)[0] = "Report", ' MATCH (reportedResource)<-[:BELONGS_TO]-(resource)<-[filed:FILED]-(user) - RETURN {__typename: "FiledReport", reportId: resource.id, createdAt: filed.createdAt, reasonCategory: filed.reasonCategory, reasonDescription: filed.reasonDescription, resource: apoc.map.merge(properties(reportedResource), {__typename: labels(reportedResource)[0]})} AS finalResource' + + WITH user, filed, resource, reportedResource, + [(reportedResource)<-[:WROTE]-(author:User) | author {.*}] AS authors, + [(reportedResource)-[:COMMENTS]->(post:Post)<-[:WROTE]-(author:User) | post {.*, author: properties(author)} ] AS posts + + RETURN {__typename: "FiledReport", reportId: resource.id, createdAt: filed.createdAt, reasonCategory: filed.reasonCategory, reasonDescription: filed.reasonDescription, resource: apoc.map.merge(properties(reportedResource), {__typename: labels(reportedResource)[0], author: authors[0], post: posts[0]})} AS finalResource' ], '', { @@ -143,6 +148,16 @@ export default { const notifications = notificationsTransactionResponse.records.map((record) => record.get('notification'), ) + // Wolle notifications.forEach((element, index) => { + // console.log('notification #', index, ': ', element) + // if (element.from.__typename === 'FiledReport') { + // if (element.from.resource.__typename === 'Comment') { + // console.log('.from.resource.post.author: ', element.from.resource.post.author) + // // console.log('.from.post.author: ', element.from.post.author) + // } + // } + // }) + // Wolle console.log('notifications: ', notifications) return notifications }) try { @@ -187,7 +202,7 @@ export default { NOTIFIED: { id: async (parent) => { // serialize an ID to help the client update the cache - return `${parent.reason}/${parent.from.id}/${parent.to.id}` + return `${parent.reason}/${parent.from.id || parent.from.reportId}/${parent.to.id}` }, }, } diff --git a/backend/src/schema/resolvers/notifications.spec.js b/backend/src/schema/resolvers/notifications.spec.js index 06c488d97..609c361a6 100644 --- a/backend/src/schema/resolvers/notifications.spec.js +++ b/backend/src/schema/resolvers/notifications.spec.js @@ -226,9 +226,21 @@ describe('given some notifications', () => { __typename ... on Post { content + author { + id + } } ... on Comment { content + author { + id + } + post { + id + author { + id + } + } } ... on FiledReport { reportId @@ -244,10 +256,22 @@ describe('given some notifications', () => { id title content + author { + id + } } ... on Comment { id content + author { + id + } + post { + id + author { + id + } + } } } } @@ -255,6 +279,7 @@ describe('given some notifications', () => { } } ` + describe('unauthenticated', () => { it('throws authorization error', async () => { const { errors } = await query({ query: notificationQuery }) @@ -268,7 +293,7 @@ describe('given some notifications', () => { }) describe('no filters', () => { - it('returns all notifications of current user', async () => { + it.only('returns all notifications of current user', async () => { const expected = { data: { notifications: [ @@ -288,6 +313,9 @@ describe('given some notifications', () => { id: 'p4', title: 'Bad Post', content: 'I am bad content !!!', + author: { + id: 'author', + }, }, }, }, @@ -322,6 +350,15 @@ describe('given some notifications', () => { __typename: 'Comment', id: 'c4', content: 'I am harassing content in a harassing comment to a bad post !!!', + author: { + id: 'author', + }, + post: { + id: 'p4', + author: { + id: 'author', + }, + }, }, }, }, @@ -332,6 +369,9 @@ describe('given some notifications', () => { from: { __typename: 'Post', content: 'You have been mentioned in a post', + author: { + id: 'author', + }, }, }), expect.objectContaining({ @@ -341,6 +381,15 @@ describe('given some notifications', () => { from: { __typename: 'Comment', content: 'You have been mentioned in a comment', + author: { + id: 'author', + }, + post: { + id: 'p3', + author: { + id: 'author', + }, + }, }, }), expect.objectContaining({ @@ -350,6 +399,9 @@ describe('given some notifications', () => { from: { __typename: 'Post', content: 'Already seen post mention', + author: { + id: 'author', + }, }, }), expect.objectContaining({ @@ -359,6 +411,15 @@ describe('given some notifications', () => { from: { __typename: 'Comment', content: 'You have seen this comment mentioning already', + author: { + id: 'author', + }, + post: { + id: 'p3', + author: { + id: 'author', + }, + }, }, }), ], diff --git a/webapp/components/NotificationMenu/NotificationMenu.vue b/webapp/components/NotificationMenu/NotificationMenu.vue index ec991f0ef..df4a3d150 100644 --- a/webapp/components/NotificationMenu/NotificationMenu.vue +++ b/webapp/components/NotificationMenu/NotificationMenu.vue @@ -101,6 +101,18 @@ export default { (notification) => notification.id, ).sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)), } + // Wolle const unitedNotifications = unionBy( + // [newNotification], + // previousResult.notifications, + // (notification) => notification.id, + // ).sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)) + // console.log('unitedNotifications: ', unitedNotifications) + // unitedNotifications.forEach((element, index) => { + // console.log('unitedNotification #', index, ': ', element) + // }) + // return { + // notifications: unitedNotifications, + // } }, }, error(error) { diff --git a/webapp/components/utils/Notifications.js b/webapp/components/utils/Notifications.js index d6ddd9fde..f56674579 100644 --- a/webapp/components/utils/Notifications.js +++ b/webapp/components/utils/Notifications.js @@ -169,5 +169,6 @@ export const extractNotificationDataOfCurrentUser = (notification, currentUser) reasonTranslationExtention, linkTo: { name: linkName, params: linkParams, ...linkHashParam }, } + // Wolle console.log('data: ', data) return data } diff --git a/webapp/graphql/User.js b/webapp/graphql/User.js index bcf5ddf4b..54e21510d 100644 --- a/webapp/graphql/User.js +++ b/webapp/graphql/User.js @@ -64,7 +64,6 @@ export const minimisedUserQuery = () => { export const notificationQuery = (i18n) => { return gql` ${userFragment} - ${userCountsFragment} ${commentFragment} ${postFragment} @@ -103,7 +102,6 @@ export const notificationQuery = (i18n) => { __typename ... on User { ...user - ...userCounts } ... on Post { ...post @@ -154,6 +152,9 @@ export const markAsReadMutation = (i18n) => { } ... on Comment { ...comment + author { + ...user + } post { ...post author { @@ -162,7 +163,33 @@ export const markAsReadMutation = (i18n) => { } } ... on FiledReport { - id + reportId + reasonCategory + reasonDescription + resource { + __typename + ... on User { + ...user + } + ... on Post { + ...post + author { + ...user + } + } + ... on Comment { + ...comment + author { + ...user + } + post { + ...post + author { + ...user + } + } + } + } } } } @@ -203,6 +230,35 @@ export const notificationAdded = () => { } } } + ... on FiledReport { + reportId + reasonCategory + reasonDescription + resource { + __typename + ... on User { + ...user + } + ... on Post { + ...post + author { + ...user + } + } + ... on Comment { + ...comment + author { + ...user + } + post { + ...post + author { + ...user + } + } + } + } + } } } } diff --git a/webapp/yarn.lock b/webapp/yarn.lock index 4bf57907d..915f9107b 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -2284,19 +2284,6 @@ global "^4.3.2" util-deprecate "^1.0.2" -"@storybook/addons@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/addons/-/addons-5.3.17.tgz#8efab65904040b0b8578eedc9a5772dbcbf6fa83" - integrity sha512-zg6O1bmffRsHXJOWAnSD2O3tPnVMoD8Yfu+a5zBVXDiUP1E/TGzgjjjYBUUCU3yQg1Ted5rIn4o6ql/rZNNlgA== - dependencies: - "@storybook/api" "5.3.17" - "@storybook/channels" "5.3.17" - "@storybook/client-logger" "5.3.17" - "@storybook/core-events" "5.3.17" - core-js "^3.0.1" - global "^4.3.2" - util-deprecate "^1.0.2" - "@storybook/addons@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/addons/-/addons-5.3.18.tgz#5cbba6407ef7a802041c5ee831473bc3bed61f64" @@ -2333,32 +2320,6 @@ telejson "^3.0.2" util-deprecate "^1.0.2" -"@storybook/api@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/api/-/api-5.3.17.tgz#1c0dad3309afef6b0a5585cb59c65824fb4d2721" - integrity sha512-G40jtXFY10hQo6GSw5JeFYt41loD4+7s0uU18Rm6lfa/twOgp6vqqyDCWDvpRRxRBB5uDIKKHLt13X9gWe8tQQ== - dependencies: - "@reach/router" "^1.2.1" - "@storybook/channels" "5.3.17" - "@storybook/client-logger" "5.3.17" - "@storybook/core-events" "5.3.17" - "@storybook/csf" "0.0.1" - "@storybook/router" "5.3.17" - "@storybook/theming" "5.3.17" - "@types/reach__router" "^1.2.3" - core-js "^3.0.1" - fast-deep-equal "^2.0.1" - global "^4.3.2" - lodash "^4.17.15" - memoizerific "^1.11.3" - prop-types "^15.6.2" - react "^16.8.3" - semver "^6.0.0" - shallow-equal "^1.1.0" - store2 "^2.7.1" - telejson "^3.2.0" - util-deprecate "^1.0.2" - "@storybook/api@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/api/-/api-5.3.18.tgz#95582ab90d947065e0e34ed603650a3630dcbd16" @@ -2385,17 +2346,6 @@ telejson "^3.2.0" util-deprecate "^1.0.2" -"@storybook/channel-postmessage@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/channel-postmessage/-/channel-postmessage-5.3.17.tgz#807b6316cd0e52d9f27363d5092ad1cd896b694c" - integrity sha512-1aSQNeO2+roPRgMFjW3AWTO3uS93lbCMUTYCBdi20md4bQ9SutJy33rynCQcWuMj1prCQ2Ekz4BGhdcIQVKlzg== - dependencies: - "@storybook/channels" "5.3.17" - "@storybook/client-logger" "5.3.17" - core-js "^3.0.1" - global "^4.3.2" - telejson "^3.2.0" - "@storybook/channel-postmessage@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/channel-postmessage/-/channel-postmessage-5.3.18.tgz#93d46740b5cc9b36ddd073f0715b54c4959953bf" @@ -2414,13 +2364,6 @@ dependencies: core-js "^3.0.1" -"@storybook/channels@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/channels/-/channels-5.3.17.tgz#74eccb10c2395499da6a290bcd0272d6d6c7c5b2" - integrity sha512-5hlBRbyk+YxC4KgecYG8wWwB2v1BzRJXhSlemFDOQk9wx37gVpne+rBydEtNFO4InmaZf6tKbBcpH0wBFLdWYA== - dependencies: - core-js "^3.0.1" - "@storybook/channels@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/channels/-/channels-5.3.18.tgz#490c9eaa8292b0571c0f665052b12addf7c35f21" @@ -2428,29 +2371,6 @@ dependencies: core-js "^3.0.1" -"@storybook/client-api@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/client-api/-/client-api-5.3.17.tgz#fc1d247caf267ebcc6ddf957fca7e02ae752d99e" - integrity sha512-oe55FPTGVL2k+j45eCN3oE7ePkE4VpgUQ/dhJbjU0R2L+HyRyBhd0wnMYj1f5E8uVNbtjFYAtbjjgcf1R1imeg== - dependencies: - "@storybook/addons" "5.3.17" - "@storybook/channel-postmessage" "5.3.17" - "@storybook/channels" "5.3.17" - "@storybook/client-logger" "5.3.17" - "@storybook/core-events" "5.3.17" - "@storybook/csf" "0.0.1" - "@types/webpack-env" "^1.15.0" - core-js "^3.0.1" - eventemitter3 "^4.0.0" - global "^4.3.2" - is-plain-object "^3.0.0" - lodash "^4.17.15" - memoizerific "^1.11.3" - qs "^6.6.0" - stable "^0.1.8" - ts-dedent "^1.1.0" - util-deprecate "^1.0.2" - "@storybook/client-api@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/client-api/-/client-api-5.3.18.tgz#e71041796f95888de0e4524734418e6b120b060a" @@ -2481,13 +2401,6 @@ dependencies: core-js "^3.0.1" -"@storybook/client-logger@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/client-logger/-/client-logger-5.3.17.tgz#bf9c7ef52da75a5c1f2c5d74724442224deea6e4" - integrity sha512-GYYvVGIOs+fq11LXXy7x2sr3hhC9LMI1jtIckjKV1dsY9MJ5g22M+Wl5Iw4nf6VMWsqcN9LSlYE+u/H+Q2uCHw== - dependencies: - core-js "^3.0.1" - "@storybook/client-logger@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/client-logger/-/client-logger-5.3.18.tgz#27c9d09d788965db0164be6e168bc3f03adbf88f" @@ -2520,33 +2433,6 @@ react-textarea-autosize "^7.1.0" simplebar-react "^1.0.0-alpha.6" -"@storybook/components@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/components/-/components-5.3.17.tgz#287430fc9c5f59b1d3590b50b3c7688355b22639" - integrity sha512-M5oqbzcqFX4VDNI8siT3phT7rmFwChQ/xPwX9ygByBsZCoNuLMzafavfTOhZvxCPiliFbBxmxtK/ibCsSzuKZg== - dependencies: - "@storybook/client-logger" "5.3.17" - "@storybook/theming" "5.3.17" - "@types/react-syntax-highlighter" "11.0.4" - "@types/react-textarea-autosize" "^4.3.3" - core-js "^3.0.1" - global "^4.3.2" - lodash "^4.17.15" - markdown-to-jsx "^6.9.1" - memoizerific "^1.11.3" - polished "^3.3.1" - popper.js "^1.14.7" - prop-types "^15.7.2" - react "^16.8.3" - react-dom "^16.8.3" - react-focus-lock "^2.1.0" - react-helmet-async "^1.0.2" - react-popper-tooltip "^2.8.3" - react-syntax-highlighter "^11.0.2" - react-textarea-autosize "^7.1.0" - simplebar-react "^1.0.0-alpha.6" - ts-dedent "^1.1.0" - "@storybook/components@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/components/-/components-5.3.18.tgz#528f6ab1660981e948993a04b407a6fad7751589" @@ -2581,13 +2467,6 @@ dependencies: core-js "^3.0.1" -"@storybook/core-events@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/core-events/-/core-events-5.3.17.tgz#698ce0a36c29fe8fa04608f56ccca53aa1d31638" - integrity sha512-DOeX9fpeGW4o9Gocxa4VW9wAlAyfIVNDTzq0wVvvMBthTTo9u58NmndglEMDgDa2Cq6iAIPh7vz2bRJCNexzLw== - dependencies: - core-js "^3.0.1" - "@storybook/core-events@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/core-events/-/core-events-5.3.18.tgz#e5d335f8a2c7dd46502b8f505006f1e111b46d49" @@ -2706,21 +2585,6 @@ memoizerific "^1.11.3" qs "^6.6.0" -"@storybook/router@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/router/-/router-5.3.17.tgz#4db96b45f39b25a3f7a4e2899c36e7e9e4ba6108" - integrity sha512-ANsiehGRTVSremgTW0Vt47dQ4JA86a4/w/4G6QqHU8Cm4jO3cw/wAcCxlzfcgCXOUiq+SuyPTU43+0O5uBx33g== - dependencies: - "@reach/router" "^1.2.1" - "@storybook/csf" "0.0.1" - "@types/reach__router" "^1.2.3" - core-js "^3.0.1" - global "^4.3.2" - lodash "^4.17.15" - memoizerific "^1.11.3" - qs "^6.6.0" - util-deprecate "^1.0.2" - "@storybook/router@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/router/-/router-5.3.18.tgz#8ab22f1f2f7f957e78baf992030707a62289076e" @@ -2754,24 +2618,6 @@ prop-types "^15.7.2" resolve-from "^5.0.0" -"@storybook/theming@5.3.17": - version "5.3.17" - resolved "https://registry.yarnpkg.com/@storybook/theming/-/theming-5.3.17.tgz#cf6278c4857229c7167faf04d5b2206bc5ee04e1" - integrity sha512-4JeOZnDDHtb4LOt5sXe/s1Jhbb2UPsr8zL9NWmKJmTsgnyTvBipNHOmFYDUsIacB5K4GXSqm+cZ7Z4AkUgWCDw== - dependencies: - "@emotion/core" "^10.0.20" - "@emotion/styled" "^10.0.17" - "@storybook/client-logger" "5.3.17" - core-js "^3.0.1" - deep-object-diff "^1.1.0" - emotion-theming "^10.0.19" - global "^4.3.2" - memoizerific "^1.11.3" - polished "^3.3.1" - prop-types "^15.7.2" - resolve-from "^5.0.0" - ts-dedent "^1.1.0" - "@storybook/theming@5.3.18": version "5.3.18" resolved "https://registry.yarnpkg.com/@storybook/theming/-/theming-5.3.18.tgz#35e78de79d9cf8f1248af0dd1c7fa60555761312"