diff --git a/locales/en/translation.json b/locales/en/translation.json index 27ab26b9..9e40b8cc 100644 --- a/locales/en/translation.json +++ b/locales/en/translation.json @@ -16,7 +16,8 @@ "show_more": "Show more", "show_less": "Show less", "cw": "Media hidden", - "report": "Report {user}" + "report": "Report {user}", + "open_original": "Open original page" } }, "accounts": { @@ -121,6 +122,12 @@ "follow": "Follow", "unfollow": "Unfollow", "open_original": "Open original page", + "block": "Block", + "unblock": "Unblock", + "mute": "Mute", + "unmute": "Unmute", + "block_domain": "Block domain {server}", + "unblock_domain": "Unblock domain {server}", "timeline": "Timeline", "followers": "Followers", "followings": "Followings" diff --git a/renderer/components/detail/Profile.tsx b/renderer/components/detail/Profile.tsx index a2d4b8fa..cf9fe1d9 100644 --- a/renderer/components/detail/Profile.tsx +++ b/renderer/components/detail/Profile.tsx @@ -23,6 +23,7 @@ import { TabsBody, TabsHeader } from '@material-tailwind/react' +import { domainFromAcct } from '@/utils/domain' type Props = { client: MegalodonInterface @@ -35,19 +36,25 @@ export default function Profile(props: Props) { const [user, setUser] = useState(null) const [relationship, setRelationship] = useState(null) const [popoverDetail, setPopoverDetail] = useState(false) + const [domain, setDomain] = useState(null) useEffect(() => { const f = async () => { if (props.user_id) { const res = await props.client.getAccount(props.user_id) setUser(res.data) - const rel = await props.client.getRelationship(props.user_id) - setRelationship(rel.data) + setDomain(domainFromAcct(res.data.acct)) + await refresh() } } f() }, [props.user_id, props.client]) + const refresh = async () => { + const rel = await props.client.getRelationship(props.user_id) + setRelationship(rel.data) + } + const follow = async (id: string) => { const rel = await props.client.followAccount(id) setRelationship(rel.data) @@ -62,6 +69,48 @@ export default function Profile(props: Props) { global.ipc.invoke('open-browser', url) } + const block = async () => { + if (user) { + await props.client.blockAccount(user.id) + await refresh() + } + } + + const unblock = async () => { + if (user) { + await props.client.unblockAccount(user.id) + await refresh() + } + } + + const mute = async () => { + if (user) { + await props.client.muteAccount(user.id, false) + await refresh() + } + } + + const unmute = async () => { + if (user) { + await props.client.unmuteAccount(user.id) + await refresh() + } + } + + const blockDomain = async () => { + if (user && domain) { + await props.client.blockDomain(domain) + await refresh() + } + } + + const unblockDomain = async () => { + if (user && domain) { + await props.client.unblockDomain(domain) + await refresh() + } + } + const profileClicked: MouseEventHandler = async e => { const url = findLink(e.target as HTMLElement, 'profile') if (url) { @@ -107,6 +156,63 @@ export default function Profile(props: Props) { > + {relationship.blocking ? ( + { + unblock() + setPopoverDetail(false) + }} + > + + + ) : ( + { + block() + setPopoverDetail(false) + }} + > + + + )} + {relationship.muting ? ( + { + unmute() + setPopoverDetail(false) + }} + > + + + ) : ( + { + mute() + setPopoverDetail(false) + }} + > + + + )} + {relationship.domain_blocking ? ( + { + blockDomain() + setPopoverDetail(false) + }} + > + + + ) : ( + { + unblockDomain() + setPopoverDetail(false) + }} + > + + + )} diff --git a/renderer/components/timelines/status/Actions.tsx b/renderer/components/timelines/status/Actions.tsx index 2bf82f23..18861edf 100644 --- a/renderer/components/timelines/status/Actions.tsx +++ b/renderer/components/timelines/status/Actions.tsx @@ -53,10 +53,15 @@ export default function Actions(props: Props) { const onEmojiSelect = async emoji => { await props.client.createEmojiReaction(props.status.id, emoji.native) - setPopoverDetail(false) + setPopoverEmoji(false) props.onRefresh() } + const original = () => { + setPopoverDetail(false) + global.ipc.invoke('open-browser', props.status.url) + } + const report = () => { setPopoverDetail(false) router.push({ query: { id: router.query.id, timeline: router.query.timeline, report_target_id: props.status.id, modal: true } }) @@ -97,6 +102,9 @@ export default function Actions(props: Props) { + + + diff --git a/renderer/utils/domain.ts b/renderer/utils/domain.ts new file mode 100644 index 00000000..63bf7849 --- /dev/null +++ b/renderer/utils/domain.ts @@ -0,0 +1,7 @@ +export const domainFromAcct = (acct: string): string | null => { + const [_account, server] = acct.split('@') + if (server) { + return server + } + return null +}