mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement block/unbock UI
This commit is contained in:
parent
824b2a5561
commit
7f509b3201
@ -15,10 +15,12 @@ export default function Resolver(type, options = {}) {
|
|||||||
const {
|
const {
|
||||||
idAttribute = 'id',
|
idAttribute = 'id',
|
||||||
undefinedToNull = [],
|
undefinedToNull = [],
|
||||||
|
boolean = {},
|
||||||
count = {},
|
count = {},
|
||||||
hasOne = {},
|
hasOne = {},
|
||||||
hasMany = {},
|
hasMany = {},
|
||||||
} = options
|
} = options
|
||||||
|
|
||||||
const _hasResolver = (resolvers, { key, connection }, { returnType }) => {
|
const _hasResolver = (resolvers, { key, connection }, { returnType }) => {
|
||||||
return async (parent, params, context, resolveInfo) => {
|
return async (parent, params, context, resolveInfo) => {
|
||||||
if (typeof parent[key] !== 'undefined') return parent[key]
|
if (typeof parent[key] !== 'undefined') return parent[key]
|
||||||
@ -31,6 +33,26 @@ export default function Resolver(type, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const booleanResolver = obj => {
|
||||||
|
const resolvers = {}
|
||||||
|
for (const [key, condition] of Object.entries(obj)) {
|
||||||
|
resolvers[key] = async (parent, params, { cypherParams }, resolveInfo) => {
|
||||||
|
if (typeof parent[key] !== 'undefined') return parent[key]
|
||||||
|
const result = await instance.cypher(
|
||||||
|
`
|
||||||
|
${condition.replace('this', 'this {id: $parent.id}')} as ${key}`,
|
||||||
|
{
|
||||||
|
parent,
|
||||||
|
cypherParams,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
const [record] = result.records
|
||||||
|
return record.get(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resolvers
|
||||||
|
}
|
||||||
|
|
||||||
const countResolver = obj => {
|
const countResolver = obj => {
|
||||||
const resolvers = {}
|
const resolvers = {}
|
||||||
for (const [key, connection] of Object.entries(obj)) {
|
for (const [key, connection] of Object.entries(obj)) {
|
||||||
@ -67,6 +89,7 @@ export default function Resolver(type, options = {}) {
|
|||||||
}
|
}
|
||||||
const result = {
|
const result = {
|
||||||
...undefinedToNullResolver(undefinedToNull),
|
...undefinedToNullResolver(undefinedToNull),
|
||||||
|
...booleanResolver(boolean),
|
||||||
...countResolver(count),
|
...countResolver(count),
|
||||||
...hasOneResolver(hasOne),
|
...hasOneResolver(hasOne),
|
||||||
...hasManyResolver(hasMany),
|
...hasManyResolver(hasMany),
|
||||||
|
|||||||
@ -110,18 +110,6 @@ export default {
|
|||||||
const [{ email }] = result.records.map(r => r.get('e').properties)
|
const [{ email }] = result.records.map(r => r.get('e').properties)
|
||||||
return email
|
return email
|
||||||
},
|
},
|
||||||
isBlocked: async (parent, params, context, resolveInfo) => {
|
|
||||||
if (typeof parent.isBlocked !== 'undefined') return parent.isBlocked
|
|
||||||
const result = await instance.cypher(
|
|
||||||
`
|
|
||||||
MATCH (u:User { id: $currentUser.id })-[:BLOCKED]->(b:User {id: $parent.id})
|
|
||||||
RETURN COUNT(u) >= 1 as isBlocked
|
|
||||||
`,
|
|
||||||
{ parent, currentUser: context.user },
|
|
||||||
)
|
|
||||||
const [record] = result.records
|
|
||||||
return record.get('isBlocked')
|
|
||||||
},
|
|
||||||
...Resolver('User', {
|
...Resolver('User', {
|
||||||
undefinedToNull: [
|
undefinedToNull: [
|
||||||
'actorId',
|
'actorId',
|
||||||
@ -132,6 +120,12 @@ export default {
|
|||||||
'locationName',
|
'locationName',
|
||||||
'about',
|
'about',
|
||||||
],
|
],
|
||||||
|
boolean: {
|
||||||
|
followedByCurrentUser:
|
||||||
|
'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',
|
||||||
|
},
|
||||||
count: {
|
count: {
|
||||||
contributionsCount: '-[:WROTE]->(related:Post)',
|
contributionsCount: '-[:WROTE]->(related:Post)',
|
||||||
friendsCount: '<-[:FRIENDS]->(related:User)',
|
friendsCount: '<-[:FRIENDS]->(related:User)',
|
||||||
|
|||||||
@ -122,13 +122,34 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isOwner && this.resourceType === 'user') {
|
if (this.resourceType === 'user') {
|
||||||
routes.push({
|
if (this.isOwner) {
|
||||||
name: this.$t(`settings.name`),
|
routes.push({
|
||||||
path: '/settings',
|
name: this.$t(`settings.name`),
|
||||||
icon: 'edit',
|
path: '/settings',
|
||||||
})
|
icon: 'edit',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
if (this.resource.isBlocked) {
|
||||||
|
routes.push({
|
||||||
|
name: this.$t(`settings.blocked-users.unblock`),
|
||||||
|
callback: () => {
|
||||||
|
this.$emit('unblock', this.resource)
|
||||||
|
},
|
||||||
|
icon: 'user-plus',
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
routes.push({
|
||||||
|
name: this.$t(`settings.blocked-users.block`),
|
||||||
|
callback: () => {
|
||||||
|
this.$emit('block', this.resource)
|
||||||
|
},
|
||||||
|
icon: 'user-times',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return routes
|
return routes
|
||||||
},
|
},
|
||||||
isModerator() {
|
isModerator() {
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export default i18n => {
|
|||||||
}
|
}
|
||||||
followedByCount
|
followedByCount
|
||||||
followedByCurrentUser
|
followedByCurrentUser
|
||||||
|
isBlocked
|
||||||
followedBy(first: 7) {
|
followedBy(first: 7) {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
export default () => {
|
export const BlockedUsers = () => {
|
||||||
return gql(`
|
return gql(`
|
||||||
{
|
{
|
||||||
blockedUsers {
|
blockedUsers {
|
||||||
@ -15,3 +15,25 @@ export default () => {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Block = () => {
|
||||||
|
return gql(`mutation($id:ID!) {
|
||||||
|
block(id: $id) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
isBlocked
|
||||||
|
followedByCurrentUser
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Unblock = () => {
|
||||||
|
return gql(`mutation($id:ID!) {
|
||||||
|
unblock(id: $id) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
isBlocked
|
||||||
|
followedByCurrentUser
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
}
|
||||||
|
|||||||
@ -202,7 +202,9 @@
|
|||||||
"name": "Name",
|
"name": "Name",
|
||||||
"slug": "Alias"
|
"slug": "Alias"
|
||||||
},
|
},
|
||||||
"empty": "Bislang hast du niemanden blockiert."
|
"empty": "Bislang hast du niemanden blockiert.",
|
||||||
|
"block": "Nutzer blockieren",
|
||||||
|
"unblock": "Nutzer entblocken"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
|
|||||||
@ -203,7 +203,9 @@
|
|||||||
"name": "Name",
|
"name": "Name",
|
||||||
"slug": "Slug"
|
"slug": "Slug"
|
||||||
},
|
},
|
||||||
"empty": "So far, you did not block anybody."
|
"empty": "So far, you did not block anybody.",
|
||||||
|
"block": "Block user",
|
||||||
|
"unblock": "Unblock user"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
|
|||||||
@ -22,6 +22,8 @@
|
|||||||
:resource="user"
|
:resource="user"
|
||||||
:is-owner="myProfile"
|
:is-owner="myProfile"
|
||||||
class="user-content-menu"
|
class="user-content-menu"
|
||||||
|
@block="block"
|
||||||
|
@unblock="unblock"
|
||||||
/>
|
/>
|
||||||
</no-ssr>
|
</no-ssr>
|
||||||
<ds-space margin="small">
|
<ds-space margin="small">
|
||||||
@ -54,13 +56,18 @@
|
|||||||
</ds-flex-item>
|
</ds-flex-item>
|
||||||
</ds-flex>
|
</ds-flex>
|
||||||
<ds-space margin="small">
|
<ds-space margin="small">
|
||||||
<hc-follow-button
|
<template v-if="!myProfile">
|
||||||
v-if="!myProfile"
|
<hc-follow-button
|
||||||
:follow-id="user.id"
|
v-if="!user.isBlocked"
|
||||||
:is-followed="user.followedByCurrentUser"
|
:follow-id="user.id"
|
||||||
@optimistic="follow => (user.followedByCurrentUser = follow)"
|
:is-followed="user.followedByCurrentUser"
|
||||||
@update="follow => fetchUser()"
|
@optimistic="follow => (user.followedByCurrentUser = follow)"
|
||||||
/>
|
@update="follow => fetchUser()"
|
||||||
|
/>
|
||||||
|
<ds-button v-else fullwidth @click="unblock(user)">
|
||||||
|
{{ $t('settings.blocked-users.unblock') }}
|
||||||
|
</ds-button>
|
||||||
|
</template>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
<template v-if="user.about">
|
<template v-if="user.about">
|
||||||
<hr />
|
<hr />
|
||||||
@ -242,6 +249,7 @@ import HcUpload from '~/components/Upload'
|
|||||||
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
||||||
import PostQuery from '~/graphql/UserProfile/Post.js'
|
import PostQuery from '~/graphql/UserProfile/Post.js'
|
||||||
import UserQuery from '~/graphql/UserProfile/User.js'
|
import UserQuery from '~/graphql/UserProfile/User.js'
|
||||||
|
import { Block, Unblock } from '~/graphql/settings/BlockedUsers.js'
|
||||||
|
|
||||||
const tabToFilterMapping = ({ tab, id }) => {
|
const tabToFilterMapping = ({ tab, id }) => {
|
||||||
return {
|
return {
|
||||||
@ -372,6 +380,13 @@ export default {
|
|||||||
}
|
}
|
||||||
return this.uniq(this.Post.filter(post => !post.deleted))
|
return this.uniq(this.Post.filter(post => !post.deleted))
|
||||||
},
|
},
|
||||||
|
async block(user) {
|
||||||
|
await this.$apollo.mutate({ mutation: Block(), variables: { id: user.id } })
|
||||||
|
await this.fetchUser()
|
||||||
|
},
|
||||||
|
async unblock(user) {
|
||||||
|
await this.$apollo.mutate({ mutation: Unblock(), variables: { id: user.id } })
|
||||||
|
},
|
||||||
},
|
},
|
||||||
apollo: {
|
apollo: {
|
||||||
Post: {
|
Post: {
|
||||||
|
|||||||
@ -61,7 +61,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BlockedUsers from '~/graphql/settings/BlockedUsers'
|
import { BlockedUsers } from '~/graphql/settings/BlockedUsers'
|
||||||
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
import HcAvatar from '~/components/Avatar/Avatar.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user