Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
feat: add get mentions and replies api
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-grover committed Oct 14, 2023
1 parent edd782d commit 27b1e17
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CHANGELOG.md
dist
example/.next
42 changes: 42 additions & 0 deletions src/server/NeynarClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
Cast,
CastWithViewerContext,
GeneratedSigner,
Notification,
NotificationWithViewerContext,
PendingSigner,
Signer,
User,
Expand Down Expand Up @@ -147,6 +149,46 @@ export default class NeynarClient {
}>('all-casts-in-thread', params, 1)
}

getMentionsAndReplies(
fid: number,
options?: { viewer?: never; cursor?: string; limit?: number },
): Promise<{
result: {
notifications: Notification[]
next: {
cursor: string
}
}
}>
getMentionsAndReplies(
fid: number,
options?: { viewer: number; cursor?: string; limit?: number },
): Promise<{
result: {
notifications: NotificationWithViewerContext[]
next: {
cursor: string
}
}
}>
getMentionsAndReplies(
fid: number,
options: { viewer?: number; cursor?: string; limit?: number } = {},
) {
const params = new URLSearchParams({ fid: fid.toString() })
if (options.viewer) params.set('viewerFid', options.viewer.toString())
if (options.cursor) params.set('cursor', options.cursor)
if (options.limit) params.set('limit', options.limit.toString())
return this.get<{
result: {
notifications: Notification[] | NotificationWithViewerContext[]
next: {
cursor: string // TODO: is this nullable if there are no more?
}
}
}>('mentions-and-replies', params, 1)
}

postCast(
signerUuid: string,
text: string,
Expand Down
53 changes: 53 additions & 0 deletions src/server/types/Notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Address, Hash } from 'viem'

export type Notification = {
hash: Hash
parentHash: Hash | null
parentUrl: string | null
parentAuthor: {
fid: string | null
}
author: {
fid: number
custodyAddress: Address
username: string
displayName: string
pfp: {
url: string
}
profile: {
bio: {
text: string
mentions: [] // Known bug - this is always empty
}
}
followerCount: number
followingCount: number
verifications: Address[]
activeStatus: 'active' | 'inactive'
}
text: string
timestamp: string
embeds: { url: string }[]
type: 'cast-mention' | 'cast-reply'
reactions: {
count: number
fids: number[]
}
recasts: {
count: number
fids: number[]
}
recasters: string[]
replies: {
count: number
}
threadHash: Hash | null
}

export type NotificationWithViewerContext = Notification & {
viewerContext: {
liked: boolean
recasted: boolean
}
}
6 changes: 3 additions & 3 deletions src/server/types/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hash } from 'viem'
import { Address } from 'viem'

export type User = {
fid: number
Expand All @@ -10,12 +10,12 @@ export type User = {
profile: {
bio: {
text: string
mentions: [] // This always seems to be empty
mentions: [] // Known bug - this is always empty
}
}
followerCount: number
followingCount: number
verifications: Hash[]
verifications: Address[]
activeStatus: 'active' | 'inactive'
}

Expand Down
1 change: 1 addition & 0 deletions src/server/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Signer'
export * from './Cast'
export * from './Notification'
export * from './User'

0 comments on commit 27b1e17

Please sign in to comment.