add domain blocking (#496)
* add domain blocking fixes another thing from #6 * show "domain blocking" on profile page
This commit is contained in:
parent
47315c7f6d
commit
95665f6d74
|
@ -9,7 +9,7 @@ import {
|
||||||
} from '../_database/relationships'
|
} from '../_database/relationships'
|
||||||
import { store } from '../_store/store'
|
import { store } from '../_store/store'
|
||||||
|
|
||||||
async function updateAccount (accountId, instanceName, accessToken) {
|
async function _updateAccount (accountId, instanceName, accessToken) {
|
||||||
let localPromise = getAccountFromDatabase(instanceName, accountId)
|
let localPromise = getAccountFromDatabase(instanceName, accountId)
|
||||||
let remotePromise = getAccount(instanceName, accessToken, accountId).then(account => {
|
let remotePromise = getAccount(instanceName, accessToken, accountId).then(account => {
|
||||||
/* no await */ setAccountInDatabase(instanceName, 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 localPromise = getRelationshipFromDatabase(instanceName, accountId)
|
||||||
let remotePromise = getRelationship(instanceName, accessToken, accountId).then(relationship => {
|
let remotePromise = getRelationship(instanceName, accessToken, accountId).then(relationship => {
|
||||||
/* no await */ setRelationshipInDatabase(instanceName, relationship)
|
/* no await */ setRelationshipInDatabase(instanceName, relationship)
|
||||||
|
@ -66,7 +66,13 @@ export async function updateProfileAndRelationship (accountId) {
|
||||||
let { currentInstance, accessToken } = store.get()
|
let { currentInstance, accessToken } = store.get()
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
updateAccount(accountId, currentInstance, accessToken),
|
_updateAccount(accountId, currentInstance, accessToken),
|
||||||
updateRelationship(accountId, currentInstance, accessToken)
|
_updateRelationship(accountId, currentInstance, accessToken)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateRelationship (accountId) {
|
||||||
|
let { currentInstance, accessToken } = store.get()
|
||||||
|
|
||||||
|
await _updateRelationship(accountId, currentInstance, accessToken)
|
||||||
|
}
|
||||||
|
|
26
routes/_actions/setDomainBlocked.js
Normal file
26
routes/_actions/setDomainBlocked.js
Normal 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 || ''))
|
||||||
|
}
|
||||||
|
}
|
12
routes/_api/blockDomain.js
Normal file
12
routes/_api/blockDomain.js
Normal 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})
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import { setAccountBlocked } from '../../../_actions/block'
|
||||||
import { setAccountMuted } from '../../../_actions/mute'
|
import { setAccountMuted } from '../../../_actions/mute'
|
||||||
import { setAccountFollowed } from '../../../_actions/follow'
|
import { setAccountFollowed } from '../../../_actions/follow'
|
||||||
import { setShowReblogs } from '../../../_actions/setShowReblogs'
|
import { setShowReblogs } from '../../../_actions/setShowReblogs'
|
||||||
|
import { setDomainBlocked } from '../../../_actions/setDomainBlocked'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate,
|
oncreate,
|
||||||
|
@ -66,10 +67,18 @@ export default {
|
||||||
? `Hide boosts from @${acct}`
|
? `Hide boosts from @${acct}`
|
||||||
: `Show 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: ({
|
items: ({
|
||||||
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
|
blockLabel, blocking, blockIcon, muteLabel, muteIcon,
|
||||||
followLabel, followIcon, following, followRequested,
|
followLabel, followIcon, following, followRequested,
|
||||||
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel
|
accountId, verifyCredentialsId, acct, isUser, showReblogsLabel,
|
||||||
|
domain, blockDomainLabel
|
||||||
}) => ([
|
}) => ([
|
||||||
!isUser && {
|
!isUser && {
|
||||||
key: 'mention',
|
key: 'mention',
|
||||||
|
@ -96,6 +105,11 @@ export default {
|
||||||
label: showReblogsLabel,
|
label: showReblogsLabel,
|
||||||
icon: '#fa-retweet'
|
icon: '#fa-retweet'
|
||||||
},
|
},
|
||||||
|
!isUser && domain && {
|
||||||
|
key: 'blockDomain',
|
||||||
|
label: blockDomainLabel,
|
||||||
|
icon: '#fa-ban'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'copy',
|
key: 'copy',
|
||||||
label: 'Copy link to account',
|
label: 'Copy link to account',
|
||||||
|
@ -116,10 +130,12 @@ export default {
|
||||||
return this.onBlockClicked()
|
return this.onBlockClicked()
|
||||||
case 'mute':
|
case 'mute':
|
||||||
return this.onMuteClicked()
|
return this.onMuteClicked()
|
||||||
case 'copy':
|
|
||||||
return this.onCopyClicked()
|
|
||||||
case 'showReblogs':
|
case 'showReblogs':
|
||||||
return this.onShowReblogsClicked()
|
return this.onShowReblogsClicked()
|
||||||
|
case 'blockDomain':
|
||||||
|
return this.onBlockDomainClicked()
|
||||||
|
case 'copy':
|
||||||
|
return this.onCopyClicked()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onMentionClicked () {
|
async onMentionClicked () {
|
||||||
|
@ -151,6 +167,11 @@ export default {
|
||||||
this.close()
|
this.close()
|
||||||
await setShowReblogs(accountId, !showingReblogs, true)
|
await setShowReblogs(accountId, !showingReblogs, true)
|
||||||
},
|
},
|
||||||
|
async onBlockDomainClicked () {
|
||||||
|
let { accountId, domain, blockingDomain } = this.get()
|
||||||
|
this.close()
|
||||||
|
await setDomainBlocked(accountId, domain, !blockingDomain, true)
|
||||||
|
},
|
||||||
async onCopyClicked () {
|
async onCopyClicked () {
|
||||||
let { account } = this.get()
|
let { account } = this.get()
|
||||||
let { url } = account
|
let { url } = account
|
||||||
|
|
|
@ -20,7 +20,14 @@
|
||||||
<div class="account-profile-followed-by">
|
<div class="account-profile-followed-by">
|
||||||
{#if relationship && relationship.blocking}
|
{#if relationship && relationship.blocking}
|
||||||
<span class="account-profile-followed-by-span">Blocked</span>
|
<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>
|
<span class="account-profile-followed-by-span">Follows you</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -31,6 +38,7 @@
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: var(--deemphasized-text-color);
|
color: var(--deemphasized-text-color);
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.account-profile-followed-by-span {
|
.account-profile-followed-by-span {
|
||||||
background: rgba(30, 30, 30, 0.2);
|
background: rgba(30, 30, 30, 0.2);
|
||||||
|
|
Loading…
Reference in a new issue