feat: 💨
This commit is contained in:
@@ -72,7 +72,7 @@ type TNostrContext = {
|
|||||||
|
|
||||||
const NostrContext = createContext<TNostrContext | undefined>(undefined)
|
const NostrContext = createContext<TNostrContext | undefined>(undefined)
|
||||||
|
|
||||||
let lastPublishedSeenNotificationsAtEventAt = -1
|
const lastPublishedSeenNotificationsAtEventAtMap = new Map<string, number>()
|
||||||
|
|
||||||
export const useNostr = () => {
|
export const useNostr = () => {
|
||||||
const context = useContext(NostrContext)
|
const context = useContext(NostrContext)
|
||||||
@@ -691,12 +691,14 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}, 5_000)
|
}, 5_000)
|
||||||
|
|
||||||
// Prevent too frequent requests for signing seen notifications events
|
// Prevent too frequent requests for signing seen notifications events
|
||||||
|
const lastPublishedSeenNotificationsAtEventAt =
|
||||||
|
lastPublishedSeenNotificationsAtEventAtMap.get(account.pubkey) ?? -1
|
||||||
if (
|
if (
|
||||||
lastPublishedSeenNotificationsAtEventAt < 0 ||
|
lastPublishedSeenNotificationsAtEventAt < 0 ||
|
||||||
now - lastPublishedSeenNotificationsAtEventAt > 10 * 60 // 10 minutes
|
now - lastPublishedSeenNotificationsAtEventAt > 10 * 60 // 10 minutes
|
||||||
) {
|
) {
|
||||||
await publish(createSeenNotificationsAtDraftEvent())
|
await publish(createSeenNotificationsAtDraftEvent())
|
||||||
lastPublishedSeenNotificationsAtEventAt = now
|
lastPublishedSeenNotificationsAtEventAtMap.set(account.pubkey, now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,30 +12,21 @@ export type TPollResults = {
|
|||||||
updatedAt: number
|
updatedAt: number
|
||||||
}
|
}
|
||||||
|
|
||||||
class PollResultsService {
|
type TFetchPollResultsParams = {
|
||||||
static instance: PollResultsService
|
|
||||||
private pollResultsMap: Map<string, TPollResults> = new Map()
|
|
||||||
private pollResultsSubscribers = new Map<string, Set<() => void>>()
|
|
||||||
private loader = new DataLoader<
|
|
||||||
{
|
|
||||||
pollEventId: string
|
pollEventId: string
|
||||||
relays: string[]
|
relays: string[]
|
||||||
validPollOptionIds: string[]
|
validPollOptionIds: string[]
|
||||||
isMultipleChoice: boolean
|
isMultipleChoice: boolean
|
||||||
endsAt?: number
|
endsAt?: number
|
||||||
},
|
}
|
||||||
TPollResults | undefined
|
|
||||||
>(
|
class PollResultsService {
|
||||||
|
static instance: PollResultsService
|
||||||
|
private pollResultsMap: Map<string, TPollResults> = new Map()
|
||||||
|
private pollResultsSubscribers = new Map<string, Set<() => void>>()
|
||||||
|
private loader = new DataLoader<TFetchPollResultsParams, TPollResults | undefined>(
|
||||||
async (params) => {
|
async (params) => {
|
||||||
const pollMap = new Map<
|
const pollMap = new Map<string, Omit<TFetchPollResultsParams, 'pollEventId'>>()
|
||||||
string,
|
|
||||||
{
|
|
||||||
relays: string[]
|
|
||||||
validPollOptionIds: string[]
|
|
||||||
isMultipleChoice: boolean
|
|
||||||
endsAt?: number
|
|
||||||
}
|
|
||||||
>()
|
|
||||||
|
|
||||||
params.forEach(({ pollEventId, relays, validPollOptionIds, isMultipleChoice, endsAt }) => {
|
params.forEach(({ pollEventId, relays, validPollOptionIds, isMultipleChoice, endsAt }) => {
|
||||||
if (!pollMap.has(pollEventId)) {
|
if (!pollMap.has(pollEventId)) {
|
||||||
@@ -97,7 +88,6 @@ class PollResultsService {
|
|||||||
isMultipleChoice: boolean,
|
isMultipleChoice: boolean,
|
||||||
endsAt?: number
|
endsAt?: number
|
||||||
) {
|
) {
|
||||||
console.log('Fetching poll results for:', pollEventId)
|
|
||||||
const filter: Filter = {
|
const filter: Filter = {
|
||||||
kinds: [ExtendedKind.POLL_RESPONSE],
|
kinds: [ExtendedKind.POLL_RESPONSE],
|
||||||
'#e': [pollEventId],
|
'#e': [pollEventId],
|
||||||
|
|||||||
Reference in New Issue
Block a user