Skip to content

Commit

Permalink
Get users with mega feed, use mega feed for reads
Browse files Browse the repository at this point in the history
  • Loading branch information
moysa committed Sep 25, 2024
1 parent 461021b commit a291f5d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 55 deletions.
20 changes: 19 additions & 1 deletion src/contexts/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {

const setProxyThroughPrimal = (shouldProxy: boolean, temp?: boolean) => {
account?.actions.setProxyThroughPrimal(shouldProxy);

!temp && saveSettings();
}

const setDefaultZapAmount = (option: ZapOption, temp?: boolean) => {
updateStore('defaultZap', () => option);

!temp && saveSettings();
};

const setZapOptions = (option: ZapOption, index: number, temp?: boolean) => {
updateStore('availableZapOptions', index, () => ({ ...option }));


!temp && saveSettings();
};

Expand All @@ -166,6 +170,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
updateStore('availableZapOptions', () => options);
updateStore('defaultZap', () => amount);


!temp && saveSettings();
}
catch (e) {
Expand Down Expand Up @@ -195,6 +200,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {

saveTheme(account?.publicKey, theme.name);
updateStore('theme', () => theme.name);

!temp && saveSettings();
}

Expand All @@ -211,12 +217,14 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {

saveAnimated(account?.publicKey, isAnimated);
updateStore('isAnimated', () => isAnimated);

!temp && saveSettings();
};

const setApplyContentModeration = (flag = true) => {
updateStore('applyContentModeration', () => flag);


saveSettings();
};

Expand All @@ -228,6 +236,8 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
const add = addToTop ? updateAvailableFeedsTop : updateAvailableFeeds;

updateStore('availableFeeds', (feeds) => add(account?.publicKey, feed, feeds));


!temp && saveSettings();
}
};
Expand All @@ -242,6 +252,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
(feeds) => removeFromAvailableFeeds(account?.publicKey, feed, feeds),
);


!temp && saveSettings();
}
};
Expand All @@ -251,6 +262,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
updateStore('availableFeeds',
() => replaceAvailableFeeds(account?.publicKey, feedList),
);

!temp && saveSettings();
}
};
Expand Down Expand Up @@ -451,6 +463,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
const updateNotificationSettings = (key: string, value: boolean, temp?: boolean) => {
updateStore('notificationSettings', () => ({ [key]: value }));


!temp && saveSettings();
};

Expand Down Expand Up @@ -514,6 +527,8 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
if (trending) scopes.push(trendingScope);

updateStore('contentModeration', x => x.name === name, () => ({ scopes }));


saveSettings();
};

