Add caption on profile page if it's filtered

This commit is contained in:
Bojan Mojsilovic 2023-08-30 15:17:30 +02:00
parent 014aac2219
commit f2229e033c
6 changed files with 74 additions and 26 deletions

View File

@ -71,7 +71,7 @@ export type AccountContextStore = {
addFilterList: (pubkey: string | undefined) => void, addFilterList: (pubkey: string | undefined) => void,
removeFilterList: (pubkey: string | undefined) => void, removeFilterList: (pubkey: string | undefined) => void,
updateFilterList: (pubkey: string | undefined, content?: boolean, trending?: boolean) => void, updateFilterList: (pubkey: string | undefined, content?: boolean, trending?: boolean) => void,
addToAllowlist: (pubkey: string | undefined) => void, addToAllowlist: (pubkey: string | undefined, then?: () => void) => void,
removeFromAllowlist: (pubkey: string | undefined) => void, removeFromAllowlist: (pubkey: string | undefined) => void,
}, },
} }
@ -881,7 +881,7 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
getAllowlist(pubkey, subId); getAllowlist(pubkey, subId);
}; };
const addToAllowlist = async (pubkey: string | undefined) => { const addToAllowlist = async (pubkey: string | undefined, then?: () => void) => {
if (!pubkey) { if (!pubkey) {
return; return;
} }
@ -903,9 +903,9 @@ export function AccountProvider(props: { children: number | boolean | Node | JSX
if (success) { if (success) {
note && triggerImportEvents([note], `import_allowlist_event_add_${APP_ID}`) note && triggerImportEvents([note], `import_allowlist_event_add_${APP_ID}`)
return;
} }
then && then();
unsub(); unsub();
return; return;
} }

View File

@ -64,6 +64,7 @@ export type ProfileContextStore = {
lastNote: PrimalNote | undefined, lastNote: PrimalNote | undefined,
following: string[], following: string[],
sidebar: FeedPage & { notes: PrimalNote[] }, sidebar: FeedPage & { notes: PrimalNote[] },
filterReason: { action: 'block' | 'allow', pubkey?: string, group?: string } | null,
actions: { actions: {
saveNotes: (newNotes: PrimalNote[]) => void, saveNotes: (newNotes: PrimalNote[]) => void,
clearNotes: () => void, clearNotes: () => void,
@ -96,6 +97,7 @@ export const initialData = {
reposts: {}, reposts: {},
lastNote: undefined, lastNote: undefined,
following: [], following: [],
filterReason: null,
sidebar: { sidebar: {
messages: [], messages: [],
users: {}, users: {},
@ -402,9 +404,10 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
updateStore('profileKey', () => profileKey); updateStore('profileKey', () => profileKey);
if (profileKey) { if (profileKey) {
updateStore('filterReason', () => null);
updateStore('userProfile', () => undefined); updateStore('userProfile', () => undefined);
updateStore('userStats', () => ({ ...emptyStats })); updateStore('userStats', () => ({ ...emptyStats }));
getUserProfileInfo(profileKey, `profile_info_${APP_ID}`); getUserProfileInfo(profileKey, account?.publicKey, `profile_info_${APP_ID}`);
getProfileScoredNotes(profileKey, account?.publicKey, `profile_scored_${APP_ID}`, 10); getProfileScoredNotes(profileKey, account?.publicKey, `profile_scored_${APP_ID}`, 10);
isUserFollowing(profileKey, account?.publicKey, `is_profile_following_${APP_ID}`); isUserFollowing(profileKey, account?.publicKey, `is_profile_following_${APP_ID}`);
@ -444,6 +447,14 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
} }
if (subId === `profile_info_${APP_ID}`) { if (subId === `profile_info_${APP_ID}`) {
if (content?.kind === Kind.FilteringReason) {
const reason: { action: 'block' | 'allow', pubkey?: string, group?: string } | null =
JSON.parse(content.content) || null;
if (reason?.action === 'block') {
updateStore('filterReason', () => ({ ...reason }));
}
}
if (content?.kind === Kind.Metadata) { if (content?.kind === Kind.Metadata) {
let user = JSON.parse(content.content); let user = JSON.parse(content.content);

View File

@ -16,14 +16,23 @@ export const getUserProfiles = (pubkeys: string[], subid: string) => {
])); ]));
} }
export const getUserProfileInfo = (pubkey: string | undefined, subid: string) => { export const getUserProfileInfo = (pubkey: string | undefined, user_pubkey: string | undefined, subid: string) => {
if (!pubkey) { if (!pubkey) {
return; return;
} }
let payload: any = {
pubkey,
};
if (user_pubkey) {
payload.user_pubkey = user_pubkey;
}
sendMessage(JSON.stringify([ sendMessage(JSON.stringify([
"REQ", "REQ",
subid, subid,
{cache: ["user_profile", { pubkey }]}, {cache: ["user_profile", payload]},
])); ]));
} }

View File

@ -91,7 +91,7 @@ const Mutelist: Component = () => {
} }
}); });
getUserProfileInfo(pubkey, subId); getUserProfileInfo(pubkey, undefined, subId);
}; };
const user = (pubkey: string) => mutedUsers[pubkey]; const user = (pubkey: string) => mutedUsers[pubkey];

