Use API to check if user is following profile

This commit is contained in:
Bojan Mojsilovic 2023-07-21 20:19:59 +02:00
parent a866038dcb
commit a4c1ee2863
4 changed files with 29 additions and 11 deletions

View File

@ -52,11 +52,6 @@ const Layout: Component = () => {
window.removeEventListener('resize', onResize);
});
createEffect(() => {
const path = location.pathname.split('/');
console.log('ROUTE: ', path)
})
const onNewNotePosted = (note: SendNoteResult) => {
const path = location.pathname.split('/');

View File

@ -37,6 +37,7 @@ import {
getProfileContactList,
getProfileScoredNotes,
getUserProfileInfo,
isUserFollowing,
} from "../lib/profile";
import { useAccountContext } from "./AccountContext";
@ -56,6 +57,7 @@ export type ProfileContextStore = {
page: FeedPage,
reposts: Record<string, string> | undefined,
},
isProfileFollowing: boolean,
isFetching: boolean,
page: FeedPage,
reposts: Record<string, string> | undefined,
@ -89,6 +91,7 @@ export const initialData = {
knownProfiles: { names: {} },
notes: [],
isFetching: false,
isProfileFollowing: false,
page: { messages: [], users: {}, postStats: {}, mentions: {}, noteActions: {} },
reposts: {},
lastNote: undefined,
@ -195,8 +198,6 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
const checkForNewNotes = (pubkey: string | undefined) => {
console.log('CHECKING FOR NEW NOTES ', pubkey);
if (store.future.notes.length > 100) {
return;
}
@ -383,9 +384,12 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
updateStore('userStats', () => ({ ...emptyStats }));
getUserProfileInfo(profileKey, `profile_info_${APP_ID}`);
getProfileScoredNotes(profileKey, `profile_scored_${APP_ID}`, 10);
setTimeout(() => {
getProfileContactList(profileKey, `profile_contacts_${APP_ID}`);
}, 100);
isUserFollowing(profileKey, account?.publicKey, `is_profile_following_${APP_ID}`);
// setTimeout(() => {
// getProfileContactList(profileKey, `profile_contacts_${APP_ID}`);
// }, 100);
}
}
@ -493,6 +497,13 @@ export const ProfileProvider = (props: { children: ContextChildren }) => {
return;
}
if (subId === `is_profile_following_${APP_ID}`) {
if (type === 'EVENT') {
updateStore('isProfileFollowing', JSON.parse(content?.content || 'false'))
return;
}
}
if (subId === `profile_scored_${APP_ID}`) {
if (type === 'EOSE') {
saveSidebar(store.sidebar);

View File

@ -24,6 +24,18 @@ export const getUserProfileInfo = (pubkey: string | undefined, subid: string) =>
]));
}
export const isUserFollowing = (pubkey: string | undefined, user_pubkey: string | undefined, subid: string) => {
if (!pubkey || !user_pubkey) {
return;
}
sendMessage(JSON.stringify([
"REQ",
subid,
{cache: ["is_user_following", { pubkey, user_pubkey }]},
]));
};
export const getProfileContactList = (pubkey: string | undefined, subid: string) => {
if (!pubkey) {
return;

View File

@ -155,7 +155,7 @@ const Profile: Component = () => {
}
const isFollowingYou = () => {
return account?.publicKey && profile?.following.includes(account.publicKey);
return profile?.isProfileFollowing;
}
const [isBannerCached, setisBannerCached] = createSignal(false);