Skip to content

Commit

Permalink
Merge pull request #791 from h3poteto/iss-704
Browse files Browse the repository at this point in the history
refs #704 Add a menu to block the domain
  • Loading branch information
h3poteto authored May 21, 2023
2 parents 26d3583 + 0ad8374 commit 3330ef7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
12 changes: 7 additions & 5 deletions locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
"copy": "Copy link to post",
"edit": "Edit",
"delete": "Delete",
"report": "Report",
"report": "Report {{user}}",
"from_other_account": "React from other accounts"
}
},
Expand Down Expand Up @@ -252,10 +252,12 @@
"following": "Following",
"followers": "Followers",
"open_page": "Open original page",
"mute": "Mute",
"unmute": "Unmute",
"block": "Block",
"unblock": "Unblock"
"mute": "Mute {{user}}",
"unmute": "Unmute {{user}}",
"block": "Block {{user}}",
"unblock": "Unblock {{user}}",
"unblock_domain": "Unblock domain {{server}}",
"block_domain": "Block domain {{server}}"
}
},
"report": {
Expand Down
30 changes: 28 additions & 2 deletions src/components/detail/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Following, { FuncProps as FollowingFunc } from './profile/Following'
import Followers, { FuncProps as FollowersFunc } from './profile/Followers'
import { useTranslation } from 'react-i18next'
import { findLink } from 'src/utils/statusParser'
import { domainFromAcct } from 'src/utils/domain'

const PostsTab = forwardRef(Posts)
const FollowingTab = forwardRef(Following)
Expand Down Expand Up @@ -327,6 +328,8 @@ const profileMenu = (
): ReactElement => {
const { t } = useTranslation()

const domain = domainFromAcct(user.acct)

const handleSelect = async (eventKey: string) => {
onClose()
switch (eventKey) {
Expand All @@ -352,6 +355,15 @@ const profileMenu = (
onChange()
return
}
case 'domain_block': {
if (relationship.domain_blocking) {
await client.unblockDomain(domain)
} else {
await client.blockDomain(domain)
}
onChange()
return
}
}
}
return (
Expand All @@ -362,11 +374,25 @@ const profileMenu = (
<>
<Dropdown.Separator />
<Dropdown.Item eventKey="mute">
{relationship.muting ? t('detail.profile.unmute') : t('detail.profile.mute')} @{user.username}
{relationship.muting
? t('detail.profile.unmute', { user: `@${user.username}` })
: t('detail.profile.mute', { user: `@${user.username}` })}
</Dropdown.Item>
<Dropdown.Item eventKey="block">
{relationship.blocking ? t('detail.profile.unblock') : t('detail.profile.block')} @{user.username}
{relationship.blocking
? t('detail.profile.unblock', { user: `@${user.username}` })
: t('detail.profile.block', { user: `@${user.username}` })}
</Dropdown.Item>
{domain && (
<>
<Dropdown.Separator />
<Dropdown.Item eventKey="domain_block">
{relationship.domain_blocking
? t('detail.profile.unblock_domain', { server: domain })
: t('detail.profile.block_domain', { server: domain })}
</Dropdown.Item>
</>
)}
</>
)}
</Dropdown.Menu>
Expand Down
7 changes: 5 additions & 2 deletions src/components/timelines/status/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const Actions: React.FC<Props> = props => {
<Whisper
trigger="click"
placement="bottom"
preventOverflow
speaker={({ className, left, top, onClose }, ref) =>
detailMenu(
{
Expand All @@ -202,6 +203,7 @@ const Actions: React.FC<Props> = props => {
top,
onClose,
own: props.account && props.account.account_id === props.status.account.id,
status: props.status,
disabled: typeof props.disabled === 'boolean' ? props.disabled : props.disabled.detail,
openBrowser: () => {
open(status.url)
Expand Down Expand Up @@ -272,6 +274,7 @@ type DetailMenuProps = {
left?: number
top?: number
own: boolean
status: Entity.Status
disabled: boolean
openBrowser: () => void
copyLink: () => void
Expand All @@ -284,7 +287,7 @@ type DetailMenuProps = {

const detailMenu = (props: DetailMenuProps, ref: React.RefCallback<HTMLElement>) => {
const { t } = useTranslation()
const { left, top, className } = props
const { left, top, className, status } = props

const handleSelect = async (eventKey: string) => {
props.onClose()
Expand Down Expand Up @@ -327,7 +330,7 @@ const detailMenu = (props: DetailMenuProps, ref: React.RefCallback<HTMLElement>)
)}
<Dropdown.Separator />
<Dropdown.Item disabled={props.disabled} eventKey="report">
{t('timeline.actions.detail.report')}
{t('timeline.actions.detail.report', { user: `@${status.account.username}` })}
</Dropdown.Item>
<Dropdown.Separator />
<Dropdown.Item eventKey="from_other_account">{t('timeline.actions.detail.from_other_account')}</Dropdown.Item>
Expand Down
7 changes: 7 additions & 0 deletions src/utils/domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const domainFromAcct = (acct: string): string | null => {
const [_account, server] = acct.split('@')
if (server) {
return server
}
return null
}

0 comments on commit 3330ef7

Please sign in to comment.