Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 3b07a59

Browse files
authored
Merge pull request #58 from ethereumfollowprotocol/notif-start-ts
notifications start timestamp param
2 parents 4f678f5 + 445bff8 commit 3b07a59

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/router/api/v1/users/notifications/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export function notifications(users: Hono<{ Bindings: Environment }>, services:
1111
users.get('/:addressOrENS/notifications', includeValidator, async context => {
1212
const { addressOrENS } = context.req.param()
1313
const { cache } = context.req.query()
14-
let { offset, limit, opcode, interval, tag } = context.req.valid('query')
14+
let { offset, limit, opcode, start, interval, tag } = context.req.valid('query')
1515
if (!limit) limit = '10'
1616
if (!offset) offset = '0'
1717
if (!(opcode && [1, 2, 3, 4].includes(Number(opcode)))) opcode = '0'
18+
if (!start || start === '') start = Math.floor(Date.now() / 1000).toString()
1819
if (!tag || tag === '') tag = 'p_tag_empty'
1920
if (interval === 'hour') interval = '1:00:00'
2021
else if (interval === 'day') interval = '24:00:00'
@@ -24,7 +25,7 @@ export function notifications(users: Hono<{ Bindings: Environment }>, services:
2425
else interval = '168:00:00'
2526

2627
const cacheService = services.cache(env(context))
27-
const cacheTarget = `users/${addressOrENS}/notifications?opcode=${opcode}&interval=${interval}&tag=${tag}&limit=${limit}&offset=${offset}`
28+
const cacheTarget = `users/${addressOrENS}/notifications?opcode=${opcode}&start=${start}&interval=${interval}&tag=${tag}&limit=${limit}&offset=${offset}`
2829

2930
if (cache !== 'fresh') {
3031
const cacheHit = await cacheService.get(cacheTarget)
@@ -41,7 +42,15 @@ export function notifications(users: Hono<{ Bindings: Environment }>, services:
4142

4243
const notifications: NotificationRow[] = await services
4344
.efp(env(context))
44-
.getNotificationsByAddress(address, opcode as string, interval, tag as string, limit as string, offset as string)
45+
.getNotificationsByAddress(
46+
address,
47+
opcode as string,
48+
BigInt(start as string),
49+
interval,
50+
tag as string,
51+
limit as string,
52+
offset as string
53+
)
4554

4655
const response = notifications.map(notification => {
4756
return {

src/service/efp-indexer/mock/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class MockEFPIndexerService implements IEFPIndexerService {
133133
getNotificationsByAddress(
134134
_address: Address,
135135
_opcode: string,
136+
_start: bigint,
136137
_interval: string,
137138
_tag: string,
138139
_limit: string,

src/service/efp-indexer/service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export interface IEFPIndexerService {
246246
getNotificationsByAddress(
247247
address: Address,
248248
opcode: string,
249+
start_timestamp: bigint,
249250
interval: string,
250251
tag: string,
251252
limit: string,
@@ -457,12 +458,13 @@ export class EFPIndexerService implements IEFPIndexerService {
457458
async getNotificationsByAddress(
458459
address: Address,
459460
opcode: string,
461+
start_timestamp: bigint,
460462
interval: string,
461463
tag: string,
462464
limit: string,
463465
offset: string
464466
): Promise<NotificationRow[]> {
465-
const query = sql<NotificationRow>`SELECT * FROM query.get_notifications_by_address_tags(${address}, ${opcode}, ${interval}, ${tag}, ${limit}, ${offset})`
467+
const query = sql<NotificationRow>`SELECT * FROM query.get_notifications_by_address_tags(${address}, ${opcode}, ${start_timestamp}, ${interval}, ${tag}, ${limit}, ${offset})`
466468
const result = await query.execute(this.#db)
467469
if (!result || result.rows.length === 0) {
468470
return []

0 commit comments

Comments
 (0)