Browse Source

feat: 💨

imwald
codytseng 8 months ago
parent
commit
5baa0b0ce3
  1. 6
      src/providers/NostrProvider/index.tsx
  2. 28
      src/services/poll-results.service.ts

6
src/providers/NostrProvider/index.tsx

@ -72,7 +72,7 @@ type TNostrContext = { @@ -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 }) { @@ -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)
}
}

28
src/services/poll-results.service.ts

@ -12,30 +12,21 @@ export type TPollResults = { @@ -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
>(
}
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,
{
relays: string[]
validPollOptionIds: string[]
isMultipleChoice: boolean
endsAt?: number
}
>()
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 { @@ -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],

Loading…
Cancel
Save