feat: 💨
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { useToast } from '@/hooks/use-toast'
|
import { useToast } from '@/hooks/use-toast'
|
||||||
import { createCommentDraftEvent, createShortTextNoteDraftEvent } from '@/lib/draft-event'
|
import { createCommentDraftEvent, createShortTextNoteDraftEvent } from '@/lib/draft-event'
|
||||||
import { useFeed } from '@/providers/FeedProvider.tsx'
|
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
import client from '@/services/client.service'
|
import client from '@/services/client.service'
|
||||||
import relayInfoService from '@/services/relay-info.service'
|
|
||||||
import { ChevronDown, ImageUp, LoaderCircle } from 'lucide-react'
|
import { ChevronDown, ImageUp, LoaderCircle } from 'lucide-react'
|
||||||
import { Event, kinds } from 'nostr-tools'
|
import { Event, kinds } from 'nostr-tools'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
@@ -14,7 +12,6 @@ import Mentions from './Mentions'
|
|||||||
import PostOptions from './PostOptions.tsx'
|
import PostOptions from './PostOptions.tsx'
|
||||||
import Preview from './Preview'
|
import Preview from './Preview'
|
||||||
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
||||||
import { TPostOptions } from './types.ts'
|
|
||||||
import Uploader from './Uploader'
|
import Uploader from './Uploader'
|
||||||
|
|
||||||
export default function NormalPostContent({
|
export default function NormalPostContent({
|
||||||
@@ -29,12 +26,12 @@ export default function NormalPostContent({
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { toast } = useToast()
|
const { toast } = useToast()
|
||||||
const { publish, checkLogin } = useNostr()
|
const { publish, checkLogin } = useNostr()
|
||||||
const { relayUrls } = useFeed()
|
|
||||||
const [content, setContent] = useState(defaultContent)
|
const [content, setContent] = useState(defaultContent)
|
||||||
const [pictureInfos, setPictureInfos] = useState<{ url: string; tags: string[][] }[]>([])
|
const [pictureInfos, setPictureInfos] = useState<{ url: string; tags: string[][] }[]>([])
|
||||||
const [posting, setPosting] = useState(false)
|
const [posting, setPosting] = useState(false)
|
||||||
const [showMoreOptions, setShowMoreOptions] = useState(false)
|
const [showMoreOptions, setShowMoreOptions] = useState(false)
|
||||||
const [postOptions, setPostOptions] = useState<TPostOptions>({})
|
const [addClientTag, setAddClientTag] = useState(false)
|
||||||
|
const [specifiedRelayUrls, setSpecifiedRelayUrls] = useState<string[] | undefined>(undefined)
|
||||||
const [uploadingPicture, setUploadingPicture] = useState(false)
|
const [uploadingPicture, setUploadingPicture] = useState(false)
|
||||||
const canPost = !!content && !posting
|
const canPost = !!content && !posting
|
||||||
|
|
||||||
@@ -53,25 +50,20 @@ export default function NormalPostContent({
|
|||||||
const relayList = await client.fetchRelayList(parentEvent.pubkey)
|
const relayList = await client.fetchRelayList(parentEvent.pubkey)
|
||||||
additionalRelayUrls.push(...relayList.read.slice(0, 5))
|
additionalRelayUrls.push(...relayList.read.slice(0, 5))
|
||||||
}
|
}
|
||||||
let protectedEvent = false
|
|
||||||
if (postOptions.sendOnlyToCurrentRelays) {
|
|
||||||
const relayInfos = await relayInfoService.getRelayInfos(relayUrls)
|
|
||||||
protectedEvent = relayInfos.every((info) => info?.supported_nips?.includes(70))
|
|
||||||
}
|
|
||||||
const draftEvent =
|
const draftEvent =
|
||||||
parentEvent && parentEvent.kind !== kinds.ShortTextNote
|
parentEvent && parentEvent.kind !== kinds.ShortTextNote
|
||||||
? await createCommentDraftEvent(content, parentEvent, pictureInfos, {
|
? await createCommentDraftEvent(content, parentEvent, pictureInfos, {
|
||||||
addClientTag: postOptions.addClientTag,
|
addClientTag,
|
||||||
protectedEvent
|
protectedEvent: !!specifiedRelayUrls
|
||||||
})
|
})
|
||||||
: await createShortTextNoteDraftEvent(content, pictureInfos, {
|
: await createShortTextNoteDraftEvent(content, pictureInfos, {
|
||||||
parentEvent,
|
parentEvent,
|
||||||
addClientTag: postOptions.addClientTag,
|
addClientTag,
|
||||||
protectedEvent
|
protectedEvent: !!specifiedRelayUrls
|
||||||
})
|
})
|
||||||
await publish(draftEvent, {
|
await publish(draftEvent, {
|
||||||
additionalRelayUrls,
|
additionalRelayUrls,
|
||||||
specifiedRelayUrls: postOptions.sendOnlyToCurrentRelays ? relayUrls : undefined
|
specifiedRelayUrls
|
||||||
})
|
})
|
||||||
setContent('')
|
setContent('')
|
||||||
close()
|
close()
|
||||||
@@ -114,8 +106,8 @@ export default function NormalPostContent({
|
|||||||
{content && <Preview content={content} />}
|
{content && <Preview content={content} />}
|
||||||
<SendOnlyToSwitch
|
<SendOnlyToSwitch
|
||||||
parentEvent={parentEvent}
|
parentEvent={parentEvent}
|
||||||
postOptions={postOptions}
|
specifiedRelayUrls={specifiedRelayUrls}
|
||||||
setPostOptions={setPostOptions}
|
setSpecifiedRelayUrls={setSpecifiedRelayUrls}
|
||||||
/>
|
/>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
@@ -163,8 +155,8 @@ export default function NormalPostContent({
|
|||||||
</div>
|
</div>
|
||||||
<PostOptions
|
<PostOptions
|
||||||
show={showMoreOptions}
|
show={showMoreOptions}
|
||||||
postOptions={postOptions}
|
addClientTag={addClientTag}
|
||||||
setPostOptions={setPostOptions}
|
setAddClientTag={setAddClientTag}
|
||||||
/>
|
/>
|
||||||
<div className="flex gap-2 items-center justify-around sm:hidden">
|
<div className="flex gap-2 items-center justify-around sm:hidden">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { useToast } from '@/hooks/use-toast'
|
import { useToast } from '@/hooks/use-toast'
|
||||||
import { createPictureNoteDraftEvent } from '@/lib/draft-event'
|
import { createPictureNoteDraftEvent } from '@/lib/draft-event'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { useFeed } from '@/providers/FeedProvider.tsx'
|
|
||||||
import { useNostr } from '@/providers/NostrProvider'
|
import { useNostr } from '@/providers/NostrProvider'
|
||||||
import relayInfoService from '@/services/relay-info.service'
|
|
||||||
import { ChevronDown, Loader, LoaderCircle, Plus, X } from 'lucide-react'
|
import { ChevronDown, Loader, LoaderCircle, Plus, X } from 'lucide-react'
|
||||||
import { Dispatch, SetStateAction, useState } from 'react'
|
import { Dispatch, SetStateAction, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@@ -13,19 +11,18 @@ import TextareaWithMentions from '../TextareaWithMentions.tsx'
|
|||||||
import Mentions from './Mentions'
|
import Mentions from './Mentions'
|
||||||
import PostOptions from './PostOptions.tsx'
|
import PostOptions from './PostOptions.tsx'
|
||||||
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
import SendOnlyToSwitch from './SendOnlyToSwitch.tsx'
|
||||||
import { TPostOptions } from './types.ts'
|
|
||||||
import Uploader from './Uploader'
|
import Uploader from './Uploader'
|
||||||
|
|
||||||
export default function PicturePostContent({ close }: { close: () => void }) {
|
export default function PicturePostContent({ close }: { close: () => void }) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { toast } = useToast()
|
const { toast } = useToast()
|
||||||
const { publish, checkLogin } = useNostr()
|
const { publish, checkLogin } = useNostr()
|
||||||
const { relayUrls } = useFeed()
|
|
||||||
const [content, setContent] = useState('')
|
const [content, setContent] = useState('')
|
||||||
const [pictureInfos, setPictureInfos] = useState<{ url: string; tags: string[][] }[]>([])
|
const [pictureInfos, setPictureInfos] = useState<{ url: string; tags: string[][] }[]>([])
|
||||||
const [posting, setPosting] = useState(false)
|
const [posting, setPosting] = useState(false)
|
||||||
const [showMoreOptions, setShowMoreOptions] = useState(false)
|
const [showMoreOptions, setShowMoreOptions] = useState(false)
|
||||||
const [postOptions, setPostOptions] = useState<TPostOptions>({})
|
const [addClientTag, setAddClientTag] = useState(false)
|
||||||
|
const [specifiedRelayUrls, setSpecifiedRelayUrls] = useState<string[] | undefined>(undefined)
|
||||||
const canPost = !!content && !posting && pictureInfos.length > 0
|
const canPost = !!content && !posting && pictureInfos.length > 0
|
||||||
|
|
||||||
const post = async (e: React.MouseEvent) => {
|
const post = async (e: React.MouseEvent) => {
|
||||||
@@ -41,18 +38,11 @@ export default function PicturePostContent({ close }: { close: () => void }) {
|
|||||||
if (!pictureInfos.length) {
|
if (!pictureInfos.length) {
|
||||||
throw new Error(t('Picture note requires images'))
|
throw new Error(t('Picture note requires images'))
|
||||||
}
|
}
|
||||||
let protectedEvent = false
|
|
||||||
if (postOptions.sendOnlyToCurrentRelays) {
|
|
||||||
const relayInfos = await relayInfoService.getRelayInfos(relayUrls)
|
|
||||||
protectedEvent = relayInfos.every((info) => info?.supported_nips?.includes(70))
|
|
||||||
}
|
|
||||||
const draftEvent = await createPictureNoteDraftEvent(content, pictureInfos, {
|
const draftEvent = await createPictureNoteDraftEvent(content, pictureInfos, {
|
||||||
addClientTag: postOptions.addClientTag,
|
addClientTag,
|
||||||
protectedEvent
|
protectedEvent: !!specifiedRelayUrls
|
||||||
})
|
|
||||||
await publish(draftEvent, {
|
|
||||||
specifiedRelayUrls: postOptions.sendOnlyToCurrentRelays ? relayUrls : undefined
|
|
||||||
})
|
})
|
||||||
|
await publish(draftEvent, { specifiedRelayUrls })
|
||||||
setContent('')
|
setContent('')
|
||||||
close()
|
close()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -95,7 +85,10 @@ export default function PicturePostContent({ close }: { close: () => void }) {
|
|||||||
textValue={content}
|
textValue={content}
|
||||||
placeholder={t('Write something...')}
|
placeholder={t('Write something...')}
|
||||||
/>
|
/>
|
||||||
<SendOnlyToSwitch postOptions={postOptions} setPostOptions={setPostOptions} />
|
<SendOnlyToSwitch
|
||||||
|
specifiedRelayUrls={specifiedRelayUrls}
|
||||||
|
setSpecifiedRelayUrls={setSpecifiedRelayUrls}
|
||||||
|
/>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<Button
|
<Button
|
||||||
variant="link"
|
variant="link"
|
||||||
@@ -126,8 +119,8 @@ export default function PicturePostContent({ close }: { close: () => void }) {
|
|||||||
</div>
|
</div>
|
||||||
<PostOptions
|
<PostOptions
|
||||||
show={showMoreOptions}
|
show={showMoreOptions}
|
||||||
postOptions={postOptions}
|
addClientTag={addClientTag}
|
||||||
setPostOptions={setPostOptions}
|
setAddClientTag={setAddClientTag}
|
||||||
/>
|
/>
|
||||||
<div className="flex gap-2 items-center justify-around sm:hidden">
|
<div className="flex gap-2 items-center justify-around sm:hidden">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -3,30 +3,26 @@ import { Switch } from '@/components/ui/switch'
|
|||||||
import { StorageKey } from '@/constants'
|
import { StorageKey } from '@/constants'
|
||||||
import { Dispatch, SetStateAction, useEffect } from 'react'
|
import { Dispatch, SetStateAction, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { TPostOptions } from './types'
|
|
||||||
|
|
||||||
export default function PostOptions({
|
export default function PostOptions({
|
||||||
show,
|
show,
|
||||||
postOptions,
|
addClientTag,
|
||||||
setPostOptions
|
setAddClientTag
|
||||||
}: {
|
}: {
|
||||||
show: boolean
|
show: boolean
|
||||||
postOptions: TPostOptions
|
addClientTag: boolean
|
||||||
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
|
setAddClientTag: Dispatch<SetStateAction<boolean>>
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPostOptions((prev) => ({
|
setAddClientTag(window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true')
|
||||||
...prev,
|
|
||||||
addClientTag: window.localStorage.getItem(StorageKey.ADD_CLIENT_TAG) === 'true'
|
|
||||||
}))
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
if (!show) return null
|
if (!show) return null
|
||||||
|
|
||||||
const onAddClientTagChange = (checked: boolean) => {
|
const onAddClientTagChange = (checked: boolean) => {
|
||||||
setPostOptions((prev) => ({ ...prev, addClientTag: checked }))
|
setAddClientTag(checked)
|
||||||
window.localStorage.setItem(StorageKey.ADD_CLIENT_TAG, checked.toString())
|
window.localStorage.setItem(StorageKey.ADD_CLIENT_TAG, checked.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,11 +30,7 @@ export default function PostOptions({
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<Label htmlFor="add-client-tag">{t('Add client tag')}</Label>
|
<Label htmlFor="add-client-tag">{t('Add client tag')}</Label>
|
||||||
<Switch
|
<Switch id="add-client-tag" checked={addClientTag} onCheckedChange={onAddClientTagChange} />
|
||||||
id="add-client-tag"
|
|
||||||
checked={postOptions.addClientTag}
|
|
||||||
onCheckedChange={onAddClientTagChange}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="text-muted-foreground text-xs">
|
<div className="text-muted-foreground text-xs">
|
||||||
{t('Show others this was sent via Jumble')}
|
{t('Show others this was sent via Jumble')}
|
||||||
|
|||||||
@@ -4,46 +4,51 @@ import { Switch } from '@/components/ui/switch'
|
|||||||
import { isProtectedEvent } from '@/lib/event'
|
import { isProtectedEvent } from '@/lib/event'
|
||||||
import { simplifyUrl } from '@/lib/url'
|
import { simplifyUrl } from '@/lib/url'
|
||||||
import { useFeed } from '@/providers/FeedProvider'
|
import { useFeed } from '@/providers/FeedProvider'
|
||||||
|
import client from '@/services/client.service'
|
||||||
import { Info } from 'lucide-react'
|
import { Info } from 'lucide-react'
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
import { Dispatch, SetStateAction, useEffect } from 'react'
|
import { Dispatch, SetStateAction, useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { TPostOptions } from './types'
|
|
||||||
|
|
||||||
export default function SendOnlyToSwitch({
|
export default function SendOnlyToSwitch({
|
||||||
parentEvent,
|
parentEvent,
|
||||||
postOptions,
|
specifiedRelayUrls,
|
||||||
setPostOptions
|
setSpecifiedRelayUrls
|
||||||
}: {
|
}: {
|
||||||
parentEvent?: Event
|
parentEvent?: Event
|
||||||
postOptions: TPostOptions
|
specifiedRelayUrls?: string[]
|
||||||
setPostOptions: Dispatch<SetStateAction<TPostOptions>>
|
setSpecifiedRelayUrls: Dispatch<SetStateAction<string[] | undefined>>
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { relayUrls } = useFeed()
|
const { relayUrls } = useFeed()
|
||||||
|
const urls = useMemo(() => {
|
||||||
useEffect(() => {
|
if (!parentEvent) return relayUrls
|
||||||
const isProtected = parentEvent ? isProtectedEvent(parentEvent) : false
|
const isProtected = isProtectedEvent(parentEvent)
|
||||||
if (isProtected) {
|
const seenOn = client.getSeenEventRelayUrls(parentEvent.id)
|
||||||
setPostOptions((prev) => ({ ...prev, sendOnlyToCurrentRelays: true }))
|
if (isProtected && seenOn.length) {
|
||||||
|
setSpecifiedRelayUrls(seenOn)
|
||||||
|
return seenOn
|
||||||
}
|
}
|
||||||
}, [])
|
return relayUrls
|
||||||
|
}, [parentEvent, relayUrls])
|
||||||
|
|
||||||
|
if (!urls.length) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<Label htmlFor="send-only-to-current-relays" className="truncate">
|
<Label htmlFor="send-only-to-current-relays" className="truncate">
|
||||||
{relayUrls.length === 1
|
{urls.length === 1
|
||||||
? t('Send only to r', { r: simplifyUrl(relayUrls[0]) })
|
? t('Send only to r', { r: simplifyUrl(urls[0]) })
|
||||||
: t('Send only to current relays')}
|
: t('Send only to these relays')}
|
||||||
</Label>
|
</Label>
|
||||||
{relayUrls.length > 1 && (
|
{urls.length > 1 && (
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<Info size={14} />
|
<Info size={14} />
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-fit text-sm">
|
<PopoverContent className="w-fit text-sm">
|
||||||
{relayUrls.map((url) => (
|
{urls.map((url) => (
|
||||||
<div key={url}>{simplifyUrl(url)}</div>
|
<div key={url}>{simplifyUrl(url)}</div>
|
||||||
))}
|
))}
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
@@ -53,10 +58,8 @@ export default function SendOnlyToSwitch({
|
|||||||
<Switch
|
<Switch
|
||||||
className="shrink-0"
|
className="shrink-0"
|
||||||
id="send-only-to-current-relays"
|
id="send-only-to-current-relays"
|
||||||
checked={postOptions.sendOnlyToCurrentRelays}
|
checked={!!specifiedRelayUrls}
|
||||||
onCheckedChange={(checked) =>
|
onCheckedChange={(checked) => setSpecifiedRelayUrls(checked ? urls : undefined)}
|
||||||
setPostOptions((prev) => ({ ...prev, sendOnlyToCurrentRelays: checked }))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export type TPostOptions = {
|
|
||||||
addClientTag?: boolean
|
|
||||||
sendOnlyToCurrentRelays?: boolean
|
|
||||||
}
|
|
||||||
@@ -164,7 +164,7 @@ export default {
|
|||||||
'Login to set': 'Login to set',
|
'Login to set': 'Login to set',
|
||||||
'Please login to view following feed': 'Please login to view following feed',
|
'Please login to view following feed': 'Please login to view following feed',
|
||||||
'Send only to r': 'Send only to {{r}}',
|
'Send only to r': 'Send only to {{r}}',
|
||||||
'Send only to current relays': 'Send only to current relays',
|
'Send only to these relays': 'Send only to these relays',
|
||||||
Explore: 'Explore',
|
Explore: 'Explore',
|
||||||
'Search relays': 'Search relays',
|
'Search relays': 'Search relays',
|
||||||
relayInfoBadgeAuth: 'Auth',
|
relayInfoBadgeAuth: 'Auth',
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ export default {
|
|||||||
'Login to set': '登录后设置',
|
'Login to set': '登录后设置',
|
||||||
'Please login to view following feed': '请登录以查看关注动态',
|
'Please login to view following feed': '请登录以查看关注动态',
|
||||||
'Send only to r': '只发送到 {{r}}',
|
'Send only to r': '只发送到 {{r}}',
|
||||||
'Send only to current relays': '只发送到当前服务器',
|
'Send only to these relays': '只发送到这些服务器',
|
||||||
Explore: '探索',
|
Explore: '探索',
|
||||||
'Search relays': '搜索服务器',
|
'Search relays': '搜索服务器',
|
||||||
relayInfoBadgeAuth: '需登陆',
|
relayInfoBadgeAuth: '需登陆',
|
||||||
|
|||||||
@@ -111,7 +111,9 @@ export function SecondaryPageTitlebar({
|
|||||||
{title}
|
{title}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<BackButton>{title}</BackButton>
|
<div className="flex items-center flex-1 w-0">
|
||||||
|
<BackButton>{title}</BackButton>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex-shrink-0">{controls}</div>
|
<div className="flex-shrink-0">{controls}</div>
|
||||||
</Titlebar>
|
</Titlebar>
|
||||||
|
|||||||
@@ -49,17 +49,17 @@ class ClientService extends EventTarget {
|
|||||||
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
|
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
|
||||||
private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
|
private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
|
||||||
(ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))),
|
(ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))),
|
||||||
{ cacheMap: this.profileEventCache, maxBatchSize: 20 }
|
{ cacheMap: this.profileEventCache, maxBatchSize: 50 }
|
||||||
)
|
)
|
||||||
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||||
this.profileEventBatchLoadFn.bind(this),
|
this.profileEventBatchLoadFn.bind(this),
|
||||||
{ cache: false, maxBatchSize: 20 }
|
{ cache: false, maxBatchSize: 50 }
|
||||||
)
|
)
|
||||||
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
|
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
|
||||||
this.relayListEventBatchLoadFn.bind(this),
|
this.relayListEventBatchLoadFn.bind(this),
|
||||||
{
|
{
|
||||||
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }),
|
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }),
|
||||||
maxBatchSize: 20
|
maxBatchSize: 50
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
private followListCache = new LRUCache<string, Promise<NEvent | undefined>>({
|
private followListCache = new LRUCache<string, Promise<NEvent | undefined>>({
|
||||||
@@ -578,9 +578,9 @@ class ClientService extends EventTarget {
|
|||||||
|
|
||||||
async initUserIndexFromFollowings(pubkey: string) {
|
async initUserIndexFromFollowings(pubkey: string) {
|
||||||
const followings = await this.fetchFollowings(pubkey)
|
const followings = await this.fetchFollowings(pubkey)
|
||||||
for (let i = 0; i * 20 < followings.length; i++) {
|
for (let i = 0; i * 50 < followings.length; i++) {
|
||||||
await this.profileEventDataloader.loadMany(followings.slice(i * 20, (i + 1) * 20))
|
await this.profileEventDataloader.loadMany(followings.slice(i * 50, (i + 1) * 50))
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200))
|
await new Promise((resolve) => setTimeout(resolve, 30000))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user