Follow @roschaefer PR suggestions

- As blocking is now reciprocal, we do not need another query, we can
  use neo4j-graphql-js magic to query for a BLOCKED relationship between
the postAuthor and the currentUser
This commit is contained in:
mattwr18 2020-01-21 18:50:46 +01:00
parent 5d5574b1b5
commit c7ee90e980
6 changed files with 3 additions and 49 deletions

View File

@ -102,7 +102,6 @@ export default shield(
blockedUsers: isAuthenticated, blockedUsers: isAuthenticated,
notifications: isAuthenticated, notifications: isAuthenticated,
Donations: isAuthenticated, Donations: isAuthenticated,
blockedByPostAuthor: isAuthenticated,
}, },
Mutation: { Mutation: {
'*': deny, '*': deny,

View File

@ -48,29 +48,6 @@ export default {
throw new UserInputError(e.message) throw new UserInputError(e.message)
} }
}, },
blockedByPostAuthor: async (_parent, params, context, _resolveInfo) => {
const { postAuthorId } = params
const { user, driver } = context
const session = driver.session()
const readTxResultPromise = session.readTransaction(async transaction => {
const blockedByPostAuthorTransactionResponse = await transaction.run(
`
MATCH (currentUser:User {id: $currentUserId})<-[relationship:BLOCKED]-(postAuthor:User {id: $postAuthorId})
RETURN COUNT(relationship) >= 1 as blockedByPostAuthor
`,
{ postAuthorId, currentUserId: user.id },
)
return blockedByPostAuthorTransactionResponse.records.map(record =>
record.get('blockedByPostAuthor'),
)
})
try {
const [blockedByPostAuthor] = await readTxResultPromise
return blockedByPostAuthor
} finally {
session.close()
}
},
User: async (object, args, context, resolveInfo) => { User: async (object, args, context, resolveInfo) => {
const { email } = args const { email } = args
if (email) { if (email) {

View File

@ -71,7 +71,7 @@ type User {
isBlocked: Boolean! @cypher( isBlocked: Boolean! @cypher(
statement: """ statement: """
MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId}) MATCH (this)-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId})
RETURN COUNT(user) >= 1 RETURN COUNT(user) >= 1
""" """
) )
@ -160,7 +160,6 @@ type Query {
orderBy: [_UserOrdering] orderBy: [_UserOrdering]
filter: _UserFilter filter: _UserFilter
): [User] ): [User]
blockedByPostAuthor(postAuthorId: ID!): Boolean!
blockedUsers: [User] blockedUsers: [User]
currentUser: User currentUser: User
} }

View File

@ -29,6 +29,7 @@ export default i18n => {
...user ...user
...userCounts ...userCounts
...locationAndBadges ...locationAndBadges
isBlocked
} }
comments(orderBy: createdAt_asc) { comments(orderBy: createdAt_asc) {
...comment ...comment

View File

@ -216,10 +216,3 @@ export const checkSlugAvailableQuery = gql`
} }
} }
` `
export const blockedByPostAuthor = () => {
return gql`
query($postAuthorId: ID!) {
blockedByPostAuthor(postAuthorId: $postAuthorId)
}
`
}

View File

@ -90,7 +90,7 @@
/> />
<ds-space margin-bottom="large" /> <ds-space margin-bottom="large" />
<comment-form <comment-form
v-if="showNewCommentForm && !this.blocked" v-if="showNewCommentForm && !post.author.isBlocked"
:post="post" :post="post"
@createComment="createComment" @createComment="createComment"
/> />
@ -120,7 +120,6 @@ import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostH
import PostQuery from '~/graphql/PostQuery' import PostQuery from '~/graphql/PostQuery'
import HcEmotions from '~/components/Emotions/Emotions' import HcEmotions from '~/components/Emotions/Emotions'
import PostMutations from '~/graphql/PostMutations' import PostMutations from '~/graphql/PostMutations'
import { blockedByPostAuthor } from '~/graphql/User'
export default { export default {
name: 'PostSlug', name: 'PostSlug',
@ -231,20 +230,6 @@ export default {
}, },
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
}, },
blockedByPostAuthor: {
query() {
return blockedByPostAuthor()
},
variables() {
return {
postAuthorId: this.postAuthor ? this.postAuthor.id : this.$store.getters['auth/user'].id,
}
},
update({ blockedByPostAuthor }) {
this.blocked = blockedByPostAuthor
},
fetchPolicy: 'cache-and-network',
},
}, },
} }
</script> </script>