mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-29 00:10:50 +00:00
Use API to check if user is following profile
This commit is contained in:
parent
a866038dcb
commit
a4c1ee2863
@ -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('/');
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user