Skip to content

Commit

Permalink
Rename blacklist/whitelist to mute/unmute
Browse files Browse the repository at this point in the history
- Follow @roschaefer suggestion in issue
- This can be reverted if we decide otherwise
  • Loading branch information
mattwr18 committed Jan 8, 2020
1 parent cd7f0e2 commit ba3e9e1
Show file tree
Hide file tree
Showing 29 changed files with 274 additions and 274 deletions.
6 changes: 3 additions & 3 deletions backend/src/middleware/permissionsMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default shield(
Badge: allow,
PostsEmotionsCountByEmotion: allow,
PostsEmotionsByCurrentUser: isAuthenticated,
blacklistedUsers: isAuthenticated,
mutedUsers: isAuthenticated,
notifications: isAuthenticated,
Donations: isAuthenticated,
},
Expand Down Expand Up @@ -135,8 +135,8 @@ export default shield(
resetPassword: allow,
AddPostEmotions: isAuthenticated,
RemovePostEmotions: isAuthenticated,
blacklistUserContent: isAuthenticated,
whitelistUserContent: isAuthenticated,
muteUser: isAuthenticated,
unmuteUser: isAuthenticated,
markAsRead: isAuthenticated,
AddEmailAddress: isAuthenticated,
VerifyEmailAddress: isAuthenticated,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ module.exports = {
target: 'User',
direction: 'out',
},
blacklisted: {
muted: {
type: 'relationship',
relationship: 'BLACKLISTED',
relationship: 'MUTED',
target: 'User',
direction: 'out',
},
Expand Down
18 changes: 9 additions & 9 deletions backend/src/schema/resolvers/posts.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import uuid from 'uuid/v4'
import { neo4jgraphql } from 'neo4j-graphql-js'
import fileUpload from './fileUpload'
import { getBlacklistedUsers } from './users.js'
import { getMutedUsers } from './users.js'
import { mergeWith, isArray, isEmpty } from 'lodash'
import { UserInputError } from 'apollo-server'
import Resolver from './helpers/Resolver'

const filterForBlacklistedUsers = async (params, context) => {
const filterForMutedUsers = async (params, context) => {
if (!context.user) return params
const [blacklistedUsers] = await Promise.all([getBlacklistedUsers(context)])
const blacklistedUsersIds = [...blacklistedUsers.map(user => user.id)]
if (!blacklistedUsersIds.length) return params
const [mutedUsers] = await Promise.all([getMutedUsers(context)])
const mutedUsersIds = [...mutedUsers.map(user => user.id)]
if (!mutedUsersIds.length) return params

params.filter = mergeWith(
params.filter,
{
author_not: { id_in: blacklistedUsersIds },
author_not: { id_in: mutedUsersIds },
},
(objValue, srcValue) => {
if (isArray(objValue)) {
Expand All @@ -39,16 +39,16 @@ const maintainPinnedPosts = params => {
export default {
Query: {
Post: async (object, params, context, resolveInfo) => {
params = await filterForBlacklistedUsers(params, context)
params = await filterForMutedUsers(params, context)
params = await maintainPinnedPosts(params)
return neo4jgraphql(object, params, context, resolveInfo)
},
findPosts: async (object, params, context, resolveInfo) => {
params = await filterForBlacklistedUsers(params, context)
params = await filterForMutedUsers(params, context)
return neo4jgraphql(object, params, context, resolveInfo)
},
profilePagePosts: async (object, params, context, resolveInfo) => {
params = await filterForBlacklistedUsers(params, context)
params = await filterForMutedUsers(params, context)
return neo4jgraphql(object, params, context, resolveInfo)
},
PostsEmotionsCountByEmotion: async (object, params, context, resolveInfo) => {
Expand Down
40 changes: 20 additions & 20 deletions backend/src/schema/resolvers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import createOrUpdateLocations from './users/location'

const neode = getNeode()

export const getBlacklistedUsers = async context => {
export const getMutedUsers = async context => {
const { neode } = context
const userModel = neode.model('User')
let blacklistedUsers = neode
let mutedUsers = neode
.query()
.match('user', userModel)
.where('user.id', context.user.id)
.relationship(userModel.relationships().get('blacklisted'))
.to('blacklisted', userModel)
.return('blacklisted')
blacklistedUsers = await blacklistedUsers.execute()
blacklistedUsers = blacklistedUsers.records.map(r => r.get('blacklisted').properties)
return blacklistedUsers
.relationship(userModel.relationships().get('muted'))
.to('muted', userModel)
.return('muted')
mutedUsers = await mutedUsers.execute()
mutedUsers = mutedUsers.records.map(r => r.get('muted').properties)
return mutedUsers
}

export default {
Query: {
blacklistedUsers: async (object, args, context, resolveInfo) => {
mutedUsers: async (object, args, context, resolveInfo) => {
try {
return getBlacklistedUsers(context)
return getMutedUsers(context)
} catch (e) {
throw new UserInputError(e.message)
}
Expand Down Expand Up @@ -56,7 +56,7 @@ export default {
},
},
Mutation: {
blacklistUserContent: async (_parent, params, context, _resolveInfo) => {
muteUser: async (_parent, params, context, _resolveInfo) => {
const { user: currentUser } = context
if (currentUser.id === params.id) return null
await neode.cypher(
Expand All @@ -66,25 +66,25 @@ export default {
`,
{ currentUser, params },
)
const [user, blacklistedUser] = await Promise.all([
const [user, mutedUser] = await Promise.all([
neode.find('User', currentUser.id),
neode.find('User', params.id),
])
await user.relateTo(blacklistedUser, 'blacklisted')
return blacklistedUser.toJson()
await user.relateTo(mutedUser, 'muted')
return mutedUser.toJson()
},
whitelistUserContent: async (_parent, params, context, _resolveInfo) => {
unmuteUser: async (_parent, params, context, _resolveInfo) => {
const { user: currentUser } = context
if (currentUser.id === params.id) return null
await neode.cypher(
`
MATCH(u:User {id: $currentUser.id})-[previousRelationship:BLACKLISTED]->(b:User {id: $params.id})
MATCH(u:User {id: $currentUser.id})-[previousRelationship:MUTED]->(b:User {id: $params.id})
DELETE previousRelationship
`,
{ currentUser, params },
)
const whitelistedUser = await neode.find('User', params.id)
return whitelistedUser.toJson()
const unmutedUser = await neode.find('User', params.id)
return unmutedUser.toJson()
},
block: async (object, args, context, resolveInfo) => {
const { user: currentUser } = context
Expand Down Expand Up @@ -231,8 +231,8 @@ export default {
'MATCH (this)<-[:FOLLOWS]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1',
isBlocked:
'MATCH (this)<-[:BLOCKED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1',
isBlacklisted:
'MATCH (this)<-[:BLACKLISTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1',
isMuted:
'MATCH (this)<-[:MUTED]-(u:User {id: $cypherParams.currentUserId}) RETURN COUNT(u) >= 1',
},
count: {
contributionsCount:
Expand Down
Loading

0 comments on commit ba3e9e1

Please sign in to comment.