View File

@ -6,8 +6,10 @@ import {
createMemo, createMemo,
createSignal, createSignal,
For, For,
Match,
Resource, Resource,
Show Show,
Switch
} from 'solid-js'; } from 'solid-js';
import Avatar from '../components/Avatar/Avatar'; import Avatar from '../components/Avatar/Avatar';
import Branding from '../components/Branding/Branding'; import Branding from '../components/Branding/Branding';
@ -197,10 +199,8 @@ const Profile: Component = () => {
return; return;
} }
if (!isMuted(pk)) { if (!isMuted(pk) && account?.isKeyLookupDone) {
setTimeout(() => { profile?.actions.fetchNotes(pk);
profile?.actions.fetchNotes(pk);
}, 500);
} }
}); });
@ -224,6 +224,10 @@ const Profile: Component = () => {
(ignoreContentCheck ? true : isContentMuted); (ignoreContentCheck ? true : isContentMuted);
}; };
const isFiltered = () => {
return profile?.filterReason !== null;
};
const unMuteProfile = () => { const unMuteProfile = () => {
if (!account || !profile?.profileKey) { if (!account || !profile?.profileKey) {
return; return;
@ -376,6 +380,14 @@ const Profile: Component = () => {
toaster?.sendSuccess(intl.formatMessage(tToast.noteAuthorReported, { name: userName(profile?.userProfile)})); toaster?.sendSuccess(intl.formatMessage(tToast.noteAuthorReported, { name: userName(profile?.userProfile)}));
}; };
const addToAllowlist = async () => {
const pk = getHex();
if (pk) {
account?.actions.addToAllowlist(pk, () => { setProfile(pk) });
}
};
const copyProfileLink = () => { const copyProfileLink = () => {
navigator.clipboard.writeText(`${window.location.href}`); navigator.clipboard.writeText(`${window.location.href}`);
setContext(false); setContext(false);
@ -598,9 +610,13 @@ const Profile: Component = () => {
</div> </div>
<div class={styles.userFeed}> <div class={styles.userFeed}>
<Show <Switch
when={!isMuted(profile?.profileKey)}
fallback={ fallback={
<div style="margin-top: 40px;">
<Loader />
</div>
}>
<Match when={isMuted(profile?.profileKey)}>
<div class={styles.mutedProfile}> <div class={styles.mutedProfile}>
{intl.formatMessage( {intl.formatMessage(
t.isMuted, t.isMuted,
@ -612,24 +628,26 @@ const Profile: Component = () => {
{intl.formatMessage(tActions.unmute)} {intl.formatMessage(tActions.unmute)}
</button> </button>
</div> </div>
} </Match>
> <Match when={isFiltered()}>
<Show <div class={styles.mutedProfile}>
when={profile && profile.notes.length > 0} {intl.formatMessage(t.isFiltered)}
fallback={ <button
<div style="margin-top: 40px;"> onClick={addToAllowlist}
<Loader /> >
</div>} {intl.formatMessage(tActions.addToAllowlist)}
> </button>
</div>
</Match>
<Match when={profile && profile.notes.length > 0}>
<For each={profile?.notes}> <For each={profile?.notes}>
{note => ( {note => (
<Note note={note} /> <Note note={note} />
)} )}
</For> </For>
<Paginator loadNextPage={profile?.actions.fetchNextPage}/> <Paginator loadNextPage={profile?.actions.fetchNextPage}/>
</Show> </Match>
</Show> </Switch>
</div> </div>
<ConfirmModal <ConfirmModal

View File

@ -97,6 +97,11 @@ export const actions = {
defaultMessage: 'unmute', defaultMessage: 'unmute',
description: 'Label un-mute button', description: 'Label un-mute button',
}, },
addToAllowlist: {
id: 'actions.addToAllowlist',
defaultMessage: 'Add to allowlist',
description: 'Label add-to-allowlist button',
},
addRelay: { addRelay: {
id: 'actions.addRelay', id: 'actions.addRelay',
defaultMessage: 'add', defaultMessage: 'add',
@ -827,6 +832,11 @@ export const profile = {
defaultMessage: '{name} is muted', defaultMessage: '{name} is muted',
description: 'Label indicating that the profile is muted', description: 'Label indicating that the profile is muted',
}, },
isFiltered: {
id: 'profile.isFiltered',
defaultMessage: 'This account is hidden per your filter settings.',
description: 'Label indicating that the profile is filtered',
},
}; };
export const search = { export const search = {