Skip to content

Commit

Permalink
feat: action to get user data
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Nov 4, 2024
1 parent 215a3f5 commit 3bb74e4
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
9 changes: 5 additions & 4 deletions playground/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ const client = Client.create(

// console.dir(message)

for await (const cast of Actions.Watch.watchCastsMentioningUsername(client, {
username: 'bleu.eth',
}))
console.dir(cast)
// for await (const cast of Actions.Watch.watchCastsMentioningUsername(client, {
// username: 'bleu.eth',
// }))
// console.dir(cast)
console.dir(await Actions.User.get(client, { fid: 11517n }))
1 change: 1 addition & 0 deletions src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as Watch from './Actions/Watch.js'
export * as Follow from './Actions/Follow.js'
export * as Like from './Actions/Like.js'
export * as Recast from './Actions/Recast.js'
export * as User from './Actions/User.js'
2 changes: 1 addition & 1 deletion src/Actions/Cast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Actions_Cast_getCast as getCast } from '../Internal/Actions/Cast/getCast.js'
export { Actions_Cast_get as get } from '../Internal/Actions/Cast/get.js'
export { Actions_Cast_create as create } from '../Internal/Actions/Cast/create.js'
export { Actions_Cast_fromString as fromString } from '../Internal/Actions/Cast/fromString.js'
export { Actions_Cast_toString as toString } from '../Internal/Actions/Cast/toString.js'
1 change: 1 addition & 0 deletions src/Actions/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Actions_User_get as get } from '../Internal/Actions/User/get.js'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Client } from '../../Client/types.js'
import type { GlobalErrorType } from '../../Errors/error.js'
import { Actions_Cast_toString } from './toString.js'

export declare namespace Actions_Cast_getCast {
export declare namespace Actions_Cast_get {
type ParametersType = NodeActions.Cast.getCast.ParametersType
type ReturnType = NodeTypes.Cast & {
recasts: NodeTypes.Reaction[]
Expand All @@ -19,11 +19,11 @@ export declare namespace Actions_Cast_getCast {
}
type ErrorType = NodeActions.Cast.getCast.ErrorType | GlobalErrorType
}
export async function Actions_Cast_getCast(
export async function Actions_Cast_get(
client: Client,
parameters: Actions_Cast_getCast.ParametersType,
parameters: Actions_Cast_get.ParametersType,
options?: CallOptions,
): Promise<Actions_Cast_getCast.ReturnType> {
): Promise<Actions_Cast_get.ReturnType> {
const cast = await NodeActions.Cast.getCast(client, parameters, options)

const reactions = await (async () => {
Expand Down Expand Up @@ -55,5 +55,5 @@ export async function Actions_Cast_getCast(
}
}

Actions_Cast_getCast.parseError = (error: unknown) =>
error as Actions_Cast_getCast.ErrorType
Actions_Cast_get.parseError = (error: unknown) =>
error as Actions_Cast_get.ErrorType
54 changes: 54 additions & 0 deletions src/Internal/Actions/User/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { CallOptions } from '@connectrpc/connect'
import {
Actions as NodeActions,
type Types as NodeTypes,
} from '../../../Node/index.js'
import type { Client } from '../../Client/types.js'
import type { GlobalErrorType } from '../../Errors/error.js'

export declare namespace Actions_User_get {
type ParametersType = { fid: bigint }
type ReturnType = {
pfp: string | null
displayName: string | null
bio: string | null
url: string | null
username: string | null
location: string | null
}
type ErrorType =
| NodeActions.UserData.getUserDataByFid.ErrorType
| GlobalErrorType
}
export async function Actions_User_get(
client: Client,
parameters: Actions_User_get.ParametersType,
options?: CallOptions,
): Promise<Actions_User_get.ReturnType> {
let nextPageToken: NodeTypes.NextPageToken = null
const userDatas = await (async () => {
const datas: NodeTypes.UserData[] = []
do {
const result = await NodeActions.UserData.getUserDataByFid(
client,
{ fid: parameters.fid },
options,
)
datas.push(...result.datas)
nextPageToken = result.nextPageToken
} while (nextPageToken !== null)
return datas
})()
return {
pfp: userDatas.find((data) => data.type === 'pfp')?.value ?? null,
displayName:
userDatas.find((data) => data.type === 'display')?.value ?? null,
bio: userDatas.find((data) => data.type === 'bio')?.value ?? null,
url: userDatas.find((data) => data.type === 'url')?.value ?? null,
username: userDatas.find((data) => data.type === 'username')?.value ?? null,
location: userDatas.find((data) => data.type === 'location')?.value ?? null,
}
}

Actions_User_get.parseError = (error: unknown) =>
error as Actions_User_get.ErrorType
1 change: 1 addition & 0 deletions src/Node/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export type { Message } from './Internal/Message/types.js'
export type { UserData } from './Internal/UserData/types.js'
export type { Reaction } from './Internal/Reaction/types.js'
export type { ReactionTarget } from './Internal/ReactionTarget/types.js'
export type { NextPageToken } from './Internal/Pagination/types.js'

0 comments on commit 3bb74e4

Please sign in to comment.