add domain blocking (#496)

* add domain blocking

fixes another thing from #6

* show "domain blocking" on profile page
This commit is contained in:
Nolan Lawson 2018-08-26 14:16:00 -07:00 committed by GitHub
parent 47315c7f6d
commit 95665f6d74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 8 deletions

View file

@ -9,7 +9,7 @@ import {
} from '../_database/relationships'
import { store } from '../_store/store'
async function updateAccount (accountId, instanceName, accessToken) {
async function _updateAccount (accountId, instanceName, accessToken) {
let localPromise = getAccountFromDatabase(instanceName, accountId)
let remotePromise = getAccount(instanceName, accessToken, accountId).then(account => {
/* no await */ setAccountInDatabase(instanceName, account)
@ -28,7 +28,7 @@ async function updateAccount (accountId, instanceName, accessToken) {
}
}
async function updateRelationship (accountId, instanceName, accessToken) {
async function _updateRelationship (accountId, instanceName, accessToken) {
let localPromise = getRelationshipFromDatabase(instanceName, accountId)
let remotePromise = getRelationship(instanceName, accessToken, accountId).then(relationship => {
/* no await */ setRelationshipInDatabase(instanceName, relationship)
@ -66,7 +66,13 @@ export async function updateProfileAndRelationship (accountId) {
let { currentInstance, accessToken } = store.get()
await Promise.all([
updateAccount(accountId, currentInstance, accessToken),
updateRelationship(accountId, currentInstance, accessToken)
_updateAccount(accountId, currentInstance, accessToken),
_updateRelationship(accountId, currentInstance, accessToken)
])
}
export async function updateRelationship (accountId) {
let { currentInstance, accessToken } = store.get()
await _updateRelationship(accountId, currentInstance, accessToken)
}

View file

@ -0,0 +1,26 @@
import { store } from '../_store/store'
import { blockDomain, unblockDomain } from '../_api/blockDomain'
import { toast } from '../_utils/toast'
import { updateRelationship } from './accounts'
export async function setDomainBlocked (accountId, domain, block, toastOnSuccess) {
let { currentInstance, accessToken } = store.get()
try {
if (block) {
await blockDomain(currentInstance, accessToken, domain)
} else {
await unblockDomain(currentInstance, accessToken, domain)
}
await updateRelationship(accountId)
if (toastOnSuccess) {
if (block) {
toast.say(`Hiding ${domain}`)
} else {
toast.say(`Unhiding ${domain}`)
}
}
} catch (e) {
console.error(e)
toast.say(`Unable to ${block ? 'hide' : 'unhide'} domain: ` + (e.message || ''))
}
}

View file

@ -0,0 +1,12 @@
import { post, WRITE_TIMEOUT, paramsString, del } from '../_utils/ajax'
import { auth, basename } from './utils'
export async function blockDomain (instanceName, accessToken, domain) {
let url = `${basename(instanceName)}/api/v1/domain_blocks?${paramsString({ domain })}`
return post(url, null, auth(accessToken), {timeout: WRITE_TIMEOUT})
}
export async function unblockDomain (instanceName, accessToken, domain) {
let url = `${basename(instanceName)}/api/v1/domain_blocks?${paramsString({ domain })}`
return del(url, auth(accessToken), {timeout: WRITE_TIMEOUT})
}

View file

@ -19,6 +19,7 @@ import { setAccountBlocked } from '../../../_actions/block'
import { setAccountMuted } from '../../../_actions/mute'
import { setAccountFollowed } from '../../../_actions/follow'
import { setShowReblogs } from '../../../_actions/setShowReblogs'
import { setDomainBlocked } from '../../../_actions/setDomainBlocked'
export default {
oncreate,
@ -66,10 +67,18 @@ export default {
? `Hide boosts from @${acct}`
: `Show boosts from @${acct}`
),
domain: ({ acct }) => acct.split('@')[1],
blockingDomain: ({ relationship }) => !!relationship.domain_blocking,
blockDomainLabel: ({ blockingDomain, domain }) => (
blockingDomain
? `Unhide ${domain}`
: `Hide ${domain}`
),
items: ({
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
followLabel, followIcon, following, followRequested,
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel,
domain, blockDomainLabel
}) => ([
!isUser && {
key: 'mention',
@ -96,6 +105,11 @@ export default {
label: showReblogsLabel,
icon: '#fa-retweet'
},
!isUser && domain && {
key: 'blockDomain',
label: blockDomainLabel,
icon: '#fa-ban'
},
{
key: 'copy',
label: 'Copy link to account',
@ -116,10 +130,12 @@ export default {
return this.onBlockClicked()
case 'mute':
return this.onMuteClicked()
case 'copy':
return this.onCopyClicked()
case 'showReblogs':
return this.onShowReblogsClicked()
case 'blockDomain':
return this.onBlockDomainClicked()
case 'copy':
return this.onCopyClicked()
}
},
async onMentionClicked () {
@ -151,6 +167,11 @@ export default {
this.close()
await setShowReblogs(accountId, !showingReblogs, true)
},
async onBlockDomainClicked () {
let { accountId, domain, blockingDomain } = this.get()
this.close()
await setDomainBlocked(accountId, domain, !blockingDomain, true)
},
async onCopyClicked () {
let { account } = this.get()
let { url } = account

View file

@ -20,7 +20,14 @@
<div class="account-profile-followed-by">
{#if relationship && relationship.blocking}
<span class="account-profile-followed-by-span">Blocked</span>
{:elseif relationship && relationship.followed_by}
{/if}
{#if relationship && relationship.domain_blocking}
<span class="account-profile-followed-by-span">Domain hidden</span>
{/if}
{#if relationship && relationship.muting}
<span class="account-profile-followed-by-span">Muted</span>
{/if}
{#if relationship && relationship.followed_by}
<span class="account-profile-followed-by-span">Follows you</span>
{/if}
</div>
@ -31,6 +38,7 @@
text-transform: uppercase;
color: var(--deemphasized-text-color);
font-size: 0.8em;
white-space: nowrap;
}
.account-profile-followed-by-span {
background: rgba(30, 30, 30, 0.2);