Remove the ability to unfollow yourself

This commit is contained in:
Bojan Mojsilovic 2024-03-26 10:37:24 +01:00
parent af70930b35
commit cca4ab5949
5 changed files with 27 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import { A } from '@solidjs/router';
import { Component, For, Show } from 'solid-js';
import { useAccountContext } from '../../contexts/AccountContext';
import { hookForDev } from '../../lib/devTools';
import { authorName, nip05Verification, truncateNpub } from '../../stores/profile';
import { PrimalUser } from '../../types/primal';
@ -10,6 +11,8 @@ import styles from './PeopleList.module.scss';
const PeopleList: Component<{ people: PrimalUser[], label: string, id?: string }> = (props) => {
const account = useAccountContext();
const people = () => props.people;
return (
@ -44,7 +47,9 @@ const PeopleList: Component<{ people: PrimalUser[], label: string, id?: string }
{truncateNpub(person?.npub)}
</div>
</div>
<Show when={account?.publicKey !== person.pubkey}>
<FollowButton person={person} />
</Show>
</A>
}
</For>

View File

@ -14,6 +14,7 @@ import Avatar from '../Avatar/Avatar';
import FollowButton from '../FollowButton/FollowButton';
import { A } from '@solidjs/router';
import { humanizeNumber } from '../../lib/stats';
import { useAccountContext } from '../../contexts/AccountContext';
const ProfileContact: Component<{
@ -24,6 +25,7 @@ const ProfileContact: Component<{
}> = (props) => {
const intl = useIntl();
const account = useAccountContext();
return (
<div id={props.id} class={styles.profileContact}>
@ -57,7 +59,9 @@ const ProfileContact: Component<{
</div>
</div>
</Show>
<Show when={account?.publicKey !== props.profile?.pubkey}>
<FollowButton person={props.profile} postAction={props.postAction} />
</Show>
</div>
</div>
);

View File

@ -757,7 +757,11 @@ export function AccountProvider(props: { children: JSXElement }) {
}
const removeFollow = (pubkey: string, cb?: (remove: boolean, pubkey: string) => void) => {
if (!store.publicKey || !store.following.includes(pubkey)) {
if (
!store.publicKey ||
!store.following.includes(pubkey) ||
store.publicKey === pubkey
) {
return;
}

View File

@ -210,14 +210,19 @@ const CreateAccount: Component = () => { const intl = useIntl();
toast?.sendSuccess(intl.formatMessage(tToast.updateProfileSuccess));
pubkey && getUserProfiles([pubkey], `user_profile_${APP_ID}`);
const tags = followed.map(pk => ['p', pk]);
let tags = followed.map(pk => ['p', pk]);
const date = Math.floor((new Date()).getTime() / 1000);
if (pubkey) {
// Follow himself
tags.push(['p', pubkey]);
}
const sendResult = await sendContacts(tags, date, '', account.relays, relaySettings);
if (sendResult.success && sendResult.note) {
triggerImportEvents([sendResult.note], `import_contacts_${APP_ID}`, () => {
getProfileContactList(account?.publicKey, `user_contacts_${APP_ID}`);
getProfileContactList(pubkey, `user_contacts_${APP_ID}`);
});
}
@ -225,7 +230,7 @@ const CreateAccount: Component = () => { const intl = useIntl();
if (relayResult.success && relayResult.note) {
triggerImportEvents([relayResult.note], `import_relays_${APP_ID}`, () => {
getRelays(account?.publicKey, `user_relays_${APP_ID}`);
getRelays(pubkey, `user_relays_${APP_ID}`);
});
}

View File

@ -603,7 +603,9 @@ const Profile: Component = () => {
</ButtonSecondary>
</Show>
<Show when={account?.publicKey !== profile?.profileKey}>
<FollowButton person={profile?.userProfile} large={true} />
</Show>
<Show when={isCurrentUser()}>
<div class={styles.editProfileButton}>