Skip to content

Commit

Permalink
refs #996 Disable follow, block, mute button if the profile is myself…
Browse files Browse the repository at this point in the history
… profile
  • Loading branch information
h3poteto committed Nov 23, 2023
1 parent 744e9ac commit 98c3407
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/components/detail/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Profile: React.FC<Props> = props => {
const { formatMessage } = useIntl()

const [client, setClient] = useState<MegalodonInterface | null>(null)
const [myself, setMyself] = useState<Entity.Account | null>(null)
const [account, setAccount] = useState<Account | null>(null)
const [server, setServer] = useState<Server | null>(null)
const [user, setUser] = useState<Entity.Account | null>(null)
Expand All @@ -59,6 +60,8 @@ const Profile: React.FC<Props> = props => {
setServer(server)
cli = generator(server.sns, server.base_url, account.access_token, 'Fedistar')
setClient(cli)
const u = await cli.verifyAccountCredentials()
setMyself(u.data)
} else if (router.query.server_id) {
const server = await invoke<Server>('get_server', { id: parseInt(router.query.server_id.toString()) })
setAccount(null)
Expand Down Expand Up @@ -231,7 +234,7 @@ const Profile: React.FC<Props> = props => {
<FlexboxGrid.Item>
<FlexboxGrid style={{ gap: '8px' }}>
<FlexboxGrid.Item>
<FollowButton relationship={relationship} follow={follow} unfollow={unfollow} />
<FollowButton relationship={relationship} follow={follow} unfollow={unfollow} myself={myself} user={user} />
</FlexboxGrid.Item>
<FlexboxGrid.Item>
<Whisper
Expand All @@ -246,6 +249,7 @@ const Profile: React.FC<Props> = props => {
top,
onClose,
client,
myself,
user,
relationship,
onChange: () => {
Expand Down Expand Up @@ -320,14 +324,15 @@ type ProfileMenuProps = {
top?: number
onClose: (delay?: number) => NodeJS.Timeout | void
client: MegalodonInterface
myself: Entity.Account
user: Entity.Account
relationship: Entity.Relationship | null
onChange: () => void
openAddListMember: (user: Entity.Account, client: MegalodonInterface) => void
}

const profileMenu = (
{ className, left, top, onClose, client, user, relationship, onChange, openAddListMember }: ProfileMenuProps,
{ className, left, top, onClose, client, myself, user, relationship, onChange, openAddListMember }: ProfileMenuProps,
ref: React.RefCallback<HTMLElement>
): ReactElement => {
const domain = domainFromAcct(user.acct)
Expand Down Expand Up @@ -381,14 +386,14 @@ const profileMenu = (
{relationship && (
<>
<Dropdown.Separator />
<Dropdown.Item eventKey="mute">
<Dropdown.Item eventKey="mute" disabled={myself.acct === user.acct}>
{relationship.muting ? (
<FormattedMessage id="detail.profile.unmute" values={{ user: `@${user.username}` }} />
) : (
<FormattedMessage id="detail.profile.mute" values={{ user: `@${user.username}` }} />
)}
</Dropdown.Item>
<Dropdown.Item eventKey="block">
<Dropdown.Item eventKey="block" disabled={myself.acct === user.acct}>
{relationship.blocking ? (
<FormattedMessage id="detail.profile.unblock" values={{ user: `@${user.username}` }} />
) : (
Expand All @@ -402,7 +407,7 @@ const profileMenu = (
{domain && (
<>
<Dropdown.Separator />
<Dropdown.Item eventKey="domain_block">
<Dropdown.Item eventKey="domain_block" disabled={myself.acct === user.acct}>
{relationship.domain_blocking ? (
<FormattedMessage id="detail.profile.unblock_domain" values={{ server: domain }} />
) : (
Expand Down Expand Up @@ -430,6 +435,8 @@ const precision = (num: number): string => {

type FollowButtonProps = {
relationship: Entity.Relationship
myself: Entity.Account
user: Entity.Account
follow: () => Promise<void>
unfollow: () => Promise<void>
}
Expand All @@ -444,6 +451,9 @@ const FollowButton: React.FC<FollowButtonProps> = props => {
if (!props.relationship) {
return null
}
if (props.user.acct === props.myself.acct) {
return null
}
if (props.relationship.following) {
return (
<Button
Expand Down

0 comments on commit 98c3407

Please sign in to comment.