mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
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:
parent
5d5574b1b5
commit
c7ee90e980
@ -102,7 +102,6 @@ export default shield(
|
||||
blockedUsers: isAuthenticated,
|
||||
notifications: isAuthenticated,
|
||||
Donations: isAuthenticated,
|
||||
blockedByPostAuthor: isAuthenticated,
|
||||
},
|
||||
Mutation: {
|
||||
'*': deny,
|
||||
|
||||
@ -48,29 +48,6 @@ export default {
|
||||
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) => {
|
||||
const { email } = args
|
||||
if (email) {
|
||||
|
||||
@ -71,7 +71,7 @@ type User {
|
||||
|
||||
isBlocked: Boolean! @cypher(
|
||||
statement: """
|
||||
MATCH (this)<-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId})
|
||||
MATCH (this)-[:BLOCKED]-(user:User {id: $cypherParams.currentUserId})
|
||||
RETURN COUNT(user) >= 1
|
||||
"""
|
||||
)
|
||||
@ -160,7 +160,6 @@ type Query {
|
||||
orderBy: [_UserOrdering]
|
||||
filter: _UserFilter
|
||||
): [User]
|
||||
blockedByPostAuthor(postAuthorId: ID!): Boolean!
|
||||
blockedUsers: [User]
|
||||
currentUser: User
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ export default i18n => {
|
||||
...user
|
||||
...userCounts
|
||||
...locationAndBadges
|
||||
isBlocked
|
||||
}
|
||||
comments(orderBy: createdAt_asc) {
|
||||
...comment
|
||||
|
||||
@ -216,10 +216,3 @@ export const checkSlugAvailableQuery = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
export const blockedByPostAuthor = () => {
|
||||
return gql`
|
||||
query($postAuthorId: ID!) {
|
||||
blockedByPostAuthor(postAuthorId: $postAuthorId)
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@
|
||||
/>
|
||||
<ds-space margin-bottom="large" />
|
||||
<comment-form
|
||||
v-if="showNewCommentForm && !this.blocked"
|
||||
v-if="showNewCommentForm && !post.author.isBlocked"
|
||||
:post="post"
|
||||
@createComment="createComment"
|
||||
/>
|
||||
@ -120,7 +120,6 @@ import { postMenuModalsData, deletePostMutation } from '~/components/utils/PostH
|
||||
import PostQuery from '~/graphql/PostQuery'
|
||||
import HcEmotions from '~/components/Emotions/Emotions'
|
||||
import PostMutations from '~/graphql/PostMutations'
|
||||
import { blockedByPostAuthor } from '~/graphql/User'
|
||||
|
||||
export default {
|
||||
name: 'PostSlug',
|
||||
@ -231,20 +230,6 @@ export default {
|
||||
},
|
||||
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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user