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