Expand Down Expand Up @@ -617,6 +632,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
if (type === 'EVENT' && content?.content) {
try {
const {
animated,
theme,
zapDefault,
zapConfig,
Expand All @@ -630,6 +646,8 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {

theme && setThemeByName(theme, true);

setAnimation(animated, true);

// If new setting is missing, merge with the old setting
if (zapDefault) {
setDefaultZapAmount(zapDefault, true);
Expand Down Expand Up @@ -815,7 +833,7 @@ export const SettingsProvider = (props: { children: ContextChildren }) => {
setThemeByName(storedTheme, true);
const storedAnimated = localStorage.getItem('animated') || 'true';
const anim = storedAnimated === 'true' ? true : false;
setAnimation(anim);
setAnimation(anim, true);

refreshMobileReleases();
});
Expand Down
52 changes: 50 additions & 2 deletions src/megaFeeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Kind } from "./constants";
import { getMegaFeed } from "./lib/feed";
import { getArticleThread, getMegaFeed } from "./lib/feed";
import { setLinkPreviews } from "./lib/notes";
import { subsTo } from "./sockets";
import { isRepostInCollection } from "./stores/note";
Expand All @@ -14,14 +14,16 @@ import {
NoteActions,
PrimalArticle,
PrimalNote,
PrimalUser,
TopZap,
} from "./types/primal";
import { parseBolt11 } from "./utils";
import { convertToNotesMega, convertToReadsMega } from "./stores/megaFeed";
import { convertToNotesMega, convertToReadsMega, convertToUsersMega } from "./stores/megaFeed";
import { FeedRange } from "./pages/FeedQueryTest";
import { getRecomendedArticleIds, getScoredUsers } from "./lib/search";
import { fetchArticles } from "./handleNotes";
import { APP_ID } from "./App";
import { decodeIdentifier } from "./lib/keys";

export type PaginationInfo = {
since: number,
Expand All @@ -30,6 +32,7 @@ export type PaginationInfo = {
};

export type MegaFeedResults = {
users: PrimalUser[],
notes: PrimalNote[],
reads: PrimalArticle[],
paging: PaginationInfo,
Expand Down Expand Up @@ -186,6 +189,49 @@ export const fetchRecomendedReads = (
});
}

export const fetchReadThread = (
userPubkey: string | undefined,
naddr: string,
subId: string,
) => {
return new Promise<MegaFeedResults>((resolve) => {
let page: MegaFeedPage = {
users: {},
notes: [],
reads: [],
noteStats: {},
mentions: {},
noteActions: {},
relayHints: {},
topZaps: {},
wordCount: {},
since: 0,
until: 0,
sortBy: 'created_at',
};

const decoded = decodeIdentifier(naddr);

const { pubkey, identifier, kind } = decoded.data;

const unsub = subsTo(subId, {
onEvent: (_, content) => {
content && updateFeedPage(page, content);
},
onEose: () => {
unsub();
resolve(pageResolve(page));
},
onNotice: (_, reason) => {
unsub();
resolve({ users: [], notes: [], reads: [], paging: { since: 0, until: 0, sortBy: 'created_at'}});
}
});

getArticleThread(userPubkey, pubkey, identifier, kind, subId);
});
}

const pageResolve = (page: MegaFeedPage) => {

// If there are reposts that have empty content,
Expand All @@ -204,10 +250,12 @@ const pageResolve = (page: MegaFeedPage) => {
})
}

const users = convertToUsersMega(page);
const notes = convertToNotesMega(page);
const reads = convertToReadsMega(page);

return {
users,
notes,
reads,
paging: {
Expand Down
51 changes: 22 additions & 29 deletions src/pages/Longform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import PageCaption from "../components/PageCaption/PageCaption";
import ArticleSkeleton from "../components/Skeleton/ArticleSkeleton";
import { useMediaContext } from "../contexts/MediaContext";
import { Transition, TransitionGroup } from "solid-transition-group";
import { fetchReadThread } from "../megaFeeds";

export type LongFormData = {
title: string,
Expand Down Expand Up @@ -466,44 +467,36 @@ const Longform: Component< { naddr: string } > = (props) => {
updateStore(() => ({ ...emptyStore }));
};

const fetchArticle = () => {
const decoded = decodeIdentifier(naddr());
const fetchArticle = async () => {

const { pubkey, identifier, kind } = decoded.data;
updateStore('isFetching', () => true);

if (![Kind.LongForm, Kind.LongFormShell].includes(kind)) return;
const { users, notes, reads } = await fetchReadThread(
account?.publicKey,
naddr(),
`thread_read_${naddr()}_${APP_ID}`,
);

const subId = `naddr_${naddr()}_${APP_ID}`;
const article = reads.find(a => {
if (a.noteId === naddr()) return true;

const unsub = subscribeTo(subId, (type, subId, content) =>{
if (type === 'EOSE') {
unsub();
savePage(store.page);
return;
}
const decode1 = decodeIdentifier(naddr());
const decode2 = decodeIdentifier(a.naddr);

if (type === 'NOTICE') {
updateStore('noContent', () => true);
}
const a1 = `${decode1.data.kind}_${decode1.data.pubkey}_${decode1.data.identifier}`;
const a2 = `${decode2.data.kind}_${decode2.data.pubkey}_${decode2.data.identifier}`;

if (type === 'EVENT') {
content && updatePage(content);
}
return a1 === a2;
});

updateStore('isFetching', () => true);

updateStore('page', () => ({
messages: [],
users: {},
postStats: {},
mentions: {},
noteActions: {},
topZaps: {},
wordCount: {},
}));

getArticleThread(account?.publicKey, pubkey, identifier, kind, subId);
batch(() => {
updateStore('users', () => [ ...users ]);
updateStore('replies', () => [ ...notes ]);
updateStore('article', () => ({ ...article }));
});

updateStore('isFetching', () => false);
}

const updatePage = (content: NostrEventContent) => {
Expand Down
51 changes: 35 additions & 16 deletions src/pages/Profile.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,40 @@
height: 466px;
}

[data-animated="true"] {
.banner, .profileActions, .bigAbout, .smallAbout {
opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
}
.banner {
animation-delay: var(--profile-banner-animation-delay);
}
.avatar {
>div {
opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-avatar-animation-delay);
}
}
.profileActions, .bigAbout, .smallAbout {
animation-delay: var(--profile-card-animation-delay);
}
}

.banner {
width: 100%;
height: 200px;
overflow: hidden;
opacity: 0;

img {
width: 100%;
height: 200px;
object-fit: cover;
}

opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-banner-animation-delay);
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
// animation-delay: var(--profile-banner-animation-delay);
}

.userImage {
Expand All @@ -55,9 +74,9 @@
border-radius: 50%;
background-color: var(--background-site);
>div {
opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-avatar-animation-delay);
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
// animation-delay: var(--profile-avatar-animation-delay);
}
}

Expand Down Expand Up @@ -124,9 +143,9 @@
height: 36px;
}

opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-card-animation-delay);
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
// animation-delay: var(--profile-card-animation-delay);
}

.profileAboutHolder {
Expand Down Expand Up @@ -290,9 +309,9 @@
justify-content: flex-start;
align-items: stretch;

opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-card-animation-delay);
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
// animation-delay: var(--profile-card-animation-delay);
}

.smallAbout {
Expand All @@ -301,9 +320,9 @@
align-items: flex-start;
width: 100%;

opacity: 0;
animation: fadeIn var(--profile-animation-duration) ease-in forwards;
animation-delay: var(--profile-card-animation-delay);
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
// animation-delay: var(--profile-card-animation-delay);

.columnLeft {
width: 50%;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Settings/Appearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Appearance: Component = () => {

<div>
<CheckBox2
checked={settings?.isAnimated}
checked={settings?.isAnimated !== undefined ? settings.isAnimated : true}
onChange={settings?.actions.setAnimation}
>
<div class={styles.appearanceCheckLabel}>Show Animations</div>
Expand Down
Loading

0 comments on commit a291f5d

Please sign in to comment.