MCPcopy Create free account
hub / github.com/cameri/nostream / isUserAdmitted

Method isUserAdmitted

src/app/static-mirroring-worker.ts:278–313  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

276 }
277
278 protected async isUserAdmitted(event: Event): Promise<boolean> {
279 const currentSettings = this.settings()
280
281 if (this.config.skipAdmissionCheck === true) {
282 return true
283 }
284
285 if (currentSettings.payments?.enabled !== true) {
286 return true
287 }
288
289 const isApplicableFee = (feeSchedule: FeeSchedule) =>
290 feeSchedule.enabled &&
291 !feeSchedule.whitelists?.pubkeys?.includes(event.pubkey) &&
292 !feeSchedule.whitelists?.event_kinds?.some(isEventKindOrRangeMatch(event))
293
294 const feeSchedules = currentSettings.payments?.feeSchedules?.admission?.filter(isApplicableFee)
295
296 if (!Array.isArray(feeSchedules) || !feeSchedules.length) {
297 return true
298 }
299
300 const user = await this.userRepository.findByPubkey(event.pubkey)
301 if (user?.isAdmitted !== true) {
302 logger(`user not admitted: ${event.pubkey}`)
303 return false
304 }
305
306 const minBalance = currentSettings.limits?.event?.pubkey?.minBalance
307 if (minBalance && user.balance < minBalance) {
308 logger(`user not admitted: user balance ${user.balance} < ${minBalance}`)
309 return false
310 }
311
312 return true
313 }
314
315 private onMessage(message: { eventName: string; event: unknown; source: string }): void {
316 if (

Callers 2

createMirrorMethod · 0.95

Calls 1

findByPubkeyMethod · 0.65

Tested by

no test coverage detected